示例#1
0
    def installModFromGit(self, pkg, result):

        # Update instead if already exists
        if pkg.installDir.exists():
            return self.updateModFromGit(pkg, result)

        # Install
        else:

            try:
                # Init repo, get manifest
                gh = self.RepoImpl(pkg.git)
                gh.syncManifestHttp()

                # Check dependencies based on manifest.ini or metadata.txt
                (depsOk,
                 failedDependencies) = deps.check_dependencies(gh.manifest)
                if not depsOk:
                    result.failedDependencies = failedDependencies
                    return result

                # Clone and update submodules
                repo, _ = clone_local(pkg.git, pkg.installDir, branch='master')
                if repo.submodules:
                    repo.submodule_update(recursive=True)

                result.ok = True

            except:
                log(traceback.format_exc())
                result.ok = False

        return result
示例#2
0
    def installModFromHttpZip(self, pkg, result):

        try:
            # Init repo, get manifest
            gh = self.RepoImpl(pkg.git)
            gh.syncManifestHttp()

            # Check dependencies based on manifest.ini or metadata.txt
            (depsOk, failedDependencies) = deps.check_dependencies(gh.manifest)
            if not depsOk:
                result.failedDependencies = failedDependencies
                return result

            # Download mater zip
            zip_path = Path(tempfile.mktemp(suffix=".zip"))
            if http_download(gh.getZipUrl(), zip_path):
                exploded = Path(tempfile.mktemp(suffix="_zip"))
                zlib.unzip(zip_path, exploded)

                # Remove old if exists
                if pkg.installDir.exists():
                    shutil.rmtree(pkg.installDir, ignore_errors=True)

                # Move exploded dir to install dir
                for entry_path in exploded.iterdir():
                    if entry_path.is_dir():
                        shutil.move(entry_path, pkg.installDir)
                        result.ok = True
                        break  # Only one zip directory is expected

        except:
            log(traceback.format_exc())
            result.ok = False

        return result
示例#3
0
    def updateModFromGit(self, pkg, result):

        # Install instead if not exists
        if not pkg.installDir.exists():
            return self.installModFromGit(pkg, result)

        # Update
        else:

            try:
                # Init repo, get manifest
                gh = self.RepoImpl(pkg.git)
                gh.syncManifestHttp()

                # Check dependencies based on manifest.ini or metadata.txt
                (depsOk,
                 failedDependencies) = deps.check_dependencies(gh.manifest)
                if not depsOk:
                    result.failedDependencies = failedDependencies
                    return result

                # Upgrade to git if necessary
                import git
                bare_path = Path(pkg.installDir, '.git')
                if not bare_path.exists():
                    bare, _ = gh.clone(bare_path, bare=True)
                    config_set(bare, 'core', 'bare', False)
                    repo = git.Repo(pkg.installDir)
                    repo.head.reset('--hard')

                # Pull
                repo = git.Git(pkg.installDir)
                repo.pull('--depth=1')
                repo = git.Repo(pkg.installDir)
                for mod in repo.submodules:
                    mod.update(init=True, recursive=True)

                result.ok = True

            except:
                log(traceback.format_exc())
                result.ok = False

        return result