コード例 #1
0
ファイル: fso_parser.py プロジェクト: joshuasb/knossos
    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
コード例 #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
コード例 #3
0
ファイル: fso_parser.py プロジェクト: joshuasb/knossos
    def cleanup(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):
                    # Only remove the archives...
                    progress.update(i / count, 'Removing "%s"...' % item)
                    os.unlink(mypath)
                
                i += 1
コード例 #4
0
    def cleanup(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):
                    # Only remove the archives...
                    progress.update(i / count, 'Removing "%s"...' % item)
                    os.unlink(mypath)

                i += 1
コード例 #5
0
ファイル: repo.py プロジェクト: joshuasb/knossos
    def import_tree(self, mod_tree):
        mod_tree = self._flatten_tree(mod_tree)

        for path, mod in mod_tree.items():
            # First we need its ID.
            # For now, I'll simply use the path with a prefix.

            id_ = "FSOI#" + path
            if id_ in self.mods:
                # Let's update it but try to honour local modifications.
                submods = ["FSOI#" + ".".join(smod.path) for smod in mod.submods]
                dependencies = ["FSOI#" + path for path in mod.dependencies]
                delete = [pjoin(mod.folder, path) for path in mod.delete]

                entry = self.mods[id_]
                for smod in submods:
                    if smod not in entry["submods"]:
                        entry["submods"].append(smod)

                e_deps = entry["packages"][0]["dependencies"]
                for path in dependencies:
                    if path not in e_deps:
                        e_deps.append(path)

                del_files = []
                for act in entry["actions"]:
                    if act["type"] == "delete":
                        del_files.extend(act["files"])

                missing_del_files = set(delete) - set(del_files)
                added = False
                for act in entry["actions"]:
                    if act["type"] == "delete":
                        act["files"].extend(missing_del_files)
                        added = True

                if not added:
                    entry["actions"].append({"type": "delete", "files": missing_del_files})
            else:
                # NOTE: I'm deliberatly dropping support for COPY and RENAME here.

                entry = self.mods[id_] = {
                    "id": id_,
                    "title": mod.name,
                    "version": mod.version,
                    "description": mod.desc,
                    "logo": None,
                    "notes": mod.note,
                    "submods": ["FSOI#" + ".".join(smod.path) for smod in mod.submods],
                    "packages": [
                        {
                            "name": "Core files",
                            "notes": "",
                            "status": "required",
                            "dependencies": [
                                {"id": "FSOI#" + path, "version": "*", "packages": []} for path in mod.dependencies
                            ],
                            "environment": [],
                            "files": [],
                        }
                    ],
                    "actions": [{"type": "delete", "files": [pjoin(mod.folder, path) for path in mod.delete]}],
                }

            trail = "FSOI#"
            e_deps = entry["packages"][0]["dependencies"]
            for item in mod.path:
                trail += item
                if trail not in e_deps:
                    e_deps.append({"id": trail, "version": "*", "packages": []})

                trail += "."

            # Always keep the files in sync.
            flist = self.mods[id_]["packages"][0]["files"] = []

            for urls, filenames in mod.urls:
                files = {}
                flist.append((urls, files))

                for name in filenames:
                    files[name] = {"is_archive": is_archive(name), "dest": mod.folder}
コード例 #6
0
ファイル: repo.py プロジェクト: joshuasb/knossos
    def import_tree(self, mod_tree):
        mod_tree = self._flatten_tree(mod_tree)

        for path, mod in mod_tree.items():
            # First we need its ID.
            # For now, I'll simply use the path with a prefix.
            
            id_ = 'FSOI#' + path
            if id_ in self.mods:
                # Let's update it but try to honour local modifications.
                submods = ['FSOI#' + '.'.join(smod.path) for smod in mod.submods]
                dependencies = ['FSOI#' + path for path in mod.dependencies]
                delete = [pjoin(mod.folder, path) for path in mod.delete]

                entry = self.mods[id_]
                for smod in submods:
                    if smod not in entry['submods']:
                        entry['submods'].append(smod)
                
                e_deps = entry['packages'][0]['dependencies']
                for path in dependencies:
                    if path not in e_deps:
                        e_deps.append(path)
                
                del_files = []
                for act in entry['actions']:
                    if act['type'] == 'delete':
                        del_files.extend(act['files'])

                missing_del_files = set(delete) - set(del_files)
                added = False
                for act in entry['actions']:
                    if act['type'] == 'delete':
                        act['files'].extend(missing_del_files)
                        added = True
                
                if not added:
                    entry['actions'].append({'type': 'delete', 'files': missing_del_files})
            else:
                # NOTE: I'm deliberatly dropping support for COPY and RENAME here.

                entry = self.mods[id_] = {
                    'id': id_,
                    'title': mod.name,
                    'version': mod.version,
                    'description': mod.desc,
                    'logo': None,
                    'notes': mod.note,
                    'submods': ['FSOI#' + '.'.join(smod.path) for smod in mod.submods],
                    'packages': [
                        {
                            'name': 'Core files',
                            'notes': '',
                            'status': 'required',
                            'dependencies': [{'id': 'FSOI#' + path, 'version': '*', 'packages': []} for path in mod.dependencies],
                            'environment': [],
                            'files': []
                        }
                    ],
                    'actions': [{
                        'type': 'delete',
                        'files': [pjoin(mod.folder, path) for path in mod.delete]
                    }]
                }

            trail = 'FSOI#'
            e_deps = entry['packages'][0]['dependencies']
            for item in mod.path:
                trail += item
                if trail not in e_deps:
                    e_deps.append({'id': trail, 'version': '*', 'packages': []})

                trail += '.'

            # Always keep the files in sync.
            flist = self.mods[id_]['packages'][0]['files'] = []

            for urls, filenames in mod.urls:
                files = {}
                flist.append((urls, files))

                for name in filenames:
                    files[name] = {
                        'is_archive': is_archive(name),
                        'dest': mod.folder
                    }