def __init__(self, name, version, release, arch, rpmbuild_path, source_date_epoch=None, debug=False): self.name = name self.version = GetFlagValue(version) self.release = GetFlagValue(release) self.arch = arch self.files = [] self.rpmbuild_path = FindRpmbuild(rpmbuild_path) self.rpm_path = None self.source_date_epoch = GetFlagValue(source_date_epoch) self.debug = debug
def main(): parser = argparse.ArgumentParser( description='Helper for building deb packages') parser.add_argument('--output', required=True, help='The output file, mandatory') parser.add_argument('--changes', required=True, help='The changes output file, mandatory.') parser.add_argument('--data', required=True, help='Path to the data tarball, mandatory') parser.add_argument( '--preinst', help='The preinst script (prefix with @ to provide a path).') parser.add_argument( '--postinst', help='The postinst script (prefix with @ to provide a path).') parser.add_argument( '--prerm', help='The prerm script (prefix with @ to provide a path).') parser.add_argument( '--postrm', help='The postrm script (prefix with @ to provide a path).') parser.add_argument( '--config', help='The config script (prefix with @ to provide a path).') parser.add_argument( '--templates', help='The templates file (prefix with @ to provide a path).') # see # https://www.debian.org/doc/manuals/debian-faq/ch-pkg_basics.en.html#s-conffile parser.add_argument( '--conffile', action='append', help='List of conffiles (prefix item with @ to provide a path)') AddControlFlags(parser) options = parser.parse_args() CreateDeb(options.output, options.data, preinst=GetFlagValue(options.preinst, False), postinst=GetFlagValue(options.postinst, False), prerm=GetFlagValue(options.prerm, False), postrm=GetFlagValue(options.postrm, False), config=GetFlagValue(options.config, False), templates=GetFlagValue(options.templates, False), conffiles=GetFlagValues(options.conffile), package=options.package, version=GetFlagValue(options.version), description=GetFlagValue(options.description), maintainer=GetFlagValue(options.maintainer), section=options.section, architecture=options.architecture, depends=GetFlagValues(options.depends), suggests=options.suggests, enhances=options.enhances, preDepends=options.pre_depends, recommends=options.recommends, replaces=options.replaces, homepage=GetFlagValue(options.homepage), builtUsing=GetFlagValue(options.built_using), priority=options.priority, conflicts=options.conflicts, breaks=options.breaks, installedSize=GetFlagValue(options.installed_size)) CreateChanges(output=options.changes, deb_file=options.output, architecture=options.architecture, short_description=GetFlagValue( options.description).split('\n')[0], maintainer=GetFlagValue(options.maintainer), package=options.package, version=GetFlagValue(options.version), section=options.section, priority=options.priority, distribution=options.distribution, urgency=options.urgency)
def GetFlagValues(flagvalues): if flagvalues: return [GetFlagValue(f, False) for f in flagvalues] else: return None
def main(unused_argv): CreateDeb(FLAGS.output, FLAGS.data, preinst=GetFlagValue(FLAGS.preinst, False), postinst=GetFlagValue(FLAGS.postinst, False), prerm=GetFlagValue(FLAGS.prerm, False), postrm=GetFlagValue(FLAGS.postrm, False), config=GetFlagValue(FLAGS.config, False), templates=GetFlagValue(FLAGS.templates, False), conffiles=GetFlagValues(FLAGS.conffile), package=FLAGS.package, version=GetFlagValue(FLAGS.version), description=GetFlagValue(FLAGS.description), maintainer=GetFlagValue(FLAGS.maintainer), section=FLAGS.section, architecture=FLAGS.architecture, depends=GetFlagValues(FLAGS.depends), suggests=FLAGS.suggests, enhances=FLAGS.enhances, preDepends=FLAGS.pre_depends, recommends=FLAGS.recommends, homepage=GetFlagValue(FLAGS.homepage), builtUsing=GetFlagValue(FLAGS.built_using), priority=FLAGS.priority, conflicts=FLAGS.conflicts, installedSize=GetFlagValue(FLAGS.installed_size)) CreateChanges(output=FLAGS.changes, deb_file=FLAGS.output, architecture=FLAGS.architecture, short_description=GetFlagValue( FLAGS.description).split('\n')[0], maintainer=GetFlagValue(FLAGS.maintainer), package=FLAGS.package, version=GetFlagValue(FLAGS.version), section=FLAGS.section, priority=FLAGS.priority, distribution=FLAGS.distribution, urgency=FLAGS.urgency)
def main(unused_argv): # Parse modes arguments default_mode = None if FLAGS.mode: # Convert from octal default_mode = int(FLAGS.mode, 8) mode_map = {} if FLAGS.modes: for filemode in FLAGS.modes: (f, mode) = unquote_and_split(filemode, '=') if f[0] == '/': f = f[1:] mode_map[f] = int(mode, 8) default_ownername = ('', '') if FLAGS.owner_name: default_ownername = FLAGS.owner_name.split('.', 1) names_map = {} if FLAGS.owner_names: for file_owner in FLAGS.owner_names: (f, owner) = unquote_and_split(file_owner, '=') (user, group) = owner.split('.', 1) if f[0] == '/': f = f[1:] names_map[f] = (user, group) default_ids = FLAGS.owner.split('.', 1) default_ids = (int(default_ids[0]), int(default_ids[1])) ids_map = {} if FLAGS.owners: for file_owner in FLAGS.owners: (f, owner) = unquote_and_split(file_owner, '=') (user, group) = owner.split('.', 1) if f[0] == '/': f = f[1:] ids_map[f] = (int(user), int(group)) # Add objects to the tar file with TarFile(FLAGS.output, GetFlagValue(FLAGS.directory), FLAGS.compression, FLAGS.root_directory, FLAGS.mtime) as output: def file_attributes(filename): if filename.startswith('/'): filename = filename[1:] return { 'mode': mode_map.get(filename, default_mode), 'ids': ids_map.get(filename, default_ids), 'names': names_map.get(filename, default_ownername), } if FLAGS.manifest: with open(FLAGS.manifest, 'r') as manifest_fp: manifest = json.load(manifest_fp) for f in manifest.get('files', []): output.add_file(f['src'], f['dst'], **file_attributes(f['dst'])) for f in manifest.get('empty_files', []): output.add_empty_file(f, **file_attributes(f)) for d in manifest.get('empty_dirs', []): output.add_empty_dir(d, **file_attributes(d)) for d in manifest.get('empty_root_dirs', []): output.add_empty_root_dir(d, **file_attributes(d)) for f in manifest.get('symlinks', []): output.add_link(f['linkname'], f['target']) for tar in manifest.get('tars', []): output.add_tar(tar) for deb in manifest.get('debs', []): output.add_deb(deb) for f in FLAGS.file: (inf, tof) = unquote_and_split(f, '=') output.add_file(inf, tof, **file_attributes(tof)) for f in FLAGS.empty_file: output.add_empty_file(f, **file_attributes(f)) for f in FLAGS.empty_dir: output.add_empty_dir(f, **file_attributes(f)) for f in FLAGS.empty_root_dir: output.add_empty_root_dir(f, **file_attributes(f)) for tar in FLAGS.tar: output.add_tar(tar) for deb in FLAGS.deb: output.add_deb(deb) for link in FLAGS.link: l = unquote_and_split(link, ':') output.add_link(l[0], l[1])
def main(): parser = argparse.ArgumentParser( description='Helper for building tar packages', fromfile_prefix_chars='@') parser.add_argument('--output', required=True, help='The output file, mandatory.') parser.add_argument('--file', action='append', help='A file to add to the layer.') parser.add_argument('--manifest', help='JSON manifest of contents to add to the layer.') parser.add_argument('--mode', help='Force the mode on the added files (in octal).') parser.add_argument( '--mtime', help='Set mtime on tar file entries. May be an integer or the' ' value "portable", to get the value 2000-01-01, which is' ' is usable with non *nix OSes.') parser.add_argument('--empty_file', action='append', help='An empty file to add to the layer.') parser.add_argument('--empty_dir', action='append', help='An empty dir to add to the layer.') parser.add_argument('--empty_root_dir', action='append', help='An empty dir to add to the layer.') parser.add_argument('--tar', action='append', help='A tar file to add to the layer') parser.add_argument('--deb', action='append', help='A debian package to add to the layer') parser.add_argument( '--link', action='append', help= 'Add a symlink a inside the layer pointing to b if a:b is specified') # TODO(aiuto): Add back in the validation # flags.register_validator( # 'link', # lambda l: all(value.find(':') > 0 for value in l), # message='--link value should contains a : separator') parser.add_argument( '--directory', help='Directory in which to store the file inside the layer') parser.add_argument('--compression', help='Compression (`gz` or `bz2`), default is none.') parser.add_argument( '--modes', action='append', help='Specific mode to apply to specific file (from the file argument),' ' e.g., path/to/file=0455.') parser.add_argument('--owners', action='append', help='Specify the numeric owners of individual files, ' 'e.g. path/to/file=0.0.') parser.add_argument('--owner', default='0.0', help='Specify the numeric default owner of all files,' ' e.g., 0.0') parser.add_argument( '--owner_name', help='Specify the owner name of all files, e.g. root.root.') parser.add_argument( '--owner_names', action='append', help='Specify the owner names of individual files, e.g. ' 'path/to/file=root.root.') parser.add_argument('--root_directory', default='./', help='Default root directory is named "."') options = parser.parse_args() # Parse modes arguments default_mode = None if options.mode: # Convert from octal default_mode = int(options.mode, 8) mode_map = {} if options.modes: for filemode in options.modes: (f, mode) = SplitNameValuePairAtSeparator(filemode, '=') if f[0] == '/': f = f[1:] mode_map[f] = int(mode, 8) default_ownername = ('', '') if options.owner_name: default_ownername = options.owner_name.split('.', 1) names_map = {} if options.owner_names: for file_owner in options.owner_names: (f, owner) = SplitNameValuePairAtSeparator(file_owner, '=') (user, group) = owner.split('.', 1) if f[0] == '/': f = f[1:] names_map[f] = (user, group) default_ids = options.owner.split('.', 1) default_ids = (int(default_ids[0]), int(default_ids[1])) ids_map = {} if options.owners: for file_owner in options.owners: (f, owner) = SplitNameValuePairAtSeparator(file_owner, '=') (user, group) = owner.split('.', 1) if f[0] == '/': f = f[1:] ids_map[f] = (int(user), int(group)) # Add objects to the tar file with TarFile(options.output, GetFlagValue(options.directory), options.compression, options.root_directory, options.mtime) as output: def file_attributes(filename): if filename.startswith('/'): filename = filename[1:] return { 'mode': mode_map.get(filename, default_mode), 'ids': ids_map.get(filename, default_ids), 'names': names_map.get(filename, default_ownername), } if options.manifest: with open(options.manifest, 'r') as manifest_fp: manifest = json.load(manifest_fp) for f in manifest.get('files', []): output.add_file(f['src'], f['dst'], **file_attributes(f['dst'])) for f in manifest.get('empty_files', []): output.add_empty_file(f, **file_attributes(f)) for d in manifest.get('empty_dirs', []): output.add_empty_dir(d, **file_attributes(d)) for d in manifest.get('empty_root_dirs', []): output.add_empty_root_dir(d, **file_attributes(d)) for f in manifest.get('symlinks', []): output.add_link(f['linkname'], f['target']) for tar in manifest.get('tars', []): output.add_tar(tar) for deb in manifest.get('debs', []): output.add_deb(deb) for f in options.file or []: (inf, tof) = SplitNameValuePairAtSeparator(f, '=') output.add_file(inf, tof, **file_attributes(tof)) for f in options.empty_file or []: output.add_empty_file(f, **file_attributes(f)) for f in options.empty_dir or []: output.add_empty_dir(f, **file_attributes(f)) for f in options.empty_root_dir or []: output.add_empty_root_dir(f, **file_attributes(f)) for tar in options.tar or []: output.add_tar(tar) for deb in options.deb or []: output.add_deb(deb) for link in options.link or []: l = SplitNameValuePairAtSeparator(link, ':') output.add_link(l[0], l[1])