Example #1
0
    def download_release(self):
        """
        Download uWSGI release based on "version" option and return path to downloaded file.
        """
        if self.cache_dir is not None:
            download = Download(cache=self.cache_dir)
        else:
            self.log.warning("not using a download cache for uwsgi")
            download = Download()

        download_url = self.options.get("download-url", DOWNLOAD_URL)
        download_path, is_temp = download(download_url.format(
            self.uwsgi_version),
                                          md5sum=self.md5sum)
        return download_path
Example #2
0
def mp_download(url):
    global ws
    req = pkg_resources.Requirement.parse([url])
    pkg = ws._obtain(req)
    if pkg.location:
        download = Download(cache=dc)
        download(pkg.location)
Example #3
0
 def install(self):
     '''Install Jython.'''
     logger = logging.getLogger(self.name)
     downloader = Download(self.buildout['buildout'],
                           namespace='sk.recipe.jython',
                           logger=logger)
     url, md5sum = self.options['url'], self.options['md5sum']
     if len(md5sum) == 0:
         md5sum = None
     installerPath, isInstallerTemporary = downloader(url, md5sum)
     java, jre, destination = self.options['java'], self.options[
         'jre'], self.options['location']
     if not os.path.isdir(destination):
         os.makedirs(destination)
     args = [
         java, '-jar', installerPath, '--silent', '--directory', destination
     ]
     if jre:
         args.extend(['--jre', jre])
     if len(self.parts) > 0:
         args.append('--include')
         args.extend(self.parts)
     rc = subprocess.call(args)
     if rc != 0:
         raise SystemError(
             'Jython installer return nonzero (%d) status; invoked with %r'
             % (rc, args))
     return destination
Example #4
0
 def download_release(self):
     """
     Download uWSGI release based on 'version' option and return path to downloaded file.
     """
     cache = self.buildout['buildout'].get('download-cache', None)
     download = Download(cache=cache)
     download_url = self.options.get(
         'url', 'http://projects.unbit.it/downloads/uwsgi-latest.tar.gz')
     download_path, is_temp = download(download_url)
     return download_path
 def download_release(self):
     """
     Download uWSGI release based on "version" option and return path to downloaded file.
     """
     cache = tempfile.mkdtemp("download-cache")
     download = Download(cache=cache)
     download_url = self.options.get("download-url", DOWNLOAD_URL)
     download_path, is_temp = download(
         download_url.format(self.options.get("version", "latest")))
     return download_path
Example #6
0
    def download(self):
        d = Download(self.buildout['buildout'],
            hash_name=self.option_hash_name)
        cached_path, is_temp = d(self.option_url, md5sum=self.option_md5sum)

        if self.option_sha1sum and \
            self.option_sha1sum != get_checksum(cached_path):
            raise ChecksumError('SHA1 checksum mismatch for cached download '
                'from %r at %r' % (self.option_url, cached_path))

        return cached_path, is_temp
Example #7
0
    def download_and_extract(self, url, md5sum, dest, extract_filter='*', strip_dirs=1):
        path, is_temp = Download(self.buildout['buildout'])(url, md5sum)
        files = []

        def progress_filter(src, dst):
            if fnmatch(src, extract_filter):
                stripped = os.path.normpath(src).split(os.sep)[strip_dirs:]
                if stripped:
                    files.append(os.path.join(dest, os.path.join(
                        *stripped)))
                    return files[-1]

        archive_util.unpack_archive(path, dest, progress_filter)
        return files
Example #8
0
    def install(self):
        log = logging.getLogger(self.name)

        destination = self.options.get('destination')
        download = Download(self.buildout['buildout'],
                            hash_name=self.options['hash-name'].strip()
                            in TRUE_VALUES)
        path, is_temp = download(self.options['url'],
                                 md5sum=self.options.get('md5sum'))

        parts = []

        try:
            # Create destination directory
            if not os.path.isdir(destination):
                os.makedirs(destination)
                parts.append(destination)

            download_only = self.options['download-only'].strip().lower(
            ) in TRUE_VALUES
            if download_only:
                if self.options['filename']:
                    # Use an explicit filename from the section configuration
                    filename = self.options['filename']
                else:
                    # Use the original filename of the downloaded file regardless
                    # whether download filename hashing is enabled.
                    # See http://github.com/hexagonit/hexagonit.recipe.download/issues#issue/2
                    filename = os.path.basename(
                        urlparse.urlparse(self.options['url'])[2])

                # Copy the file to destination without extraction
                target_path = os.path.join(destination, filename)
                shutil.copy(path, target_path)
                if self.options.get('mode'):
                    os.chmod(target_path, int(self.options['mode'], 8))
                if not destination in parts:
                    parts.append(target_path)
            else:
                # Extract the package
                extract_dir = tempfile.mkdtemp("buildout-" + self.name)
                self.excluded_count = 0
                try:
                    try:
                        setuptools.archive_util.unpack_archive(
                            path,
                            extract_dir,
                            progress_filter=self.progress_filter)
                    except setuptools.archive_util.UnrecognizedFormat:
                        log.error(
                            'Unable to extract the package %s. Unknown format.',
                            path)
                        raise zc.buildout.UserError('Package extraction error')
                    if self.excluded_count > 0:
                        log.info(
                            "Excluding %s file(s) matching the exclusion pattern."
                            % self.excluded_count)
                    base = self.calculate_base(extract_dir)

                    if not os.path.isdir(destination):
                        os.makedirs(destination)
                        parts.append(destination)

                    log.info('Extracting package to %s' % destination)

                    ignore_existing = self.options['ignore-existing'].strip(
                    ).lower() in TRUE_VALUES
                    for filename in os.listdir(base):
                        dest = os.path.join(destination, filename)
                        if os.path.exists(dest):
                            if ignore_existing:
                                log.info('Ignoring existing target: %s' % dest)
                            else:
                                log.error(
                                    'Target %s already exists. Either remove it or set '
                                    '``ignore-existing = true`` in your buildout.cfg to ignore existing '
                                    'files and directories.', dest)
                                raise zc.buildout.UserError(
                                    'File or directory already exists.')
                        else:
                            # Only add the file/directory to the list of installed
                            # parts if it does not already exist. This way it does
                            # not get accidentally removed when uninstalling.
                            parts.append(dest)

                        shutil.move(os.path.join(base, filename), dest)
                finally:
                    shutil.rmtree(extract_dir)

        finally:
            if is_temp:
                os.unlink(path)

        return parts
Example #9
0
 def _download(self):
     from zc.buildout.download import Download
     download = Download(self.buildout.get('buildout'))
     self.download_path = download(self.url)[0]
Example #10
0
    def downloadExtract(self, targetFolder, srcRepo, srcList):
        """
        download all sources in srcList, extract them and create symlink in target
        folder.  all sources will be saved in folder parts/PART-NAME. Each source is saved
        in srcList as the following format: (id, version).
        """

        log = logging.getLogger(self.name)

        # the zc.buildout download facility will save everything in download
        # cache.  We need make sure it is exist.
        if not os.path.exists(self.buildout['buildout']['download-cache']):
            os.makedirs(self.buildout['buildout']['download-cache'])

        # get a zc.buildout download instance
        download = Download(self.buildout['buildout'])

        parts = []
        # add the base directory name to parts, so it will be removed during
        # uninstalling.
        partdir = os.path.join(self.buildout['buildout']['parts-directory'],
                               self.name)
        parts.append(partdir)

        # process the sources one by one.
        for srcId, srcVersion in srcList:
            # the download url.
            url = srcRepo + '/' + srcId + '.' + srcVersion + '.zip'
            path, is_temp = download(url)

            # destination is parts/PART-NAME/PLUGIN_ID-PLUGIN_VERSION
            dest = os.path.join(self.buildout['buildout']['parts-directory'], 
                                self.name, srcId + '-' + srcVersion)
            if not os.path.isdir(dest):
                os.makedirs(dest)
                parts.append(dest)

            # Extract the package
            extract_dir = tempfile.mkdtemp("buildout-" + self.name)
            try:
                setuptools.archive_util.unpack_archive(path, extract_dir)
            except setuptools.archive_util.UnrecognizedFormat:
                log.error('Unable to extract the package %s. Unknown format.', path)
                raise zc.buildout.UserError('Package extraction error')

            top_level_contents = os.listdir(extract_dir)
            if len(top_level_contents) != 1:
                log.error('Unable to strip top level directory because there are more '
                          'than one element in the root of the package.')
                raise zc.buildout.UserError('Invalid package contents')
            base = os.path.join(extract_dir, top_level_contents[0])

            log.info('Extracting package to %s' % dest)

            ignore_existing = self.options['ignore-existing'].strip().lower() in TRUE_VALUES
            for filename in os.listdir(base):
                filenameDest = os.path.join(dest, filename)
                if os.path.exists(filenameDest):
                    if ignore_existing:
                        log.info('Ignoring existing target: %s' % filenameDest)
                    else:
                        log.error('Target %s already exists. Either remove it or set '
                                  '``ignore-existing = true`` in your buildout.cfg to ignore existing '
                                  'files and directories.', filenameDest)
                        raise zc.buildout.UserError('File or directory already exists.')
                else:
                    # Only add the file/directory to the list of installed
                    # parts if it does not already exist. This way it does
                    # not get accidentally removed when uninstalling.
                    parts.append(filenameDest)

                shutil.move(os.path.join(base, filename), filenameDest)

            # create the symlink or copy for this srouce
            targetPath = os.path.join(targetFolder, srcId)
            # add the dest folder to parts, so it will be removed during
            # uninstalling.
            parts.append(targetPath)
            if self.options['action'].strip().lower() == 'copy':
                log.info('Rename to %s' % targetPath)
                if os.path.islink(targetPath):
                    os.unlink(targetPath)
                elif os.path.exists(targetPath):
                    shutil.rmtree(targetPath)
                shutil.move(dest, targetPath)
            else:
                log.info('Create symlink to %s' % targetPath)
                if os.path.lexists(targetPath):
                    os.unlink(targetPath)
                os.symlink(dest, targetPath)
                # add the dest folder to parts, so it will be removed during
                # uninstalling.
                parts.append(dest)

            shutil.rmtree(extract_dir)

        return parts
 def __init__(self, buildout, name, options):
     super(PackagingRecipe, self).__init__()
     self.buildout = buildout
     self.options = options
     self.downloader = Download(buildout)