Beispiel #1
0
    def extract(self, path, sel_files=None):
        count = 0.0
        for u, files in self.urls:
            if sel_files is not None:
                files = set(files) & sel_files

            count += len(files)

        i = 0
        for u, files in self.urls:
            if sel_files is not None:
                files = set(files) & sel_files

            for item in files:
                mypath = os.path.join(path, item)
                if os.path.exists(mypath) and is_archive(mypath):
                    progress.update(i / count, 'Extracting "%s"...' % item)

                    with tempfile.TemporaryDirectory() as tempdir:
                        # Extract to a temporary directory and then move the result
                        # to final destination to avoid "Do you want to overwrite?" questions.

                        extract_archive(mypath, tempdir)
                        if self.ignore_subpath:
                            for sub_path, dirs, files in os.walk(tempdir):
                                for name in files:
                                    shutil.move(
                                        os.path.join(sub_path, name),
                                        ipath(os.path.join(path, name)))
                        else:
                            movetree(tempdir, path, ifix=True)

                i += 1
Beispiel #2
0
    def extract(self, path, sel_files=None):
        count = 0.0
        for u, files in self.urls:
            if sel_files is not None:
                files = set(files) & sel_files

            count += len(files)
        
        i = 0
        for u, files in self.urls:
            if sel_files is not None:
                files = set(files) & sel_files
            
            for item in files:
                mypath = os.path.join(path, item)
                if os.path.exists(mypath) and is_archive(mypath):
                    progress.update(i / count, 'Extracting "%s"...' % item)
                    
                    with tempfile.TemporaryDirectory() as tempdir:
                        # Extract to a temporary directory and then move the result
                        # to final destination to avoid "Do you want to overwrite?" questions.
                        
                        extract_archive(mypath, tempdir)
                        if self.ignore_subpath:
                            for sub_path, dirs, files in os.walk(tempdir):
                                for name in files:
                                    shutil.move(os.path.join(sub_path, name), ipath(os.path.join(path, name)))
                        else:
                            movetree(tempdir, path, ifix=True)
                
                i += 1
Beispiel #3
0
    def _inspect_file(self, id_, archive, dest, path):
        csum = util.gen_hash(path)
        content = {}

        if archive:
            ar_content = os.path.join(dest, 'content')

            if util.extract_archive(path, ar_content):
                for cur_path, dirs, files in os.walk(ar_content):
                    subpath = cur_path[len(ar_content):].replace(
                        '\\', '/').lstrip('/')
                    if subpath != '':
                        subpath += '/'

                    for name in files:
                        fpath = os.path.join(cur_path, name)

                        # Don't generate checksums for symlinks.
                        if not os.path.islink(fpath):
                            content[subpath + name] = util.gen_hash(fpath)

                        if name == 'mod.ini':
                            self._inspect_mod_ini(os.path.join(cur_path, name),
                                                  id_[0])
            else:
                logging.error('Failed to extract "%s"!',
                              os.path.basename(path))
                return 'FAILED', None

        return csum, content