Beispiel #1
0
  def __init__(self, name, version, release, arch, rpmbuild_path,
               source_date_epoch=None,
               debug=False):
    self.name = name
    self.version = helpers.GetFlagValue(version)
    self.release = helpers.GetFlagValue(release)
    self.arch = arch
    self.files = []
    self.rpmbuild_path = FindRpmbuild(rpmbuild_path)
    self.rpm_path = None
    self.source_date_epoch = helpers.GetFlagValue(source_date_epoch)
    self.debug = debug

    # The below are initialized in SetupWorkdir()
    self.spec_file = None

    self.preamble_file = None
    self.description_file = None
    self.install_script_file = None
    self.file_list_path = None

    self.pre_scriptlet = None
    self.post_scriptlet = None
    self.preun_scriptlet = None
    self.postun_scriptlet = None
Beispiel #2
0
 def testStripped_fromFile(self):
   with tempfile.TemporaryDirectory() as temp_d:
     argfile_path = os.path.join(temp_d, 'argfile')
     with open(argfile_path, 'wb') as f:
       f.write(b'value ')
     self.assertEqual(
         helpers.GetFlagValue('@'+argfile_path, strip=True), 'value')
Beispiel #3
0
 def testStripped(self):
   self.assertEqual(helpers.GetFlagValue('value ', strip=True), 'value')
Beispiel #4
0
 def testNonStripped(self):
   self.assertEqual(helpers.GetFlagValue('value ', strip=False), 'value ')
Beispiel #5
0
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).')
    parser.add_argument(
        '--triggers',
        help='The triggers 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=helpers.GetFlagValue(options.preinst, False),
              postinst=helpers.GetFlagValue(options.postinst, False),
              prerm=helpers.GetFlagValue(options.prerm, False),
              postrm=helpers.GetFlagValue(options.postrm, False),
              config=helpers.GetFlagValue(options.config, False),
              templates=helpers.GetFlagValue(options.templates, False),
              triggers=helpers.GetFlagValue(options.triggers, False),
              conffiles=GetFlagValues(options.conffile),
              package=options.package,
              version=helpers.GetFlagValue(options.version),
              description=helpers.GetFlagValue(options.description),
              maintainer=helpers.GetFlagValue(options.maintainer),
              section=options.section,
              architecture=helpers.GetFlagValue(options.architecture),
              depends=GetFlagValues(options.depends),
              suggests=options.suggests,
              enhances=options.enhances,
              preDepends=options.pre_depends,
              recommends=options.recommends,
              replaces=options.replaces,
              provides=options.provides,
              homepage=helpers.GetFlagValue(options.homepage),
              builtUsing=helpers.GetFlagValue(options.built_using),
              priority=options.priority,
              conflicts=options.conflicts,
              breaks=options.breaks,
              installedSize=helpers.GetFlagValue(options.installed_size))
    CreateChanges(output=options.changes,
                  deb_file=options.output,
                  architecture=options.architecture,
                  short_description=helpers.GetFlagValue(
                      options.description).split('\n')[0],
                  maintainer=helpers.GetFlagValue(options.maintainer),
                  package=options.package,
                  version=helpers.GetFlagValue(options.version),
                  section=options.section,
                  priority=options.priority,
                  distribution=options.distribution,
                  urgency=options.urgency)
Beispiel #6
0
def GetFlagValues(flagvalues):
    if flagvalues:
        return [helpers.GetFlagValue(f, False) for f in flagvalues]
    else:
        return None
Beispiel #7
0
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('--manifest',
                        help='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('--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(
        '--directory',
        help='Directory in which to store the file inside the layer')

    compression = parser.add_mutually_exclusive_group()
    compression.add_argument(
        '--compression', help='Compression (`gz` or `bz2`), default is none.')
    compression.add_argument('--compressor',
                             help='Compressor program and arguments, '
                             'e.g. `pigz -p 4`')

    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('--stamp_from',
                        default='',
                        help='File to find BUILD_STAMP in')
    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) = helpers.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) = helpers.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) = helpers.SplitNameValuePairAtSeparator(file_owner, '=')
            (user, group) = owner.split('.', 1)
            if f[0] == '/':
                f = f[1:]
            ids_map[f] = (int(user), int(group))

    default_mtime = options.mtime
    if options.stamp_from:
        default_mtime = build_info.get_timestamp(options.stamp_from)

    # Add objects to the tar file
    with TarFile(options.output,
                 directory=helpers.GetFlagValue(options.directory),
                 compression=options.compression,
                 compressor=options.compressor,
                 default_mtime=default_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 entry in manifest:
                    output.add_manifest_entry(entry, file_attributes)

        for tar in options.tar or []:
            output.add_tar(tar)
        for deb in options.deb or []:
            output.add_deb(deb)