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


Python TarFile.getnames方法代码示例

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


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

示例1: TarFileWrapper

# 需要导入模块: from tarfile import TarFile [as 别名]
# 或者: from tarfile.TarFile import getnames [as 别名]
class TarFileWrapper(ArchiveFileWrapper):
    def __init__(self, fh, *args, **kwargs):
        self.archive = TarFile(fileobj=fh)
        super(TarFileWrapper, self).__init__(*args, **kwargs)

    def extract_file(self, *args, **kwarg):
        return self.archive.extractfile(*args, **kwarg)

    def names(self):
        return self.archive.getnames()
开发者ID:fcurella,项目名称:cookiejar,代码行数:12,代码来源:extractor.py

示例2: _check_tar_file

# 需要导入模块: from tarfile import TarFile [as 别名]
# 或者: from tarfile.TarFile import getnames [as 别名]
 def _check_tar_file(self, content, rootdir, datafiles,
                     simpleNames=False, noTxt=False):
     with NamedTemporaryFile('w') as tempfile:
         tempfile.write(content)
         tempfile.flush()
         if getsize(tempfile.name) > 0:
             expect(is_tarfile(tempfile.name)).to_be_truthy()
             try:
                 tf = TarFile(tempfile.name, 'r')
                 self._check_names(datafiles, tf.getnames(), 
                                   rootdir, simpleNames, noTxt)
             finally:
                 tf.close()
         else:
             self._check_names(datafiles, [], 
                               rootdir, simpleNames, noTxt)
开发者ID:crawley,项目名称:mytardis,代码行数:18,代码来源:test_download.py

示例3: _check_tar_file

# 需要导入模块: from tarfile import TarFile [as 别名]
# 或者: from tarfile.TarFile import getnames [as 别名]
 def _check_tar_file(self, content, rootdir, datafiles,
                     simpleNames=False, noTxt=False):
     with NamedTemporaryFile('w') as tempfile:
         for c in content:
             tempfile.write(c)
         tempfile.flush()
         if getsize(tempfile.name) > 0:
             self.assertTrue(is_tarfile(tempfile.name))
             try:
                 tf = TarFile(tempfile.name, 'r')
                 self._check_names(datafiles, tf.getnames(),
                                   rootdir, simpleNames, noTxt)
             finally:
                 tf.close()
         else:
             self._check_names(datafiles, [],
                               rootdir, simpleNames, noTxt)
开发者ID:mytardis,项目名称:mytardis,代码行数:19,代码来源:test_download.py

示例4: prepare_tarball

# 需要导入模块: from tarfile import TarFile [as 别名]
# 或者: from tarfile.TarFile import getnames [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

示例5: TarFile

# 需要导入模块: from tarfile import TarFile [as 别名]
# 或者: from tarfile.TarFile import getnames [as 别名]
#!/usr/bin/python2.7

from tarfile import TarFile

from datetime import datetime

FILENAME = "projectcounts-2008.tar"
MAX_REQUESTS = 33056088 * 0.4

if __name__ == "__main__":
    tar = TarFile(FILENAME)
    inidate = datetime(year=2008, month=1, day=1)
    maxrequests = 0
    for filename in tar.getnames():
        pre, date, time = filename.split("-")
        year = int(date[0:4])
        month = int(date[4:6])
        day = int(date[6:8])
        hour = int(time[0:2])
        minute = int(time[2:4])
        second = int(time[4:6])
        date = datetime(year=year, month=month, day=day, hour=hour, minute=minute, second=second)
        td = date - inidate
        seconds = td.days * 24 * 60 * 60 + td.seconds

        f = tar.extractfile(filename)
        for line in f.readlines():
            if line.startswith("en -"):
                line = line.replace("\n", "").replace("\r", "")
                lineSplit = line.split(" ")
                requests = int(lineSplit[2])
开发者ID:goiri,项目名称:greendcsimulator,代码行数:33,代码来源:parser.py


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