Пример #1
0
# Extract files from archives.

from os import O_CREAT, O_WRONLY, fdopen, mkdir, open as osopen, utime
try:
    from os import O_BINARY
except ImportError:
    # Platforms that do not define O_BINARY do not need it either.
    O_BINARY = 0
from os.path import abspath, isdir, join as joinpath, sep, split as splitpath
from stat import S_IRWXU, S_IRWXG, S_IRWXO, S_IXUSR, S_IXGRP, S_IXOTH
import sys
import tarfile

from detectsys import detectOS

hostOS = detectOS()

# Note: Larger buffers might make extraction slower.
bufSize = 16384


def extract(archivePath, destDir, rename=None):
    '''Extract the given archive to the given directory.
	If a rename function is given, it is called with the output path relative
	to the destination directory; the value returned by the rename function is
	used as the actual relative destination file path.
	This function sets file ownership and permissions like is done in newly
	created files and ignores the ownership and permissions from the archive,
	since we are not restoring a backup.
	'''
    absDestDir = abspath(destDir) + sep
Пример #2
0
try:
	from os import symlink
except ImportError:
	def symlink(source, link_name):
		raise RuntimeError(
			'OS does not support symlink creation: %s -> %s'
			% (link_name, source)
			)
from os.path import abspath, isdir, join as joinpath, sep, split as splitpath
from stat import S_IRWXU, S_IRWXG, S_IRWXO, S_IXUSR, S_IXGRP, S_IXOTH
import sys
import tarfile

from detectsys import detectOS

hostOS = detectOS()

# Note: Larger buffers might make extraction slower.
bufSize = 16384

def extract(archivePath, destDir, rename = None):
	'''Extract the given archive to the given directory.
	If a rename function is given, it is called with the output path relative
	to the destination directory; the value returned by the rename function is
	used as the actual relative destination file path.
	This function sets file ownership and permissions like is done in newly
	created files and ignores the ownership and permissions from the archive,
	since we are not restoring a backup.
	'''
	absDestDir = abspath(destDir) + sep
	if not isdir(absDestDir):