Newer
Older
#!/usr/bin/python3
# flatdeb — build Flatpak runtimes from Debian packages
#
# Copyright 2017-2023 Collabora Ltd.
#
# SPDX-License-Identifier: MIT
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
"""
Create Flatpak runtimes from Debian packages.
"""
import argparse
import gzip
import shutil
import tarfile
from tempfile import TemporaryDirectory
import yaml
from gi.repository import GLib
# TODO: When flatdeb is packaged/released, replace this with the released
# version in packages/releases
VERSION = None
if VERSION is None:
_git_version = subprocess.check_output([
'sh', '-c',
'cd "$(dirname "$1")" && '
'git describe '
'--always '
'--dirty '
'--first-parent '
'--long '
'--tags '
'--match="v[0-9]*" '
'2>/dev/null || :',
'sh',
sys.argv[0],
])[1:].decode('utf-8').strip()
VERSION = _git_version
_DEBOS_BASE_RECIPE = os.path.join(
os.path.dirname(__file__), 'flatdeb', 'debos-base.yaml')
_DEBOS_COLLECT_DBGSYM_RECIPE = os.path.join(
os.path.dirname(__file__), 'flatdeb', 'debos-collect-dbgsym.yaml')
_DEBOS_COLLECT_SOURCE_RECIPE = os.path.join(
os.path.dirname(__file__), 'flatdeb', 'debos-collect-source.yaml')
_DEBOS_RUNTIMES_RECIPE = os.path.join(
os.path.dirname(__file__), 'flatdeb', 'debos-runtimes.yaml')
class SignedBy:
def __str__(self) -> str:
raise NotImplementedError
class SignedByFingerprint(SignedBy):
def __init__(self, fingerprint: str, subkeys: bool = True) -> None:
self.fingerprint = fingerprint
self.subkeys = subkeys
def __str__(self):
return '{}{}'.format(
self.fingerprint,
'!' if not self.subkeys else '',
)
class SignedByKeyring(SignedBy):
def __init__(self, path: str) -> None:
self.path = path
def __str__(self):
return self.path
class AptSource:
def __init__(
self,
kind, # type: str
uri, # type: str
suite, # type: str
components=('main',), # type: typing.Sequence[str]
signed_by=(), # type: typing.Sequence[SignedBy]
trusted=False
):
self.kind = kind
self.uri = uri
self.suite = suite
self.components = components
self.signed_by = set(signed_by)
self.trusted = trusted
def __eq__(self, other):
if not isinstance(other, AptSource):
return False
if self.kind != other.kind:
return False
if self.uri != other.uri:
return False
if self.suite != other.suite:
return False
if set(self.components) != set(other.components):
return False
if set(self.signed_by) != set(other.signed_by):
return False
if self.trusted != other.trusted:
return False
return True
@classmethod
def multiple_from_string(
cls, # type: typing.Type[AptSource]
line, # type: str
# type: (...) -> typing.Iterable[AptSource]
line = line.strip()
tokens = line.split()
if tokens[0] in ('deb', 'deb-src'):
return (cls.from_string(line),)
elif tokens[0] == 'both':
return (
cls.from_string('deb' + line[4:]),
cls.from_string('deb-src' + line[4:]),
)
else:
raise ValueError(
'apt sources must start with "deb ", "deb-src " or "both "')
@classmethod
def from_string(
cls, # type: typing.Type[AptSource]
line, # type: str
tokens = line.split()
trusted = False
if len(tokens) < 4:
raise ValueError(
'apt sources must be specified in the form '
'"deb http://URL SUITE COMPONENT [COMPONENT...]"')
if tokens[0] not in ('deb', 'deb-src'):
raise ValueError(
'apt sources must start with "deb " or "deb-src "')
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
if tokens[1].startswith('['):
for i in range(1, len(tokens)):
token = tokens[i].lstrip('[')
option = token.rstrip(']')
if option == 'trusted=yes':
trusted = True
elif option.startswith('signed-by='):
signed_by_str = option[len('signed-by='):].split(',')
for signer in signed_by_str:
if signer.startswith('/'):
signed_by.append(SignedByKeyring(signer))
elif re.match(r'^[0-9A-Fa-f]+$', signer):
signed_by.append(SignedByFingerprint(signer))
elif re.match(r'^[0-9A-Fa-f]+!$', signer):
signed_by.append(
SignedByFingerprint(signer, subkeys=False)
)
else:
signed_by.append(
SignedByKeyring(
f'/etc/apt/keyrings/{signer}'
)
)
if option != token:
rest = tokens[i + 1:]
break
else:
rest = tokens[1:]
return cls(
kind=tokens[0],
uri=rest[0],
suite=rest[1],
components=rest[2:],
signed_by=signed_by,
trusted=trusted,
)
def __str__(self):
options: typing.List[str] = []
if self.signed_by:
options.append(
'signed-by={}'.format(
','.join(map(str, self.signed_by))
)
)
if self.trusted:
options.append('trusted=yes')
if options:
maybe_options = ' [{}]'.format(' '.join(options))
else:
maybe_options = ''
return '%s%s %s %s %s' % (
self.kind,
maybe_options,
self.uri,
self.suite,
' '.join(self.components),
)
__multiarch_tuple_cache = {} # type: typing.Dict[str, str]
#: The Debian suite to use
self.apt_suite = 'stretch'
#: The Flatpak branch to use for the runtime, or None for apt_suite
self.runtime_branch = None # type: typing.Optional[str]
self.app_branch = None # type: typing.Optional[str]
#: The freedesktop.org cache directory
self.xdg_cache_dir = os.getenv(
'XDG_CACHE_HOME', os.path.expanduser('~/.cache'))
#: Where to write output
self.build_area = os.path.join(
self.xdg_cache_dir, 'flatdeb',
)
self.ostree_repo = os.path.join(self.build_area, 'ostree-repo')
self.remote_url = None # type: typing.Optional[str]
self.__dpkg_archs = [] # type: typing.Sequence[str]
self.flatpak_arch = None # type: typing.Optional[str]
self.__primary_dpkg_arch_matches_cache = {
} # type: typing.Dict[str, bool]
self.suite_details = {} # type: typing.Dict[str, typing.Any]
self.runtime_details = {} # type: typing.Dict[str, typing.Any]
self.ostree_commit = True
self.ostree_mode = 'archive-z2'
self.strip_source_version_suffix = None
self.bootstrap_apt_keyring = ''
#: apt sources to use when building the runtime
self.build_apt_keyrings = [] # type: typing.List[str]
self.build_apt_sources = [] # type: typing.List[AptSource]
#: apt sources to leave in /etc/apt/sources.list afterwards
self.final_apt_keyrings = [] # type: typing.List[str]
self.final_apt_sources = [] # type: typing.List[AptSource]
self.variant_name = None
self.variant_id = None
self.sdk_variant_name = None
self.sdk_variant_id = None
self.debug_symbols = True
self.automatic_dbgsym = True
self.collect_source_code = True
self.do_mtree = False
self.strict = False
self.do_platform = False
self.do_sdk = False
self.metadata = GLib.KeyFile()
self.metadata_debug = GLib.KeyFile()
self.metadata_sources = GLib.KeyFile()
def yaml_dump_one_line(
data, # type: typing.Any
stream=None, # type: ignore
):
# type: (...) -> typing.Optional[str]
return yaml.safe_dump(
data,
stream=stream,
default_flow_style=True,
width=0xFFFFFFFF,
).replace('\n', ' ')
"""
Return the Flatpak architecture name corresponding to uname
result arch.
If arch is None, return the Flatpak architecture name
corresponding to the machine where this script is running.
"""
if arch is None:
arch = os.uname()[4]
if re.match(r'^i.86$', arch):
return 'i386'
elif re.match(r'^arm.*', arch):
if arch.endswith('b'):
return 'armeb'
else:
return 'arm'
elif arch in ('mips', 'mips64'):
import struct
if struct.pack('i', 1).startswith(b'\x01'):
return arch + 'el'
return arch
"""
Return the other architecture that accompanies the given Debian
architecture in a multiarch setup, or None.
"""
if arch == 'amd64':
return 'i386'
elif arch == 'arm64':
return 'armhf'
else:
return None
@staticmethod
def multiarch_tuple(arch):
"""
Return the multiarch tuple for the given dpkg architecture name.
"""
if arch not in Builder.__multiarch_tuple_cache:
Builder.__multiarch_tuple_cache[arch] = subprocess.check_output([
'dpkg-architecture',
'-qDEB_HOST_MULTIARCH',
'-a{}'.format(arch),
]).decode('utf-8').strip()
return Builder.__multiarch_tuple_cache[arch]
"""
Return the Flatpak architecture name corresponding to the given
dpkg architecture name.
"""
if arch == 'amd64':
return 'x86_64'
elif arch == 'arm64':
return 'aarch64'
elif arch in ('armel', 'armhf'):
return 'arm'
elif arch == 'powerpc':
return 'ppc'
elif arch == 'powerpc64':
return 'ppc64'
elif arch == 'powerpcel':
return 'ppcle'
elif arch == 'ppc64el':
return 'ppc64le'
return arch
@property
def primary_dpkg_arch(self):
"""
The Debian architecture we are building a runtime for, such as
i386 or amd64.
"""
return self.__dpkg_archs[0]
@property
def dpkg_archs(self):
"""
The Debian architectures we support via multiarch, such as
['amd64', 'i386'].
"""
return self.__dpkg_archs
@dpkg_archs.setter
def dpkg_archs(self, value):
self.__primary_dpkg_arch_matches_cache = {}
self.__dpkg_archs = value
def primary_dpkg_arch_matches(self, arch_spec):
Return True if arch_spec matches primary_dpkg_arch (or
equivalently, if primary_dpkg_arch is one of the architectures
described by arch_spec). For example, any-amd64 matches amd64
but not i386.
"""
if arch_spec not in self.__primary_dpkg_arch_matches_cache:
exit_code = subprocess.call(
['dpkg-architecture', '--host-arch', self.primary_dpkg_arch,
self.__primary_dpkg_arch_matches_cache[arch_spec] = (
exit_code == 0
)
return self.__primary_dpkg_arch_matches_cache[arch_spec]
"""
Run appropriate commands for the command-line arguments
"""
parser = argparse.ArgumentParser(
description='Build Flatpak runtimes',
)
parser.add_argument('--chdir', default=None)
'--ostree-mode', default=self.ostree_mode,
)
parser.add_argument(
'--export-bundles', action='store_true', default=False,
)
parser.add_argument('--build-area', default=self.build_area)
parser.add_argument('--ostree-repo', default=self.ostree_repo)
parser.add_argument('--remote-url', default=self.remote_url)
parser.add_argument(
'--ostree-commit', action='store_true', default=self.ostree_commit,
)
parser.add_argument(
'--no-ostree-commit', dest='ostree_commit', action='store_false',
)
parser.add_argument('--suite', '-d', default=self.apt_suite)
parser.add_argument('--architecture', '--arch', '-a')
parser.add_argument('--runtime-branch', default=self.runtime_branch)
parser.add_argument('--version', action='store_true')
parser.add_argument(
'--replace-apt-source', action='append', default=[])
parser.add_argument(
'--remove-apt-source', action='append', default=[])
parser.add_argument(
'--add-apt-source', action='append', default=[])
parser.add_argument(
'--replace-build-apt-source', action='append', default=[])
parser.add_argument(
'--remove-build-apt-source', action='append', default=[])
parser.add_argument(
'--add-build-apt-source', action='append', default=[])
parser.add_argument(
'--replace-final-apt-source', action='append', default=[])
parser.add_argument(
'--remove-final-apt-source', action='append', default=[])
parser.add_argument(
'--add-final-apt-source', action='append', default=[])
parser.add_argument(
'--bootstrap-apt-keyring', default='')
parser.add_argument(
'--add-apt-keyring', action='append', default=[])
parser.add_argument(
'--add-build-apt-keyring', action='append', default=[])
parser.add_argument(
'--add-final-apt-keyring', action='append', default=[])
parser.add_argument(
'--generate-sysroot-tarball', action='store_true')
parser.add_argument(
'--no-generate-sysroot-tarball',
dest='generate_sysroot_tarball',
action='store_false',
)
parser.add_argument(
'--generate-platform-sysroot-tarball',
action='store_true',
default=False,
)
parser.add_argument(
'--no-generate-platform-sysroot-tarball',
dest='generate_platform_sysroot_tarball',
action='store_false',
)
parser.add_argument(
'--generate-sdk-sysroot-tarball',
action='store_true',
default=None,
)
parser.add_argument(
'--no-generate-sdk-sysroot-tarball',
dest='generate_sdk_sysroot_tarball',
action='store_false',
default=None,
)
parser.add_argument(
'--generate-source-tarball',
action='store_true',
default=None,
)
parser.add_argument(
'--no-generate-source-tarball',
dest='generate_source_tarball',
action='store_false',
)
parser.add_argument(
'--generate-source-directory',
default='',
)
parser.add_argument(
'--no-generate-source-directory',
dest='generate_source_directory',
action='store_const',
const='',
)
parser.add_argument(
'--generate-mtree',
action='store_true',
default=True,
)
parser.add_argument(
'--no-generate-mtree',
dest='generate_mtree',
action='store_false',
)
parser.add_argument(
'--build-id', default=None)
parser.add_argument(
'--variant-name', default=None)
parser.add_argument(
'--variant-id', default=None)
parser.add_argument(
'--sdk-variant-name', default=None)
parser.add_argument(
'--sdk-variant-id', default=None)
subparsers = parser.add_subparsers(dest='command', metavar='command')
parser.add_argument('--apt-debug', action='store_true')
parser.add_argument(
'--no-apt-debug', dest='apt_debug',
action='store_false')
'--debug-symbols', action='store_true', default=True,
help='Include packages that are tagged as debug symbols',
)
parser.add_argument(
'--no-debug-symbols', dest='debug_symbols', action='store_false',
help='Exclude packages that are tagged as debug symbols',
)
'--automatic-dbgsym', action='store_true', default=None,
help='Include corresponding automatic -dbgsym packages for '
'each package in the Platform (default: detect from suite)',
)
parser.add_argument(
'--no-automatic-dbgsym', dest='automatic_dbgsym',
action='store_false', default=None,
help='Do not include corresponding automatic -dbgsym packages '
'for each package in the Platform',
)
parser.add_argument(
'--ddeb-include-executables', action='store_true', default=False,
help='Include executable code in --ddeb-directory',
)
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
parser.add_argument(
'--dbgsym-tarball', action='store_true', default=None,
help='',
)
parser.add_argument(
'--no-dbgsym-tarball', dest='dbgsym_tarball',
action='store_false', default=None,
help='',
)
parser.add_argument(
'--ddeb-directory',
metavar='DIR',
default='',
help=(
'Download detached debug symbol .deb/.ddeb packages '
'into DIR'
),
)
parser.add_argument(
'--no-ddeb-directory',
dest='ddeb_directory',
action='store_const',
const='',
help=(
'Do not collect detached debug symbol .deb/.ddeb packages '
'in a directory'
),
)
parser.add_argument(
'--collect-source-code', action='store_true', default=True,
help='Include source code for each package (default)',
)
parser.add_argument(
'--no-collect-source-code', dest='collect_source_code',
action='store_false', default=True,
help='Do not include source code',
)
parser.add_argument(
'--strict', action='store_true', default=False,
help='Make various warnings into fatal errors',
)
parser.add_argument(
'--no-strict', action='store_false', dest='strict', default=False,
help='Do not make various warnings fatal (default)',
)
parser.add_argument(
'--platform', action='store_true', default=None,
help='Build Platform image (default unless --sdk is used)',
)
parser.add_argument(
'--no-platform', action='store_false', dest='platform',
default=None,
help='Do not build Platform (default if --sdk is used)',
)
parser.add_argument(
'--sdk', action='store_true', default=None,
help='Build SDK image (default unless --platform is used)',
)
parser.add_argument(
'--no-sdk', action='store_false', dest='sdk', default=None,
help='Do not build SDK (default if --platform is used)',
)
subparser = subparsers.add_parser(
'base',
help='Build a fresh base tarball',
)
subparser = subparsers.add_parser(
'collect-source',
help="Collect a runtime's source code",
)
subparser.add_argument('runtime_yaml_file')
subparser.add_argument('source_required', nargs='*')
subparser = subparsers.add_parser(
'collect-dbgsym',
help="Collect a runtime's detached debug symbols",
)
subparser.add_argument(
'--platform-manifest', action='append', default=[],
)
subparser.add_argument(
'--sdk-manifest', action='append', default=[],
)
subparser.add_argument('runtime_yaml_file')
subparser = subparsers.add_parser(
'runtimes',
help='Build runtimes',
)
subparser.add_argument('yaml_file')
subparser = subparsers.add_parser(
'app',
help='Build an app',
)
subparser.add_argument('--app-branch', default=self.app_branch)
subparser.add_argument('yaml_manifest')
subparser = subparsers.add_parser(
'print-flatpak-architecture',
help='Print the Flatpak architecture',
)
args = parser.parse_args()
for replacement in args.replace_apt_source:
if '=' not in replacement:
parser.error(
'--replace-apt-source argument must be in the form '
'"LABEL=deb http://ARCHIVE SUITE COMPONENT[...]"')
if (
'/' in args.generate_source_directory
or args.generate_source_directory == '..'
):
parser.error(
'--generate-source-directory must be a single '
'directory name'
)
if args.version:
print('flatdeb {}'.format(VERSION))
return
if args.chdir is not None:
os.chdir(args.chdir)
self.apt_debug = args.apt_debug
self.bootstrap_apt_keyring = args.bootstrap_apt_keyring
self.debug_symbols = args.debug_symbols
self.variant_name = args.variant_name
self.variant_id = args.variant_id
self.sdk_variant_name = args.sdk_variant_name
self.sdk_variant_id = args.sdk_variant_id
self.ostree_commit = args.ostree_commit
self.remote_url = args.remote_url
self.export_bundles = args.export_bundles
self.strict = args.strict
self.do_mtree = args.generate_mtree
if args.platform is None and args.sdk is None:
self.do_platform = True
self.do_sdk = True
elif args.sdk:
self.do_platform = bool(args.platform)
self.do_sdk = True
elif args.platform:
self.do_platform = True
self.do_sdk = bool(args.sdk)
else:
self.do_platform = bool(args.platform)
self.do_sdk = bool(args.sdk)
if args.generate_sdk_sysroot_tarball is None:
args.generate_sdk_sysroot_tarball = args.generate_sysroot_tarball
if not (self.do_sdk or self.do_platform):
parser.error(
'--no-sdk and --no-platform cannot work together')
if self.export_bundles and not self.ostree_commit:
parser.error(
'--export-bundles and --no-ostree-commit cannot '
'work together')
subprocess.check_output(
['dpkg-architecture', '-q', 'DEB_HOST_ARCH'],
).decode('utf-8').rstrip('\n')
]
self.dpkg_archs = args.architecture.split(',')
self.flatpak_arch = self.dpkg_to_flatpak_arch(self.primary_dpkg_arch)
self.ensure_build_area()
if self.ostree_repo:
os.makedirs(os.path.dirname(self.ostree_repo), exist_ok=True)
if args.command is None:
parser.error('A command is required')
with open(
os.path.join('suites', self.apt_suite + '.yaml'),
encoding='utf-8') as reader:
self.strip_source_version_suffix = self.suite_details.get(
'strip_source_version_suffix', '')
self.use_signed_by = bool(self.suite_details.get('signed_by', []))
if args.automatic_dbgsym is None:
self.automatic_dbgsym = self.suite_details.get(
'has_automatic_dbgsym', True,
)
else:
self.automatic_dbgsym = args.automatic_dbgsym
if self.do_sdk:
self.collect_source_code = args.collect_source_code
else:
# --no-sdk overrides --collect-source-code: if we are not
# building the SDK then we have no opportunity to collect
# the source code
self.collect_source_code = False
self.build_apt_sources = self.generate_apt_sources(
add=args.add_apt_source + args.add_build_apt_source,
replace=args.replace_apt_source + args.replace_build_apt_source,
remove=args.remove_apt_source + args.remove_build_apt_source,
for_build=True,
)
self.final_apt_sources = self.generate_apt_sources(
add=args.add_apt_source + args.add_final_apt_source,
replace=args.replace_apt_source + args.replace_final_apt_source,
remove=args.remove_apt_source + args.remove_final_apt_source,
for_build=False,
for addition in args.add_apt_keyring + args.add_build_apt_keyring:
self.build_apt_keyrings.append(addition)
for addition in args.add_apt_keyring + args.add_final_apt_keyring:
self.final_apt_keyrings.append(addition)
if self.build_apt_sources[0].kind != 'deb':
parser.error('First apt source must provide .deb packages')
getattr(
self, 'command_' + args.command.replace('-', '_'))(**vars(args))
def generate_apt_sources(
self,
add=(), # type: typing.Sequence[str]
replace=(), # type: typing.Sequence[str]
remove=(), # type: typing.Sequence[str]
for_build=False
):
# type: (...) -> typing.List[AptSource]
apt_sources = [] # type: typing.List[AptSource]
for source in self.suite_details['sources']:
keyring = source.get('keyring')
if keyring is not None:
if for_build:
self.build_apt_keyrings.append(keyring)
else:
self.final_apt_keyrings.append(keyring)
keyrings = source.get('keyrings', [])
if keyrings:
if for_build:
self.build_apt_keyrings.extend(keyrings)
else:
self.final_apt_keyrings.extend(keyrings)
uri = source['apt_uri']
suite = source.get('apt_suite', self.apt_suite)
suite = suite.replace('*', self.apt_suite)
components = source.get(
'apt_components',
self.suite_details.get('apt_components', ['main'])
)
signed_by_str = source.get(
'signed_by',
source.get(
'keyrings',
self.suite_details.get('signed_by', []),
),
)
signed_by: typing.List[SignedBy] = []
trusted = source.get('apt_trusted', False)
if self.use_signed_by:
for token in signed_by_str:
if token.startswith('/'):
signed_by.append(SignedByKeyring(token))
elif re.match(r'^[0-9A-Fa-f]+$', token):
signed_by.append(SignedByFingerprint(token))
elif re.match(r'^[0-9A-Fa-f]+!$', token):
signed_by.append(
SignedByFingerprint(token, subkeys=False)
elif for_build:
signed_by.append(
SignedByKeyring(
f'/etc/apt/keyrings/flatdeb-build-{token}'
)
)
else:
signed_by.append(
SignedByKeyring(
f'/etc/apt/keyrings/{token}'
)
if 'label' in source:
replaced = False
for replacement in reversed(replace):
key, value = replacement.split('=', 1)
if key == source['label']:
apt_sources.extend(
AptSource.multiple_from_string(value))
replaced = True
break
if replaced or source['label'] in remove:
continue
if for_build:
if not source.get('for_build', True):
continue
else:
if not source.get('for_final', True):
continue
if source.get('deb', True):
apt_sources.append(AptSource(
'deb', uri, suite,
components=components,
trusted=trusted,
))
if source.get('deb-src', True):
apt_sources.append(AptSource(
'deb-src', uri, suite,
components=components,
trusted=trusted,
))
for addition in add:
apt_sources.extend(AptSource.multiple_from_string(addition))
return apt_sources
def command_print_flatpak_architecture(self, **kwargs):
def ensure_build_area(self):
os.makedirs(self.xdg_cache_dir, 0o700, exist_ok=True)
os.makedirs(self.build_area, 0o755, exist_ok=True)
os.makedirs(os.path.join(self.build_area, 'tmp'), exist_ok=True)
def octal_escape_char(self, match: 're.Match') -> str:
for byte in match.group(0).encode('utf-8', 'surrogateescape'):
ret.append('\\%03o' % byte)
return ''.join(ret)
_NEEDS_OCTAL_ESCAPE = re.compile(r'[^-A-Za-z0-9+,./:@_]')
def octal_escape(self, s: str) -> str:
return self._NEEDS_OCTAL_ESCAPE.sub(self.octal_escape_char, s)
scratch = stack.enter_context(
TemporaryDirectory(prefix='flatdeb.')
)
self.ensure_build_area()
# debootstrap only supports one suite, so we use the first