Exemple #1
0
    def _create_tarball(self, output_dir, package_type, files, force,
                        package_prefix):
        filenames = []

        # Filter out some unwanted directories for the development package
        if package_type == PackageType.DEVEL:
            for filt in ['bin/', 'share/aclocal']:
                files = [x for x in files if not x.startswith(filt)]

        # Create the bz2 file first
        filename = os.path.join(output_dir, self._get_name(package_type))
        if os.path.exists(filename):
            if force:
                os.remove(filename)
            else:
                raise UsageError("File %s already exists" % filename)

        try:
            with tarfile.open(filename, "w:bz2") as tar:
                for f in files:
                    filepath = os.path.join(self.prefix, f)
                    tar.add(filepath, os.path.join(package_prefix, f))
        except OSError:
            os.replace(filename, filename + '.partial')
            raise

        filenames.append(filename)

        return ' '.join(filenames)
Exemple #2
0
 def validate_platform_files(self, platform_files):
     for f in platform_files:
         platform = f[:f.index(':')]
         if not platform in self.supported_platforms:
             raise UsageError(
                 _("Error creating package: "
                   "invalid platform '%s'") % platform)
Exemple #3
0
    def run(self, config, args):
        self.store = PackagesStore(config)
        p = self.store.get_package(args.package[0])

        if args.skip_deps_build and args.only_build_deps:
            raise UsageError(_("Cannot use --skip-deps-build together with "
                    "--only-build-deps"))

        if not args.skip_deps_build:
            self._build_deps(config, p, args.no_devel)

        if args.only_build_deps:
            return

        if p is None:
            raise PackageNotFoundError(args.package[0])
        if args.tarball:
            pkg = DistTarball(config, p, self.store)
        else:
            pkg = Packager(config, p, self.store)
        m.action(_("Creating package for %s") % p.name)
        if args.tarball:
            paths = pkg.pack(os.path.abspath(args.output_dir), args.no_devel,
                             args.force, args.keep_temp, split=not args.no_split)
        else:
            paths = pkg.pack(os.path.abspath(args.output_dir), args.no_devel,
                             args.force, args.keep_temp)
        if None in paths:
            paths.remove(None)
        p.post_install(paths)
        m.action(_("Package successfully created in %s") %
                 ' '.join([os.path.abspath(x) for x in paths]))
Exemple #4
0
    def run(self, config, args):
        self.store = PackagesStore(config, offline=args.offline)
        p = self.store.get_package(args.package[0])

        if args.skip_deps_build and args.only_build_deps:
            raise UsageError(
                _("Cannot use --skip-deps-build together with "
                  "--only-build-deps"))

        if not args.skip_deps_build:
            self._build_deps(config, p, args.no_devel, args.offline,
                             args.dry_run, args.jobs)

        if args.only_build_deps or args.dry_run:
            return

        if args.compress_method != 'default':
            m.message('Forcing tarball compression method as ' +
                      args.compress_method)
            config.package_tarball_compression = args.compress_method

        if p is None:
            raise PackageNotFoundError(args.package[0])

        p.pre_package()
        packager_class = Packager
        if args.tarball:
            if config.target_platform == Platform.ANDROID and \
               config.target_arch == Architecture.UNIVERSAL:
                packager_class = AndroidPackager
            else:
                packager_class = DistTarball
        elif config.variants.uwp:
            # Split devel/runtime packages are useless for UWP since we will
            # need both when building the package, and all needed runtime DLLs
            # are packaged with the app as assets.
            m.warning('Forcing single-tarball output for UWP package')
            args.no_split = True
            packager_class = DistTarball

        m.action(_("Creating package for %s") % p.name)
        pkg = packager_class(config, p, self.store)
        output_dir = os.path.abspath(args.output_dir)
        if isinstance(pkg, DistTarball):
            paths = pkg.pack(output_dir,
                             args.no_devel,
                             args.force,
                             args.keep_temp,
                             split=not args.no_split,
                             strip_binaries=p.strip)
        else:
            paths = pkg.pack(output_dir, args.no_devel, args.force,
                             args.keep_temp)
        if None in paths:
            paths.remove(None)
        paths = p.post_package(paths, output_dir) or paths
        m.action(
            _("Package successfully created in %s") %
            ' '.join([os.path.abspath(x) for x in paths]))
Exemple #5
0
    def _create_tarball(self, output_dir, package_type, files, force,
                        package_prefix):
        filenames = []

        # Filter out some unwanted directories for the development package
        if package_type == PackageType.DEVEL:
            for filt in ['bin/', 'share/aclocal']:
                files = [x for x in files if not x.startswith(filt)]

        # Create the bz2 file first
        filename = os.path.join(output_dir, self._get_name(package_type))
        if os.path.exists(filename):
            if force:
                os.remove(filename)
            else:
                raise UsageError("File %s already exists" % filename)

        tar = tarfile.open(filename, "w:bz2")

        for f in files:
            filepath = os.path.join(self.prefix, f)
            tar.add(filepath, os.path.join(package_prefix, f))
        tar.close()
        filenames.append(filename)

        # Create the zip file for windows
        filename = os.path.join(output_dir,
                                self._get_name(package_type, ext='zip'))
        if os.path.exists(filename):
            if force:
                os.remove(filename)
            else:
                raise UsageError("File %s already exists" % filename)

        zipf = zipfile.ZipFile(filename, 'w')

        for f in files:
            filepath = os.path.join(self.prefix, f)
            zipf.write(filepath,
                       os.path.join(package_prefix, f),
                       compress_type=zipfile.ZIP_DEFLATED)
        zipf.close()
        filenames.append(filename)

        return ' '.join(filenames)
Exemple #6
0
    def run(self, config, args):
        name = args.name[0]
        version = args.version[0]
        filename = os.path.join(config.recipes_dir, '%s.recipe' % name)
        if not args.force and os.path.exists(filename):
            m.warning(
                _("Recipe '%s' (%s) already exists, "
                  "use -f to replace" % (name, filename)))
            return

        template_args = {}

        template = RECEIPT_TPL
        template_args['name'] = name
        template_args['version'] = version

        if args.licenses:
            licenses = args.licenses.split(',')
            self.validate_licenses(licenses)
            template += LICENSES_TPL
            template_args['licenses'] = ', '.join(
                    ['License.' + self.supported_licenses[l] \
                        for l in licenses])

        if args.commit:
            template += COMMIT_TPL
            template_args['commit'] = args.commit

        if args.origin:
            template += ORIGIN_TPL
            template_args['origin'] = args.origin

        if args.deps:
            template += DEPS_TPL
            deps = args.deps.split(',')
            cookbook = CookBook(config)
            for dname in deps:
                try:
                    recipe = cookbook.get_recipe(dname)
                except RecipeNotFoundError as ex:
                    raise UsageError(
                        _("Error creating recipe: "
                          "dependant recipe %s does not exist") % dname)
            template_args['deps'] = deps

        try:
            f = open(filename, 'w')
            f.write(template % template_args)
            f.close()

            m.action(
                _("Recipe '%s' successfully created in %s") % (name, filename))
        except IOError as ex:
            raise FatalError(_("Error creating recipe: %s") % ex)
Exemple #7
0
 def __init__(self, config, package, store):
     PackagerBase.__init__(self, config, package, store)
     self.package = package
     self.prefix = config.prefix
     self.package_prefix = ''
     if self.config.packages_prefix is not None:
         self.package_prefix = '%s-' % self.config.packages_prefix
     self.compress = config.package_tarball_compression
     if self.compress not in ('bz2', 'xz'):
         raise UsageError('Invalid compression type {!r}'.format(
             self.compress))
Exemple #8
0
    def run(self, config, args):
        name = args.name[0]
        version = args.version[0]
        store = PackagesStore(config)
        filename = os.path.join(config.packages_dir, '%s.package' % name)
        if not args.force and os.path.exists(filename):
            m.warning(
                _("Package '%s' (%s) already exists, "
                  "use -f to replace" % (name, filename)))
            return

        template_args = {}

        template = RECEIPT_TPL
        template_args['name'] = name
        template_args['version'] = version

        if args.short_desc:
            template_args['shortdesc'] = args.short_desc
        else:
            template_args['shortdesc'] = name

        if args.codename:
            template += CODENAME_TPL
            template_args['codename'] = args.codename

        if args.vendor:
            template += VENDOR_TPL
            template_args['vendor'] = args.vendor

        if args.url:
            template += URL_TPL
            template_args['url'] = args.url

        if args.license:
            self.validate_licenses([args.license])
            template += LICENSE_TPL
            template_args['license'] = \
                'License.' + self.supported_licenses[args.license]

        deps = []
        if args.deps:
            template += DEPS_TPL
            deps = args.deps.split(',')
            for dname in deps:
                try:
                    package = store.get_package(dname)
                except Exception, ex:
                    raise UsageError(
                        _("Error creating package: "
                          "dependant package %s does not exist") % dname)
            template_args['deps'] = deps
Exemple #9
0
 def _create_tarball(self, output_dir, package_type, files, force,
                     package_prefix):
     filename = os.path.join(output_dir, self._get_name(package_type))
     if os.path.exists(filename):
         if force:
             os.remove(filename)
         else:
             raise UsageError("File %s already exists" % filename)
     if self.config.platform == Platform.WINDOWS:
         self._write_tarfile(filename, package_prefix, files)
     else:
         self._write_tar(filename, package_prefix, files)
     return filename
Exemple #10
0
    def run(self, config, args):
        self.store = PackagesStore(config, offline=args.offline)
        p = self.store.get_package(args.package[0])

        if args.skip_deps_build and args.only_build_deps:
            raise UsageError(
                _("Cannot use --skip-deps-build together with "
                  "--only-build-deps"))

        if not args.skip_deps_build:
            self._build_deps(config, p, args.no_devel, args.offline,
                             args.dry_run)

        if args.only_build_deps or args.dry_run:
            return

        if args.xz:
            config.package_tarball_compression = 'xz'

        if p is None:
            raise PackageNotFoundError(args.package[0])
        p.pre_package()
        if args.tarball:
            if config.target_platform == Platform.ANDROID and \
               config.target_arch == Architecture.UNIVERSAL:
                pkg = AndroidPackager(config, p, self.store)
            else:
                pkg = DistTarball(config, p, self.store)
        else:
            pkg = Packager(config, p, self.store)
        m.action(_("Creating package for %s") % p.name)
        output_dir = os.path.abspath(args.output_dir)
        if args.tarball:
            paths = pkg.pack(output_dir,
                             args.no_devel,
                             args.force,
                             args.keep_temp,
                             split=not args.no_split,
                             strip_binaries=p.strip)
        else:
            paths = pkg.pack(output_dir, args.no_devel, args.force,
                             args.keep_temp)
        if None in paths:
            paths.remove(None)
        paths = p.post_package(paths, output_dir) or paths
        m.action(
            _("Package successfully created in %s") %
            ' '.join([os.path.abspath(x) for x in paths]))
Exemple #11
0
    def runargs(self, config, output_dir, filename, libraries):
        if not os.path.exists(output_dir):
            os.makedirs(output_dir)

        if len(libraries) == 0:
            raise UsageError("You need to specify at least one library name")

        filename = filename or libraries[0]
        filepath = os.path.join(output_dir, '%s.xcconfig' % filename)

        xcconfig = XCConfig(libraries)
        xcconfig.create(filepath)
        m.action('Created %s.xcconfig' % filename)

        m.message('XCode config file were sucessfully created in %s' %
                  os.path.abspath(filepath))
Exemple #12
0
    def run(self, config, args):
        if config.target_platform != Platform.WINDOWS:
            raise UsageError(_('%s command can only be used targetting '
                             'Windows platforms') % self.name)

        if args.output_dir is not None and not os.path.exists(args.output_dir):
            os.makedirs(args.output_dir)

        cookbook = CookBook(config)
        recipes = cookbook.get_recipes_list()
        for recipe in recipes:
            try:
                recipe.gen_library_file(args.output_dir)
            except Exception as e:
                m.message(_("Error generaring library files for %s:\n %s") %
                          (recipe.name, e))
Exemple #13
0
    def __init__(self, config, package, store, archive_type):
        PackagerBase.__init__(self, config, package, store)
        self.package = package
        self.prefix = config.prefix
        self.package_prefix = ''
        if self.config.packages_prefix is not None:
            self.package_prefix = '%s-' % self.config.packages_prefix

        if archive_type == ArchiveType.TARBALL:
            self.ext = 'tar.bz2'
            self.archive_func = self._create_tarball
        elif archive_type == ArchiveType.ZIP:
            self.ext = 'zip'
            self.archive_func = self._create_zip
        else:
            raise UsageError("Unsupported archive_type %s" % archive_type)
Exemple #14
0
    def _create_tarball(self, output_dir, package_type, files, force,
                        package_prefix):
        filename = os.path.join(output_dir, self._get_name(package_type))
        if os.path.exists(filename):
            if force:
                os.remove(filename)
            else:
                raise UsageError("File %s already exists" % filename)

        tar = tarfile.open(filename, "w:bz2")

        for f in files:
            filepath = os.path.join(self.prefix, f)
            tar.add(filepath, os.path.join(package_prefix, f))
        tar.close()

        return filename
Exemple #15
0
    def _create_archive(self,
                        output_dir,
                        package_type,
                        files,
                        force,
                        package_prefix,
                        relocatable=False):
        filename = os.path.join(output_dir, self.get_name(package_type))
        if os.path.exists(filename):
            if force:
                os.remove(filename)
            else:
                raise UsageError("File %s already exists" % filename)

        self.archive_func(filename, files, package_prefix, relocatable)

        return filename
Exemple #16
0
class AddPackage(Command):
    doc = N_('Adds a new package')
    name = 'add-package'

    def __init__(self):
        self.supported_licenses = {}
        l = License
        for name in l.__dict__:
            attr = getattr(l, name)
            if not isinstance(attr, LicenseDescription):
                continue
            self.supported_licenses[attr.acronym] = name

        self.supported_platforms = {
            'linux': 'Platform.LINUX',
            'windows': 'Platform.WINDOWS',
            'darwin': 'Platform.DARWIN'
        }

        Command.__init__(self, [
            ArgparseArgument('name', nargs=1, help=_('name of the package')),
            ArgparseArgument(
                'version', nargs=1, help=_('version of the package')),
            ArgparseArgument('-s',
                             '--short-desc',
                             default='',
                             help=_('a short description of the package')),
            ArgparseArgument('-c',
                             '--codename',
                             default='',
                             help=_('a codename for the package')),
            ArgparseArgument(
                '-v', '--vendor', default='', help=_('the package vendor')),
            ArgparseArgument(
                '-u', '--url', default='', help=_('the package url')),
            ArgparseArgument('-l',
                             '--license',
                             default='',
                             help=_('license of the package. '
                                    'Supported licenses: %s') %
                             ', '.join(self.supported_licenses.keys())),
            ArgparseArgument('-d',
                             '--deps',
                             default='',
                             help=_('comma separated list of the package '
                                    'dependencies')),
            ArgparseArgument('-i',
                             '--includes',
                             default='',
                             help=_('comma separated list of packages to '
                                    'include in this package. All files '
                                    'from the packages passed as param '
                                    'will be added to this package.')),
            ArgparseArgument('--files',
                             default='',
                             help=_('comma separated list of recipe files to '
                                    'add to the runtime package '
                                    '(e.g.: recipe1:category1:category2,'
                                    'recipe2)')),
            ArgparseArgument('--files-devel',
                             default='',
                             help=_('comma separated list of recipe files to '
                                    'add to the devel package '
                                    '(e.g.: recipe1:category1:category2,'
                                    'recipe2)')),
            ArgparseArgument('--platform-files',
                             default='',
                             help=_('comma separated list of platform:recipe '
                                    'files to add to the runtime package '
                                    '(e.g.: linux:recipe1:category1:category2,'
                                    'windows:recipe2) '
                                    'Supported platforms: %s') %
                             ', '.join(self.supported_platforms.keys())),
            ArgparseArgument('--platform-files-devel',
                             default='',
                             help=_('comma separated list of platform:recipe '
                                    'files to add to the devel package '
                                    '(e.g.: linux:recipe1:category1:category2,'
                                    'windows:recipe2) '
                                    'Supported platforms: %s') %
                             ', '.join(self.supported_platforms.keys())),
            ArgparseArgument('-f',
                             '--force',
                             action='store_true',
                             default=False,
                             help=_('Replace package if existing'))
        ])

    def run(self, config, args):
        name = args.name[0]
        version = args.version[0]
        store = PackagesStore(config)
        filename = os.path.join(config.packages_dir, '%s.package' % name)
        if not args.force and os.path.exists(filename):
            m.warning(
                _("Package '%s' (%s) already exists, "
                  "use -f to replace" % (name, filename)))
            return

        template_args = {}

        template = RECEIPT_TPL
        template_args['name'] = name
        template_args['version'] = version

        if args.short_desc:
            template_args['shortdesc'] = args.short_desc
        else:
            template_args['shortdesc'] = name

        if args.codename:
            template += CODENAME_TPL
            template_args['codename'] = args.codename

        if args.vendor:
            template += VENDOR_TPL
            template_args['vendor'] = args.vendor

        if args.url:
            template += URL_TPL
            template_args['url'] = args.url

        if args.license:
            self.validate_licenses([args.license])
            template += LICENSE_TPL
            template_args['license'] = \
                'License.' + self.supported_licenses[args.license]

        deps = []
        if args.deps:
            template += DEPS_TPL
            deps = args.deps.split(',')
            for dname in deps:
                try:
                    package = store.get_package(dname)
                except Exception, ex:
                    raise UsageError(
                        _("Error creating package: "
                          "dependant package %s does not exist") % dname)
            template_args['deps'] = deps

        include_files = []
        include_files_devel = []
        platform_include_files = {}
        platform_include_files_devel = {}
        if args.includes:
            includes = args.includes.split(',')
            if list(set(deps) & set(includes)):
                raise UsageError(
                    _("Error creating package: "
                      "param --deps intersects with --includes"))
            for pname in includes:
                try:
                    package = store.get_package(pname)
                except Exception, ex:
                    raise UsageError(
                        _("Error creating package: "
                          "included package %s does not exist") % pname)
                include_files.extend(package.files)
                include_files_devel.extend(package.files_devel)
                platform_include_files = self.merge_dict(
                    platform_include_files, package.platform_files)
                platform_include_files_devel = self.merge_dict(
                    platform_include_files_devel, package.platform_files_devel)
Exemple #17
0
    def run(self, config, args):
        name = args.name[0]
        version = args.version[0]
        store = PackagesStore(config)
        filename = os.path.join(config.packages_dir, '%s.package' % name)
        if not args.force and os.path.exists(filename):
            m.warning(_("Package '%s' (%s) already exists, "
                "use -f to replace" % (name, filename)))
            return

        template_args = {}

        template = RECEIPT_TPL
        template_args['name'] = name
        template_args['version'] = version

        if args.short_desc:
            template_args['shortdesc'] = args.short_desc
        else:
            template_args['shortdesc'] = name

        if args.vendor:
            template += VENDOR_TPL
            template_args['vendor'] = args.vendor

        if args.url:
            template += URL_TPL
            template_args['url'] = args.url

        if args.license:
            self.validate_licenses([args.license])
            template += LICENSE_TPL
            template_args['license'] = \
                'License.' + self.supported_licenses[args.license]

        deps = []
        if args.deps:
            template += DEPS_TPL
            deps = args.deps.split(',')
            for dname in deps:
                try:
                    package = store.get_package(dname)
                except Exception as ex:
                    raise UsageError(_("Error creating package: "
                            "dependant package %s does not exist") % dname)
            template_args['deps'] = deps

        include_files = []
        include_files_devel = []
        platform_include_files = {}
        platform_include_files_devel = {}
        if args.includes:
            includes = args.includes.split(',')
            if list(set(deps) & set(includes)):
                raise UsageError(_("Error creating package: "
                        "param --deps intersects with --includes"))
            for pname in includes:
                try:
                    package = store.get_package(pname)
                except Exception as ex:
                    raise UsageError(_("Error creating package: "
                            "included package %s does not exist") % pname)
                include_files.extend(package.files)
                include_files_devel.extend(package.files_devel)
                platform_include_files = self.merge_dict(
                        platform_include_files,
                        package.platform_files)
                platform_include_files_devel = self.merge_dict(
                        platform_include_files_devel,
                        package.platform_files_devel)

        include_files = list(set(include_files))
        include_files_devel = list(set(include_files_devel))

        if args.files or include_files:
            template += FILES_TPL
            files = []
            if args.files:
                files = args.files.split(',')
            if include_files:
                files.extend(include_files)
            template_args['files'] = files

        if args.files_devel or include_files_devel:
            template += FILES_DEVEL_TPL
            files_devel = []
            if args.files_devel:
                files_devel = args.files_devel.split(',')
            if include_files_devel:
                files_devel.extend(include_files_devel)
            template_args['files_devel'] = files_devel

        if args.platform_files or platform_include_files:
            template += PLATFORM_FILES_TPL
            platform_files = self.parse_platform_files(
                    args.platform_files, platform_include_files)
            template_args['platform_files'] = platform_files

        if args.platform_files_devel or platform_include_files_devel:
            template += PLATFORM_FILES_DEVEL_TPL
            platform_files_devel = self.parse_platform_files(
                    args.platform_files_devel,
                    platform_include_files_devel)
            template_args['platform_files_devel'] = platform_files_devel

        try:
            f = open(filename, 'w')
            f.write(template % template_args)
            f.close()

            m.action(_("Package '%s' successfully created in %s") %
                    (name, filename))
        except IOError as ex:
            raise FatalError(_("Error creating package: %s") % ex)
Exemple #18
0
 def validate_licenses(self, licenses):
     for l in licenses:
         if l and not l in self.supported_licenses:
             raise UsageError(_("Error creating package: "
                 "invalid license '%s'") % l)