示例#1
0
def extract_package(pkg_file, pkg_work_path):
    """
    Extract files to pkg_work_path from compressed files that are in compressed_path
    """
    r = False

    if os.path.isfile(pkg_file):
        if files_extractor.is_compressed_file(pkg_file):
            if os.path.exists(pkg_work_path):
                delete_file_or_folder(pkg_work_path)

            os.makedirs(pkg_work_path)
            # delete content of destination path
            # create tempdir
            temp_dir = tempfile.mkdtemp().replace('\\', '/')

            # extract in tempdir
            if files_extractor.extract_file(pkg_file, temp_dir):
                # eliminate folders
                for item in os.listdir(temp_dir):
                    _file = temp_dir + '/' + item
                    if os.path.isfile(_file):
                        shutil.copyfile(_file, pkg_work_path + '/' + item)
                        delete_file_or_folder(_file)
                    elif os.path.isdir(_file):
                        for f in os.listdir(_file):
                            if os.path.isfile(_file + '/' + f):
                                shutil.copyfile(_file + '/' + f, pkg_work_path + '/' + f)
                                delete_file_or_folder(_file + '/' + f)
                        shutil.rmtree(_file)
                shutil.rmtree(temp_dir)
                r = True
    return r
示例#2
0
def unzip(compressed_filename, destination_path):
    """
    Extract files to destination_path from compressed files that are in compressed_path
    """
    r = False

    if os.path.isfile(compressed_filename):
        if files_extractor.is_compressed_file(compressed_filename):
            if not os.path.isdir(destination_path):
                os.makedirs(destination_path)
            # delete content of destination path
            # create tempdir
            # extract in tempdir
            r = files_extractor.extract_file(compressed_filename, destination_path)
    return r
    def extract_files(self, compressed_file, destination_path, temp_dir=None):
        """
        Extract files to destination_path from compressed files that are in compressed_path
        """
        r = False

        if not os.path.exists(destination_path):
            os.makedirs(destination_path)

        self.report.write('package file: ' + compressed_file, True, False, True)
        if os.path.isfile(compressed_file):
            if is_compressed_file(compressed_file):
                self.report.write('Extract ' + compressed_file + ' to ' + destination_path, True, False, True)
                if self.__extract__(compressed_file, destination_path, temp_dir):
                    r = True
        if not r:
            self.report.write(compressed_file + ' is not a valid file. It must be a compressed file.', True, True, True)

        return r