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


Python TarFile.bz2open方法代码示例

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


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

示例1: range

# 需要导入模块: from tarfile import TarFile [as 别名]
# 或者: from tarfile.TarFile import bz2open [as 别名]
from tarfile import TarFile
from zipfile import ZipFile

path = 'g:/geek/'

for i in range(0, 300)[::-1]:
    extract_path = path + str(i)
    #put_path =path +str(i + 1)
    file = open(extract_path, 'rb')
    strr = file.read()
    try:
        if "\x50\x4B\x03\x04" in strr:
            tar = ZipFile(extract_path)
            tar.extract(str(i - 1), path)
            tar.close()
            file.close()
        elif "\x1F\x8B\x08" in strr:
            tar = TarFile.gzopen(extract_path)
            tar.extract(str(i - 1), path)
            tar.close()
            file.close()
        elif "\x42\x5A\x68\x39" in strr:
            tar = TarFile.bz2open(extract_path)
            tar.extract(str(i - 1), path)
            tar.close()
            file.close()
        file.close()
    except:
        print "something error!"
开发者ID:zwhubuntu,项目名称:CTF-chal-code,代码行数:31,代码来源:geek_program_250_new.py

示例2: package

# 需要导入模块: from tarfile import TarFile [as 别名]
# 或者: from tarfile.TarFile import bz2open [as 别名]
def package(target, source, env):
    """Builder action for packaging the distribution archives."""

    # Print out.
    print('')
    print("#######################")
    print("# Packaging the files #")
    print("#######################")

    # List of distribution files.
    type_list = [env['DIST_TYPE']]
    if type_list[0] == 'ALL':
        type_list = ['zip', 'tar']

    # Loop over the distribution files.
    for dist_type in type_list:
        # The file name.
        if dist_type == 'zip':
            file = env['DIST_FILE'] + '.zip'
        elif dist_type == 'tar':
            file = env['DIST_FILE'] + '.tar.bz2'
        elif dist_type == 'dmg':
            file = env['DIST_FILE'] + '.dmg'

        # Print out.
        print("\n\nCreating the package distribution " + repr(file) + ".\n")

        # Create the special Mac OS X DMG file and then stop execution.
        if dist_type == 'dmg':
            # Create the Mac OS X universal application.
            print("\n# Creating the Mac OS X universal application.\n\n")
            cmd = '%s setup.py py2app' % sys.executable
            print("%s\n" % cmd)
            pipe = Popen(cmd, shell=True, stdin=PIPE, close_fds=False)
            waitpid(pipe.pid, 0)

            # Create the dmg image.
            print("\n\n# Creating the DMG image.\n\n")
            cmd = 'hdiutil create -ov -fs HFS+ -volname "relax" -srcfolder dist/relax.app ../%s' % file
            print("%s\n" % cmd)
            pipe = Popen(cmd, shell=True, stdin=PIPE, close_fds=False)
            waitpid(pipe.pid, 0)

            # Stop executing.
            return

        # Open the Zip distribution file.
        if dist_type == 'zip':
            archive = ZipFile(path.pardir + path.sep + file, 'w', compression=8)

        # Open the Tar distribution file.
        elif dist_type == 'tar':
            if search('.bz2$', file):
                archive = TarFile.bz2open(path.pardir + path.sep + file, 'w')
            elif search('.gz$', file):
                archive = TarFile.gzopen(path.pardir + path.sep + file, 'w')
            else:
                archive = TarFile.open(path.pardir + path.sep + file, 'w')

        # Base directory.
        base = getcwd() + sep

        # Walk through the directories.
        for root, dirs, files in walk(getcwd()):
            # Skip the subversion directories.
            if search("\.svn", root):
                continue

            # Add the files in the current directory to the archive.
            for i in range(len(files)):
                # Skip any '.sconsign' files, hidden files, byte-compiled '*.pyc' files, or binary objects '.o', '.os', 'obj', 'lib', and 'exp'.
                if search("\.sconsign", files[i]) or search("^\.", files[i]) or search("\.pyc$", files[i]) or search("\.o$", files[i]) or search("\.os$", files[i]) or search("\.obj$", files[i]) or search("\.lib$", files[i]) or search("\.exp$", files[i]):
                    continue

                # Create the file name (without the base directory).
                name = path.join(root, files[i])
                name = name[len(base):]
                print('relax-' + version + path.sep + name)

                # The archive file name.
                arcname = 'relax-' + version + path.sep + name

                # Zip archives.
                if dist_type == 'zip':
                    archive.write(filename=name, arcname=arcname)

                # Tar archives.
                if dist_type == 'tar':
                    archive.add(name=name, arcname=arcname)

        # Close the archive.
        archive.close()

    # Final printout.
    print("\n\n\n")
开发者ID:belisario21,项目名称:relax_trunk,代码行数:97,代码来源:distrib.py


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