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


Python TarFile.extractall方法代码示例

本文整理汇总了Python中tarfile.TarFile.extractall方法的典型用法代码示例。如果您正苦于以下问题:Python TarFile.extractall方法的具体用法?Python TarFile.extractall怎么用?Python TarFile.extractall使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tarfile.TarFile的用法示例。


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

示例1: install_repo

# 需要导入模块: from tarfile import TarFile [as 别名]
# 或者: from tarfile.TarFile import extractall [as 别名]
    def install_repo(self, repo):
        if repo in KNOWN_PUBLIC_REPOS:
            repo = KNOWN_PUBLIC_REPOS[repo]['path']  # replace it by the url
        git_path = which('git')

        if not git_path:
            return ('git command not found: You need to have git installed on '
                    'your system to be able to install git based plugins.', )

        # TODO: Update download path of plugin.
        if repo.endswith('tar.gz'):
            tar = TarFile(fileobj=urlopen(repo))
            tar.extractall(path=self.plugin_dir)
            s = repo.split(':')[-1].split('/')[-2:]
            human_name = '/'.join(s).rstrip('.tar.gz')
        else:
            human_name = human_name_for_git_url(repo)
            p = subprocess.Popen([git_path, 'clone', repo, human_name], cwd=self.plugin_dir, stdout=subprocess.PIPE,
                                 stderr=subprocess.PIPE)
            feedback = p.stdout.read().decode('utf-8')
            error_feedback = p.stderr.read().decode('utf-8')
            if p.wait():
                return "Could not load this plugin: \n\n%s\n\n---\n\n%s" % (feedback, error_feedback),
        self.add_plugin_repo(human_name, repo)
        return self.update_dynamic_plugins()
开发者ID:s905060,项目名称:errbot,代码行数:27,代码来源:plugin_manager.py

示例2: install

# 需要导入模块: from tarfile import TarFile [as 别名]
# 或者: from tarfile.TarFile import extractall [as 别名]
    def install(self, mess, args):
        """ install a plugin repository from the given source or a known public repo (see !repos to find those).
        for example from a known repo : !install err-codebot
        for example a git url : [email protected]:gbin/plugin.git
        or an url towards a tar.gz archive : http://www.gootz.net/plugin-latest.tar.gz
        """
        if not args.strip():
            return "You should have an urls/git repo argument"
        if args in KNOWN_PUBLIC_REPOS:
            args = KNOWN_PUBLIC_REPOS[args][0] # replace it by the url
        git_path = which('git')

        if not git_path:
            return 'git command not found: You need to have git installed on your system to by able to install git based plugins.'

        if args.endswith('tar.gz'):
            tar = TarFile(fileobj=urlopen(args))
            tar.extractall(path= PLUGIN_DIR)
            human_name = args.split('/')[-1][:-7]
        else:
            human_name = human_name_for_git_url(args)
            p = subprocess.Popen([git_path, 'clone', args, human_name], cwd = PLUGIN_DIR, stdout = subprocess.PIPE, stderr = subprocess.PIPE)
            feedback = p.stdout.read()
            error_feedback = p.stderr.read()
            if p.wait():
               return "Could not load this plugin : \n%s\n---\n%s" % (feedback, error_feedback)
        self.add_plugin_repo(human_name, args)
        errors = self.update_dynamic_plugins()
        if errors:
            self.send(mess.getFrom(), 'Some plugins are generating errors:\n' + '\n'.join(errors) , message_type=mess.getType())
        else:
            self.send(mess.getFrom(), "A new plugin repository named %s has been installed correctly from %s. Refreshing the plugins commands..." % (human_name, args), message_type=mess.getType())
        self.activate_non_started_plugins()
        return "Plugin reload done."
开发者ID:glenbot,项目名称:err,代码行数:36,代码来源:errBot.py

示例3: download

# 需要导入模块: from tarfile import TarFile [as 别名]
# 或者: from tarfile.TarFile import extractall [as 别名]
    def download(self, src, dest, extract_here=False):
        client = connect()

        with SpooledTemporaryFile() as file:
            file.write(client.copy(self.container_id, src).read())
            file.seek(0)
            tfile = TarFile(fileobj=file)
            if extract_here:
                base = len(os.path.basename(src)) + 1
                for member in tfile.getmembers():
                    member.name = member.name[base:]
            tfile.extractall(path=dest)
开发者ID:pombredanne,项目名称:meuh-python,代码行数:14,代码来源:bot.py

示例4: writer

# 需要导入模块: from tarfile import TarFile [as 别名]
# 或者: from tarfile.TarFile import extractall [as 别名]
 def writer(self):
     """Expect written bytes to be a tarball."""
     result = BytesIO()
     yield result
     result.seek(0, 0)
     try:
         tarball = TarFile(fileobj=result, mode="r")
         if self.path.exists():
             self.path.remove()
         self.path.createDirectory()
         tarball.extractall(self.path.path)
     except:
         # This should really be dealt with, e.g. logged:
         # https://github.com/ClusterHQ/flocker/issues/122
         pass
开发者ID:cultofmetatron,项目名称:flocker,代码行数:17,代码来源:memory.py

示例5: install_repo

# 需要导入模块: from tarfile import TarFile [as 别名]
# 或者: from tarfile.TarFile import extractall [as 别名]
    def install_repo(self, repo):
        """
        Install the repository from repo

        :param repo:
            The url, git url or path on disk of a repository. It can point to either a git repo or
             a .tar.gz of a plugin
        :returns:
            The path on disk where the repo has been installed on.
        :raises: :class:`~RepoException` if an error occured.
        """
        self.check_for_index_update()

        # try to find if we have something with that name in our index
        if repo in self[REPO_INDEX]:
            human_name = repo
            repo_url = next(iter(self[REPO_INDEX][repo].values()))['repo']
        else:
            # This is a repo url, make up a plugin definition for it
            # TODO read the definition if possible.
            human_name = human_name_for_git_url(repo)
            repo_url = repo

        git_path = which('git')
        if not git_path:
            raise RepoException('git command not found: You need to have git installed on '
                                'your system to be able to install git based plugins.', )

        # TODO: Update download path of plugin.
        if repo_url.endswith('tar.gz'):
            tar = TarFile(fileobj=urllib.urlopen(repo_url))
            tar.extractall(path=self.plugin_dir)
            s = repo_url.split(':')[-1].split('/')[-2:]
            human_name = human_name or '/'.join(s).rstrip('.tar.gz')
        else:
            human_name = human_name or human_name_for_git_url(repo_url)
            p = subprocess.Popen([git_path, 'clone', repo_url, human_name], cwd=self.plugin_dir, stdout=subprocess.PIPE,
                                 stderr=subprocess.PIPE)
            feedback = p.stdout.read().decode('utf-8')
            error_feedback = p.stderr.read().decode('utf-8')
            if p.wait():
                raise RepoException("Could not load this plugin: \n\n%s\n\n---\n\n%s" % (feedback, error_feedback))

        self.add_plugin_repo(human_name, repo_url)
        return os.path.join(self.plugin_dir, human_name)
开发者ID:Djiit,项目名称:errbot,代码行数:47,代码来源:repo_manager.py

示例6: __handle_file

# 需要导入模块: from tarfile import TarFile [as 别名]
# 或者: from tarfile.TarFile import extractall [as 别名]
 def __handle_file(self, plugin_file):
     # Uncompress the file.
     temp_dir = tempfile.gettempdir()
     if is_zipfile(plugin_file):
         compress_fd = zipfile.ZipFile(plugin_file, allowZip64=True)
         compress_fd.extractall(path=temp_dir)
     elif is_bz2file(plugin_file):
         #first check if we can handle as tar.bz2 (big chances)
         try:
             compress_fd = TarFile(name=plugin_file, mode="r:bz2")
             compress_fd.extractall(path=temp_dir)
         except CompressionError:
             print "Upz!, fail in compressed file handling, Retrying"
             try:
                 compress_fd = bz2.BZ2File(plugin_file)
                 tmp_fd = tempfile.TemporaryFile(suffix=".tar", prefix="ncmprs")
                 tmp_fd.file.write(compress_fd.read())
                 tmp_fd.file.flush()
                 tar_fd = TarFile.taropen(name=None, fileobj=tmp_fd)
                 tar_fd.extractall(path=temp_dir)
                 tar_fd.close()
                 tmp_fd.close()
             except:
                 print "Upz!, fail in compressed file handling, Again! :("
                 return None
     elif is_gzipfile(plugin_file):
         #first check if we can handle as tar.gz (big chances)
         try:
             compress_fd = TarFile(name=plugin_file, mode="r:gz")
             compress_fd.extractall(path=temp_dir)
         except CompressionError:
             print "Upz!, fail in compressed file handling, Retrying"
             try:
                 compress_fd = gzip.GzipFile(plugin_file)
                 tmp_fd = tempfile.TemporaryFile(suffix=".tar", prefix="ncmprs")
                 tmp_fd.file.write(compress_fd.read())
                 tmp_fd.file.flush()
                 tar_fd = TarFile.taropen(name=None, fileobj=tmp_fd)
                 tar_fd.extractall(path=temp_dir)
                 tar_fd.close()
                 tmp_fd.close()
             except:
                 print "Upz!, fail in compressed file handling, Again! :("
                 return None
     return self.__handle_dir(temp_dir)
开发者ID:TheProjecter,项目名称:pyideal.ideal,代码行数:47,代码来源:plugin_manager.py

示例7: update

# 需要导入模块: from tarfile import TarFile [as 别名]
# 或者: from tarfile.TarFile import extractall [as 别名]
 def update(self, name, version, target):
   shutil.rmtree(target)
   os.mkdir(target)
   try:
     updateServer=rpyc.connect(updateServerName,18862)
     validNames = config.readConfig("login.cfg")
     password = validNames['admin']['password']
     tar = updateServer.root.get(password, name, version)
     
     s = StringIO(decompress(tar))
     f = TarFile(mode='r', fileobj=s)
     
     f.extractall(target)
     print "updated",name
     return True
   except:
     traceback.print_exc()
     print "Failed to connet to the update server :("
     return False
开发者ID:siggame,项目名称:MegaMinerAI-6,代码行数:21,代码来源:tentacle.py

示例8: optional_extract

# 需要导入模块: from tarfile import TarFile [as 别名]
# 或者: from tarfile.TarFile import extractall [as 别名]
    def optional_extract(self, output, tarname):
        """Extracts test repository data if needed

        Checks whether directory exists or is older than archive.
        """

        tarname = get_test_file(tarname)

        if (not os.path.exists(output) or
                os.path.getmtime(output) < os.path.getmtime(tarname)):

            # Remove directory if outdated
            if os.path.exists(output):
                shutil.rmtree(output)

            # Extract new content
            tar = TarFile(tarname)
            tar.extractall(settings.DATA_DIR)
            tar.close()

            # Update directory timestamp
            os.utime(output, None)
开发者ID:roidelapluie,项目名称:weblate,代码行数:24,代码来源:utils.py

示例9: load_mailset

# 需要导入模块: from tarfile import TarFile [as 别名]
# 或者: from tarfile.TarFile import extractall [as 别名]
def load_mailset(mailset):
    import os
    from tarfile import TarFile
    from gzip import GzipFile
    mbox_root = os.path.join(os.environ['HOME'], 'mailsets')
    if not os.path.isdir(os.path.join(mbox_root)):
        os.mkdir(mbox_root)

    if len(os.listdir(mbox_root)) == 0:
        response = requests.get(MEDIUM_TAGGED_URL, verify=False)
        mbox_archive_path = os.path.join(mbox_root, 'py-mediumtagged.tar.gz')
        mbox_archive = open(mbox_archive_path, 'w')
        mbox_archive.write(response.content)
        mbox_archive.close()
        gzippedfile = GzipFile(filename=mbox_archive_path)
        tarfile = TarFile(fileobj=gzippedfile)
        tarfile.extractall(path=mbox_root)

    mail_service.reset()
    mail_service.load_mailset()

    return respond_json(None)
开发者ID:Nangal,项目名称:pixelated-user-agent,代码行数:24,代码来源:pixelated_user_agent.py

示例10: run

# 需要导入模块: from tarfile import TarFile [as 别名]
# 或者: from tarfile.TarFile import extractall [as 别名]
    def run(self):
        """
        Interesting magic to get a source dist and running trial on it.

        NOTE: there is magic going on here! If you know a better way feel
              free to update it.
        """
        # Clean out dist/
        if os.path.exists("dist"):
            for root, dirs, files in os.walk("dist", topdown=False):
                for name in files:
                    os.remove(os.path.join(root, name))
                for name in dirs:
                    os.rmdir(os.path.join(root, name))
        # Import setup making it as if we ran setup.py with the sdist arg
        sys.argv.append("sdist")
        import setup  # @Reimport @UnresolvedImport @UnusedImport

        try:
            # attempt to extract the sdist data
            from gzip import GzipFile
            from tarfile import TarFile

            # We open up the gzip as well as using the first item as the sdist
            gz = GzipFile(os.path.join("dist", os.listdir("dist")[0]))
            tf = TarFile(fileobj=gz)
            # Make the output dir and generate the extract path
            os.mkdir(os.path.join("dist", "sdist_test"))
            ex_path = os.path.join("dist", "sdist_test", tf.getmembers()[0].name, "buildbot", "test")
            # Extract the data and run tests
            print "Extracting to %s" % ex_path
            tf.extractall(os.path.join("dist", "sdist_test"))
            print "Executing tests ..."
            self._run(os.path.normpath(os.path.abspath(ex_path)))
        except IndexError, ie:
            # We get called twice and the IndexError is OK
            pass
开发者ID:jgraff,项目名称:buildbot,代码行数:39,代码来源:setup.py

示例11: prepare_tarball

# 需要导入模块: from tarfile import TarFile [as 别名]
# 或者: from tarfile.TarFile import extractall [as 别名]
def prepare_tarball(url, app):
    """ Prepare a tarball with app.json from the source URL.
    """
    got = get(url, allow_redirects=True)
    raw = GzipFile(fileobj=StringIO(got.content))
    tar = TarFile(fileobj=raw)

    try:
        dirpath = mkdtemp(prefix="display-screen-")
        rootdir = join(dirpath, commonprefix(tar.getnames()))
        tar.extractall(dirpath)

        if not isdir(rootdir):
            raise Exception('"{0}" is not a directory'.format(rootdir))

        with open(join(rootdir, "app.json"), "w") as out:
            json.dump(app, out)

        tarpath = make_archive(dirpath, "gztar", rootdir, ".")

    finally:
        rmtree(dirpath)

    return tarpath
开发者ID:code-for-england,项目名称:city-analytics-dashboard-setup,代码行数:26,代码来源:app.py

示例12: untar

# 需要导入模块: from tarfile import TarFile [as 别名]
# 或者: from tarfile.TarFile import extractall [as 别名]
def untar(archive, path):
	from tarfile import TarFile
	t = TarFile(archive, "r")
	t.extractall(path)
开发者ID:Knewton,项目名称:Zoidberg,代码行数:6,代码来源:utilities.py


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