예제 #1
0
def extract_orig_tarball(tarball_filename,
                         component,
                         target,
                         strip_components=None):
    """Extract an orig tarball.

    :param tarball: Path to the tarball
    :param component: Component name (or None for top-level)
    :param target: Target path
    """
    from tarfile import TarFile
    tar_args = ["tar"]
    if tarball_filename.endswith(".tar.bz2"):
        tar_args.append('xjf')
        tf = TarFile.bz2open(tarball_filename)
    elif (tarball_filename.endswith(".tar.lzma")
          or tarball_filename.endswith(".tar.xz")):
        tar_args.append('xJf')
        tf = TarFile.xzopen(tarball_filename)
    elif tarball_filename.endswith(".tar"):
        tar_args.append('xf')
        tf = TarFile.open(tarball_filename)
    elif (tarball_filename.endswith(".tar.gz")
          or tarball_filename.endswith(".tgz")):
        tf = TarFile.gzopen(tarball_filename)
        tar_args.append('xzf')
    else:
        note('Unable to figure out type of %s, '
             'assuming .tar.gz', tarball_filename)
        tf = TarFile.gzopen(tarball_filename)
        tar_args.append('xzf')

    try:
        if strip_components is None:
            if needs_strip_components(tf):
                strip_components = 1
            else:
                strip_components = 0
    finally:
        tf.close()
    if component is not None:
        target_path = os.path.join(target, component)
        os.mkdir(target_path)
    else:
        target_path = target
    tar_args.extend([tarball_filename, "-C", target_path])
    if strip_components is not None:
        tar_args.extend(["--strip-components", str(strip_components)])
    proc = subprocess.Popen(tar_args,
                            preexec_fn=subprocess_setup,
                            stderr=subprocess.PIPE)
    (stdout, stderr) = proc.communicate()
    if proc.returncode != 0:
        raise TarFailed("extract", tarball_filename, error=stderr)
예제 #2
0
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

        # Find all files untracked by the VC and not ignored.
        untracked = []
        if path.isdir(getcwd() + path.sep + ".git"):
            cmd = "git ls-files --others --exclude-standard"
            pipe = Popen(cmd, shell=True, stdout=PIPE, close_fds=False)
            for file_name in pipe.stdout.readlines():
                untracked.append(file_name.strip())

        # Walk through the directories.
        for root, dirs, files in walk(getcwd()):
            # Skip the version control directories.
            skip = False
            for vc in VERSION_CONTROL_DIRS:
                if search(vc, root):
                    skip = True
            if skip:
                continue

            # Add the files in the current directory to the archive.
            for i in range(len(files)):
                # Skip all blacklisted files.
                skip = False
                for file_name in BLACKLISTED_FILES:
                    if search(file_name, files[i]):
                        skip = True

                # Create the file name (without the base directory).
                name = path.join(root, files[i])
                name = name[len(base):]

                # Skip all untracked files.
                if name in untracked:
                    skip = True

                # Nothing to do.
                if skip:
                    continue

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

                # 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")
예제 #3
0
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!"
예제 #4
0
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")
예제 #5
0
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")