当前位置: 首页>>代码示例>>Python>>正文


Python archive_util.unpack_archive函数代码示例

本文整理汇总了Python中setuptools.archive_util.unpack_archive函数的典型用法代码示例。如果您正苦于以下问题:Python unpack_archive函数的具体用法?Python unpack_archive怎么用?Python unpack_archive使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了unpack_archive函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: download_src

    def download_src(self, url, source=None, archive=True):
        """ Download source and return path to it.

        :param url: url to source distribution
        :type url: string

        :param source_dir: source directory after unpacking (optional)
        :type source_dir: string

        :param archive: is source archive file or not
        :type archive: boolean

        :return: path to source directory
        """

        tmp_dir = tempfile.gettempdir()
        source_file = os.path.join(tmp_dir, url.split('/')[-1])
        urllib.request.urlretrieve(url, source_file)

        if source is None:
            source = source_file

        if archive:
            unpack_archive(source_file, tmp_dir)
            source = os.path.splitext(source)[0]
            if 'tar' in source:
                source = os.path.splitext(source)[0]

        return os.path.join(tmp_dir, source)
开发者ID:tazjel,项目名称:envin,代码行数:29,代码来源:installer.py

示例2: local_distribution

 def local_distribution(self):
     if self._local_dist is None:
         ensure_directory(os.path.join(self.tmpdir, "dummy"))
         info("Fetching %s from %s..." % (str(self.distribution),
             self.location))
         dist = self.repository.environment.fetch_distribution(self.requirement,
             self.tmpdir, source=self.source, develop_ok=self.develop)
         location = dist.location
         distros = list(find_distributions(location))
         if distros:
             self._local_dist = distros[0]
         elif os.path.isfile(location) and os.path.splitext(location) != \
                 ".py":
             # try to unpack the file
             unpack_dir = os.path.join(self.tmpdir, "unpack")
             info("Unpacking to %s..." % unpack_dir)
             unpack_archive(location, unpack_dir)
             distros = list(find_distributions(unpack_dir))
             if distros:
                 self._local_dist = distros[0]
             else:
                 for path in glob(os.path.join(unpack_dir, "*")):
                     distros = list(find_distributions(path))
                     if distros:
                         self._local_dist = distros[0]
                         break
                 else:
                     self._local_dist = Distribution.from_filename(location)
     return self._local_dist
开发者ID:pombredanne,项目名称:ensetuptools,代码行数:29,代码来源:package.py

示例3: _get_new

 def _get_new(self, allow_redirects=True, chunk_size=512):
     """Retrieves the new archive and extracts it to self.updatedir."""
     self.log.info("Retrieving new version")
     newurl = self.url+self.newfiles
     # Get new files
     http_get = requests.get(newurl, stream=True,
                             allow_redirects=allow_redirects)
     http_get.raise_for_status()
     with open(self.newfiles, 'wb') as filehandle:
         for chunk in http_get.iter_content(chunk_size=chunk_size):
             if chunk:
                 filehandle.write(chunk)
     # Unpack archive and remove it after extraction
     try:
         self.log.info("Unpacking downloaded archive")
         unpack_archive(self.newfiles, self.updatedir)
     except UnrecognizedFormat:
         self.log.error("Retrieved version archive is invalid!\n"
                        "Please contact the software authors.\n"
                        "Please include the invalid archive "
                        "in a bug report.")
         os.rename(self.newfiles,self.newfiles+".dump")
     else:
         # Remove archive only if unpack operation succeeded
         self.log.info("Removing archive after extraction")
         os.remove(self.newfiles)
         # Signal that update is ready
         self.log.debug("Creating downloaded file marker")
         open(self.queue_replace,"w").close()
开发者ID:rlee287,项目名称:pyautoupdate,代码行数:29,代码来源:launcher.py

示例4: extract_gz

    def extract_gz(self, archive_path,
                   archivedir_write_path,
                   file_name=None,
                   open_archive_file=None,
                   archive=None):
        """Extract gz files.

        Extracts a given file name or all the files in the gz.
        """
        if file_name:
            open_archive_file = gzip.open(archive_path, 'r')
            file_obj = open_archive_file
            open_object = False
            self.write_fileobject(archivedir_write_path,
                                  file_name,
                                  file_obj=open_archive_file,
                                  open_object=False)
            if 'archive' in locals() and archive:
                archive.close()
            return [file_name]
        files_before = set(walk_relative_path(archivedir_write_path))
        archive_util.unpack_archive(archive_path, archivedir_write_path)
        files_after = set(walk_relative_path(archivedir_write_path))
        unpacked_files = files_after - files_before
        return list(unpacked_files)
开发者ID:KristinaRiemer,项目名称:retriever,代码行数:25,代码来源:engine.py

示例5: get_filelist

 def get_filelist(self):
     '''
     Unpack the archive if it is an archive, and return a list of 
     file names that should be examined by OGR to determine if they are
     OGR supported file types.
     
     Cache the result to speed up subsequent calls.
     '''
     if not hasattr(self, '_files'):
         name, extension=os.path.splitext(self.filename)
         # only handle a few types, since some of the others might mess 
         # up some processing...like xlsx (which this will unpack.)
         logger.debug('Extension is %s', extension)
         if extension.lower() in ('.zip','.gz','.tgz'):
             try:
                 # Ensure that the files are output in the working dir, and 
                 # subdirectories are omitted (so it's a flat dir structure)
                 archive_util.unpack_archive(self.filename, self.working_dir,
                                             progress_filter=self._progress_filter)
                 logger.debug('Unpacked archive %s to %s', self.filename, 
                              self.working_dir)
                 files=[fn for fn in map(lambda dir: os.path.join(self.working_dir, 
                                                                  dir),
                                         os.listdir(self.working_dir)) 
                                         if not os.path.isdir(fn)]
                 self._files=files
             except archive_util.UnrecognizedFormat, e:
                 logger.debug('Specified file (%s) is not a recognized archive',
                              self.filename)
                 self._files=[self.filename,]
         else:
             self._files=[self.filename,]
开发者ID:bhargavasana,项目名称:nmtk,代码行数:32,代码来源:loaders.py

示例6: _extract_file_to_file_server

 def _extract_file_to_file_server(cls, file_server_root, archive_target_path):
     # extract application to file server
     tempdir = tempfile.mkdtemp("-blueprint-submit")
     try:
         try:
             archive_util.unpack_archive(archive_target_path, tempdir)
         except archive_util.UnrecognizedFormat:
             raise manager_exceptions.BadParametersError(
                 "Blueprint archive is of an unrecognized format. "
                 "Supported formats are: {0}".format(SUPPORTED_ARCHIVE_TYPES)
             )
         archive_file_list = os.listdir(tempdir)
         if len(archive_file_list) != 1 or not path.isdir(path.join(tempdir, archive_file_list[0])):
             raise manager_exceptions.BadParametersError("archive must contain exactly 1 directory")
         application_dir_base_name = archive_file_list[0]
         # generating temporary unique name for app dir, to allow multiple
         # uploads of apps with the same name (as it appears in the file
         # system, not the app name field inside the blueprint.
         # the latter is guaranteed to be unique).
         generated_app_dir_name = "{0}-{1}".format(application_dir_base_name, uuid.uuid4())
         temp_application_dir = path.join(tempdir, application_dir_base_name)
         temp_application_target_dir = path.join(tempdir, generated_app_dir_name)
         shutil.move(temp_application_dir, temp_application_target_dir)
         shutil.move(temp_application_target_dir, file_server_root)
         return generated_app_dir_name
     finally:
         shutil.rmtree(tempdir)
开发者ID:pkdevboxy,项目名称:cloudify-manager,代码行数:27,代码来源:resources.py

示例7: _unpack_eggs

def _unpack_eggs(egg_list):
    import os
    for pkg in egg_list:
        import pkg_resources
        eggs = pkg_resources.require(pkg)
        from setuptools.archive_util import unpack_archive
        for egg in eggs:
           if os.path.isdir(egg.location):
               sys.path.insert(0, egg.location)
               continue
           unpack_archive(egg.location, os.path.abspath(os.path.dirname(egg.location)))
开发者ID:wemomedia,项目名称:wevr-awsebcli,代码行数:11,代码来源:setup.py

示例8: copytree

 def copytree(self):
     # Copy the .egg-info tree to site-packages
     def skimmer(src,dst):
         # filter out source-control directories; note that 'src' is always
         # a '/'-separated path, regardless of platform.  'dst' is a
         # platform-specific path.
         for skip in '.svn/','CVS/':
             if src.startswith(skip) or '/'+skip in src:
                 return None
         self.outputs.append(dst)
         log.debug("Copying %s to %s", src, dst)
         return dst
     unpack_archive(self.source, self.target, skimmer)
开发者ID:0jpq0,项目名称:kbengine,代码行数:13,代码来源:install_egg_info.py

示例9: checkout_extension

def checkout_extension(name):
    log('Downloading extension %s to temporary folder', name)
    root = os.path.join(tdir, name)
    os.mkdir(root)
    checkout_path = PackageIndex().download(name, root)

    unpack_archive(checkout_path, root)
    path = None
    for fn in os.listdir(root):
        path = os.path.join(root, fn)
        if os.path.isdir(path):
            break
    log('Downloaded to %s', path)
    return path
开发者ID:0x78kiki,项目名称:flask,代码行数:14,代码来源:flaskext_tester.py

示例10: cache_package

def cache_package(spec, own_url):
    try:
        spec = Requirement.parse(spec)

    except ValueError:
        raise ArgumentError("Not a URL, existing file, or requirement spec: %r"
                                                                      % (spec,))

    try:
        # download and unpack source package
        path = tempfile.mkdtemp('.spynepi')
        logger.info("Downloading %r" % spec)
        dist = PackageIndex().fetch_distribution(spec, path, force_scan=True, source=True)
        archive_path = dist.location
        logger.info("Unpacking %r" % archive_path)
        unpack_archive(dist.location, path)

        # generate pypirc if possible
        if os.environ.has_key('HOME'):
            _generate_pypirc(own_url)
        else: # FIXME: ??? No idea. Hopefully setuptools knows better.
            pass # raise NotImplementedError("$HOME not defined, .pypirc not found.")

        # find setup.py in package. plagiarized from setuptools.
        setups = glob(os.path.join(path, '*', 'setup.py'))
        if not setups:
            raise ValidationError(
                "Couldn't find a setup script in %r editable distribution: %r" %
                                    (spec, os.path.join(path,'*', 'setup.py'))
            )

        if len(setups)>1:
            raise ValidationError(
                "Multiple setup scripts found in %r editable distribution: %r" %
                                    (spec, setups)
            )

        # self-register the package.
        lib_dir = os.path.dirname(setups[0])
        command = ["python", "setup.py", "register", "-r", REPO_NAME]
        logger.info('calling %r', command)
        subprocess.call(command, cwd=lib_dir, stdout=sys.stdout)

        # self-upload the package
        command = ["python", "-m", "spynepi.util.pypi.upload", archive_path]
        logger.info('calling %r', command)
        subprocess.call(command, cwd=lib_dir, stdin=sys.stdin, stdout=sys.stdout)

    finally:
        shutil.rmtree(path)
开发者ID:arskom,项目名称:spynepi,代码行数:50,代码来源:__init__.py

示例11: unpackEgg

def unpackEgg(modulo):
    eggs = pkg_resources.require(modulo)
    for egg in eggs:
        if os.path.isdir(egg.location):
            sys.path.insert(0, egg.location)
            continue
        unpack_archive(egg.location, ".")
    eggpacks = set()
    eggspth = open("./eggs.pth", "w")
    for egg in eggs:
        eggspth.write(os.path.basename(egg.location))
        eggspth.write("\n")
        eggpacks.update(egg.get_metadata_lines("top_level.txt"))
    eggspth.close()

    eggpacks.clear()
开发者ID:citizenTFA,项目名称:DDEXUI,代码行数:16,代码来源:unpackEgg.py

示例12: copytree

    def copytree(self):
        # Copy the .egg-info tree to site-packages
        def skimmer(src, dst):
            # filter out source-control directories; note that 'src' is always
            # a '/'-separated path, regardless of platform.  'dst' is a
            # platform-specific path.
            for skip in ".svn/", "CVS/":
                if src.startswith(skip) or "/" + skip in src:
                    return None
            if self.install_layout and self.install_layout in ["deb"] and src.startswith("SOURCES.txt"):
                log.info("Skipping SOURCES.txt")
                return None
            self.outputs.append(dst)
            log.debug("Copying %s to %s", src, dst)
            return dst

        unpack_archive(self.source, self.target, skimmer)
开发者ID:LewkowskiArkadiusz,项目名称:magisterka,代码行数:17,代码来源:install_egg_info.py

示例13: extract_blueprint_archive_to_mgr

def extract_blueprint_archive_to_mgr(archive_path, destination_root):
    """
    Extracting a package.

    :param destination_root: the root destination for the unzipped archive
    :param archive_path: the archive path
    :return: the full path for the extracted archive
    """
    # Importing this archives in the global scope causes import loop
    from manager_rest.resources import SUPPORTED_ARCHIVE_TYPES
    # extract application to file server
    tempdir = tempfile.mkdtemp('-blueprint-submit')
    try:
        try:
            archive_util.unpack_archive(archive_path, tempdir)
        except archive_util.UnrecognizedFormat:
            raise manager_exceptions.BadParametersError(
                    'Blueprint archive is of an unrecognized format. '
                    'Supported formats are: {0}'.format(
                            SUPPORTED_ARCHIVE_TYPES))
        archive_file_list = listdir(tempdir)
        if len(archive_file_list) != 1 or not path.isdir(
                path.join(tempdir, archive_file_list[0])):
            raise manager_exceptions.BadParametersError(
                    'archive must contain exactly 1 directory')
        application_dir_base_name = archive_file_list[0]
        # generating temporary unique name for app dir, to allow multiple
        # uploads of apps with the same name (as it appears in the file
        # system, not the app name field inside the blueprint.
        # the latter is guaranteed to be unique).
        generated_app_dir_name = '{0}-{1}'.format(
                application_dir_base_name, uuid.uuid4())
        temp_application_dir = path.join(tempdir,
                                         application_dir_base_name)
        temp_application_target_dir = path.join(tempdir,
                                                generated_app_dir_name)
        shutil.move(temp_application_dir, temp_application_target_dir)
        shutil.move(temp_application_target_dir, destination_root)
        return generated_app_dir_name
    finally:
        shutil.rmtree(tempdir)
开发者ID:GigaSpaces-ProfessionalServices,项目名称:cloudify-manager,代码行数:41,代码来源:utils.py

示例14: fixed_unpack_and_compile

def fixed_unpack_and_compile(self, egg_path, destination):
    from setuptools.archive_util import unpack_archive
    to_compile = []; to_chmod = []

    def pf(src,dst):
        if dst.endswith('.py') and not src.startswith('EGG-INFO/'):
            to_compile.append(dst)
            to_chmod.append(dst)
        elif dst.endswith('.dll') or dst.endswith('.so'):
            to_chmod.append(dst)
        self.unpack_progress(src,dst)
        return not self.dry_run and dst or None

    unpack_archive(egg_path, destination, pf)
    self.byte_compile(to_compile)
    if not self.dry_run:
        for f in to_chmod:
#           mode = ((os.stat(f)[stat.ST_MODE]) | 0555) & 07755
            mode = ((os.stat(f)[stat.ST_MODE]) | 0444) & 07755
            chmod(f, mode)

    to_compile = []; to_chmod = []
    return
开发者ID:danse-inelastic,项目名称:inelastic-svn,代码行数:23,代码来源:fix_setuptools_chmod.py

示例15: update_self

def update_self():
	if len(sys.argv) > 1 and sys.argv[1] == '--updated':
		del sys.argv[1]
		return

	from setuptools.package_index import PackageIndex
	from setuptools.archive_util import unpack_archive

	tmpdir = tempfile.mkdtemp(prefix=TEMP_DIR_PREFIX)
	print('Downloading %s' % DEFAULT_URL)
	download = PackageIndex().download(DEFAULT_URL, tmpdir)
	print('Downloaded.')
	unpack_archive(download, tmpdir)
	unpack_dir = os.path.join(tmpdir, PACK_FILE_ROOT_DIR)
	move_files(unpack_dir, os.curdir,
		shutil.ignore_patterns('.*', '*.sln', '*.pyproj', '*.sample'))
	shutil.rmtree(tmpdir)
	print('Self updated.')

	if len(sys.argv) == 1:
		# only update self.
		sys.exit(0)
	else:
		restart(with_virtualenv=False)
开发者ID:SunriseChen,项目名称:BuildLibrary,代码行数:24,代码来源:lib_install.py


注:本文中的setuptools.archive_util.unpack_archive函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。