Beispiel #1
0
def get_metadata_from_package(package_file, package=None):
    metadata_file_name = configfile.PACKAGE_METADATA_FILE
    metadata_file = extract_metadata_from_package(package_file,
                                                  metadata_file_name)
    if not metadata_file:
        logger.warning(
            "WARNING: Archive '%s' does not contain metadata; build will be marked as dirty"
            % os.path.basename(package_file))
        # Create a dummy metadata description for a package whose archive does not have one
        metadata = configfile.MetadataDescription()
        # split_tarname() returns a sequence like:
        # ("/some/path", ["boost", "1.39.0", "darwin", "20100222a"], ".tar.bz2")
        ignore_dir, from_name, ignore_ext = common.split_tarname(package_file)
        metadata.platform = from_name[2]
        metadata.build_id = from_name[3]
        metadata.configuration = 'unknown'
        if package is not None:
            if from_name[0] != package.name:
                raise InstallError("configured package name '%s' does not match name from archive '%s'" \
                                   % (package.name, from_name[0]))
            metadata.archive = package['platforms'][
                metadata.platform]['archive']
            metadata.package_description = package.copy()
        else:
            metadata.archive = configfile.ArchiveDescription()
            metadata.package_description = configfile.PackageDescription({})
        metadata.package_description.version = from_name[1]
        metadata.package_description.name = from_name[0]
        del metadata.package_description['platforms']
        metadata.dirty = True
    else:
        metadata = configfile.MetadataDescription(stream=metadata_file)
    return metadata
Beispiel #2
0
def _install_local(configured_name, platform, package, package_path,
                   install_dir, installed, dry_run):
    logger.info("installing %s from local archive" % package.name)
    metadata, files = _install_common(configured_name, platform, package,
                                      package_path, install_dir, installed,
                                      dry_run)

    if metadata:
        installed_package = package.copy()
        if platform not in package.platforms:
            installed_platform = configfile.PlatformDescription(
                dict(name=platform))
        else:
            installed_platform = installed_package.get_platform(platform)
        if installed_platform.archive is None:
            installed_platform.archive = configfile.ArchiveDescription()
        installed_platform.archive.url = "file://" + os.path.abspath(
            package_path)
        installed_platform.archive.hash = common.compute_md5(package_path)
        metadata.install_type = 'local'
        metadata.dirty = True
        logger.warning(
            "Using --local install flags any resulting package as 'dirty'")
        _update_installed_package_files(metadata,
                                        installed_package,
                                        platform=platform,
                                        installed=installed,
                                        install_dir=install_dir,
                                        files=files)
        return True
    else:
        return False
Beispiel #3
0
 def _create_or_update_platform_archive(self, platform, format,
                                        hash_algorithm):
     try:
         platform_description = self.config.get_platform(platform)
     except configfile.ConfigurationError:
         platform_description = configfile.PlatformDescription(
             {'name': platform})
         self.config.package_description.platforms[
             platform] = platform_description
     if platform_description.archive is None:
         platform_description.archive = configfile.ArchiveDescription()
     platform_description.archive.format = format
     platform_description.archive.hash_algorithm = hash_algorithm
def _install_binary(configured_name, platform, package, config_file, install_dir, installed, dry_run):
    # Check that we have a platform-specific or common url to use.
    req_plat = package.get_platform(platform)
    package_name = getattr(package, 'name', '(undefined)')
    if not req_plat:
        logger.warning("package %s has no installation information configured for platform %s"
                       % (package_name, platform))
        return False
    archive = req_plat.archive
    if not archive:
        raise InstallError("no archive specified for package %s for platform %s" %
                           (package_name, platform))
    if not archive.url:
        raise InstallError("no url specified for package %s for platform %s" % (package_name, platform))
    # Is this package already installed?
    installed_pkg = installed.dependencies.get(package.name)

    # Rely on ArchiveDescription's equality-comparison method to discover
    # whether the installed ArchiveDescription matches the requested one. This
    # test also handles the case when inst_plat.archive is None (not yet
    # installed).
    if installed_pkg and installed_pkg['install_type'] == 'local':
        logger.warning("""skipping %s package because it was installed locally from %s
  To allow new installation, run 
  autobuild uninstall %s""" % (package_name, installed_pkg['archive']['url'], package_name))
        return False

    # get the package file in the cache, downloading if needed, and verify the hash
    # (raises InstallError on failure, so no check is needed)
    cachefile = get_package_file(package_name, archive.url, hash_algorithm=(archive.hash_algorithm or 'md5'), expected_hash=archive.hash)
    if cachefile is None:
        raise InstallError("Failed to download package '%s' from '%s'" % (package_name, archive.url))

    metadata, files = _install_common(configured_name, platform, package, cachefile, install_dir, installed, dry_run)
    if metadata:
        installed_package = package.copy()
        if platform not in package.platforms:
            installed_platform = configfile.PlatformDescription(dict(name=platform))
        else:
            installed_platform = installed_package.get_platform(platform)
        if installed_platform.archive is None:
            installed_platform.archive = configfile.ArchiveDescription()
        metadata.install_type = 'package'
        _update_installed_package_files(metadata, package,
                                        platform=platform, installed=installed,
                                        install_dir=install_dir, files=files)
        return True
    else:
        return False
def _get_new_metadata(config, args_name, args_archive, arguments):
    # Get any name/value pairs from the command line
    key_values = _dict_from_key_value_arguments(arguments)

    if args_archive and 'url' in key_values:
        raise InstallablesError("--archive (%s) and url (%s) may not both be specified" \
                                % (args_archive, key_values['url']))
    if args_archive:
        archive_path = args_archive.strip()
    elif 'url' in key_values:
        archive_path = key_values.pop('url')
    else:
        archive_path = None
    archive_file = None
    if archive_path:
        if _is_uri(archive_path):
            archive_url = archive_path
        else:
            archive_url = 'file://' + config.absolute_path(archive_path)
        archive_file = get_package_file(
            args_name,
            archive_url,
            hash_algorithm=key_values.get('hash_algorithm', 'md5'),
            expected_hash=key_values.get('hash', None))
        if archive_file:
            metadata = get_metadata_from_package(archive_file)
            metadata.archive = configfile.ArchiveDescription()
            metadata.archive.url = archive_url
            if 'hash' not in key_values:
                logger.warning("No hash specified, computing from %s" %
                               archive_file)
                metadata.archive['hash'] = common.compute_md5(archive_file)
                metadata.archive['hash_algorithm'] = 'md5'

    if archive_file is None:
        logger.warning(
            "Archive not downloaded; some integrity checks may not work")
        metadata = configfile.MetadataDescription(create_quietly=True)
        metadata.package_description = configfile.PackageDescription(
            dict(name=args_name))
        metadata.archive = configfile.ArchiveDescription()
        metadata.archive.url = archive_path

    package_name = _check_name(args_name, key_values, metadata)
    if metadata.package_description['name'] is None:
        metadata.package_description['name'] = package_name

    for description_key in _PACKAGE_ATTRIBUTES:
        if description_key in key_values:
            logger.warning(
                "specifying '%s' in the installable is no longer required\n  if it is in the package metadata"
                % description_key)
            if description_key in metadata.package_description \
              and metadata.package_description[description_key] is not None \
              and key_values[description_key] != metadata.package_description[description_key]:
                raise InstallablesError("command line %s (%s) does not match archive %s (%s)" \
                                        % (description_key, key_values[description_key],
                                           description_key, metadata.package_description[description_key]))
            else:
                metadata.package_description[description_key] = key_values.pop(
                    description_key)

    for archive_key in _ARCHIVE_ATTRIBUTES:
        if archive_key in key_values:
            if archive_key in metadata.archive \
              and metadata.archive[archive_key] \
              and key_values[archive_key] != metadata.archive[archive_key]:
                raise InstallablesError("command line %s (%s) does not match archive %s (%s)" \
                                        % (archive_key, key_values[archive_key],
                                           archive_key, metadata.archive[archive_key]))
            else:
                metadata.archive[archive_key] = key_values.pop(archive_key)

    if 'platform' in key_values:
        if 'platform' in metadata \
          and metadata['platform'] is not None \
          and key_values['platform'] != metadata['platform'] \
          and metadata['platform'] != common.PLATFORM_COMMON:
            raise InstallablesError("specified platform '%s' does not match archive platform '%s'" \
                                    % ( key_values['platform'], metadata['platform']))
        else:
            platform = key_values.pop('platform')
    else:
        if 'platform' in metadata \
          and metadata['platform'] is not None:
            platform = metadata['platform']
        else:
            raise InstallablesError("Unspecified platform")

    platform_description = configfile.PlatformDescription()
    platform_description.name = platform
    platform_description.archive = metadata.archive.copy()

    _warn_unused(key_values)
    return (metadata, platform_description)