import configparserimport osfrom deploy.Windows.config import DeployConfigfrom deploy.Windows.logger import Progress, loggerfrom deploy.Windows.utils import cached_propertyfrom deploy.git_over_cdn.client import GitOverCdnClientclass GitConfigParser(configparser.ConfigParser):def check(self, section, option, value):result = self.get(section, option, fallback=None)if result == value:logger.info(f'Git config {section}.{option} = {value}')return Trueelse:return Falseclass GitOverCdnClientWindows(GitOverCdnClient):def update(self, *args, **kwargs):Progress.GitInit()_ = super().update(*args, **kwargs)Progress.GitShowVersion()return _@cached_propertydef latest_commit(self) -> str:_ = super().latest_commitProgress.GitLatestCommit()return _def download_pack(self):_ = super().download_pack()Progress.GitDownloadPack()return _class GitManager(DeployConfig):@staticmethoddef remove(file):try:os.remove(file)logger.info(f'Removed file: {file}')except FileNotFoundError:logger.info(f'File not found: {file}')@cached_propertydef git_config(self):conf = GitConfigParser()conf.read('./.git/config')return confdef git_repository_init(self, repo, source='origin', branch='master', proxy='', ssl_verify=True):logger.hr('Git Init', 1)if not self.execute(f'"{self.git}" init', allow_failure=True):self.remove('./.git/config')self.remove('./.git/index')self.remove('./.git/HEAD')self.remove('./.git/ORIG_HEAD')self.execute(f'"{self.git}" init')Progress.GitInit()logger.hr('Set Git Proxy', 1)if proxy:if not self.git_config.check('http', 'proxy', value=proxy):self.execute(f'"{self.git}" config --local http.proxy {proxy}')if not self.git_config.check('https', 'proxy', value=proxy):self.execute(f'"{self.git}" config --local https.proxy {proxy}')else:if not self.git_config.check('http', 'proxy', value=None):self.execute(f'"{self.git}" config --local --unset http.proxy', allow_failure=True)if not self.git_config.check('https', 'proxy', value=None):self.execute(f'"{self.git}" config --local --unset https.proxy', allow_failure=True)if ssl_verify:if not self.git_config.check('http', 'sslVerify', value='true'):self.execute(f'"{self.git}" config --local http.sslVerify true', allow_failure=True)else:if not self.git_config.check('http', 'sslVerify', value='false'):self.execute(f'"{self.git}" config --local http.sslVerify false', allow_failure=True)Progress.GitSetConfig()logger.hr('Set Git Repository', 1)if not self.git_config.check(f'remote "{source}"', 'url', value=repo):if not self.execute(f'"{self.git}" remote set-url {source}{repo}', allow_failure=True):self.execute(f'"{self.git}" remote add {source}{repo}')Progress.GitSetRepo()logger.hr('Fetch Repository Branch', 1)self.execute(f'"{self.git}" fetch {source}{branch}')Progress.GitFetch()logger.hr('Pull Repository Branch', 1)# Remove git lockfor lock_file in ['./.git/index.lock','./.git/HEAD.lock','./.git/refs/heads/master.lock',]:if os.path.exists(lock_file):logger.info(f'Lock file {lock_file} exists, removing')os.remove(lock_file)self.execute(f'"{self.git}" reset --hard {source}/{branch}')Progress.GitReset()# Since `git fetch` is already called, checkout is fasterif not self.execute(f'"{self.git}" checkout {branch}', allow_failure=True):self.execute(f'"{self.git}" pull --ff-only {source}{branch}')Progress.GitCheckout()logger.hr('Show Version', 1)self.execute(f'"{self.git}" --no-pager log --no-merges -1')Progress.GitShowVersion()@propertydef goc_client(self):client = GitOverCdnClient(url='https://vip.123pan.cn/1815343254/pack/LmeSzinc_StarRailCopilot_master',folder=self.root_filepath,source='origin',branch='master',git=self.git,)client.logger = loggerreturn clientdef git_install(self):logger.hr('Update Alas', 0)if not self.AutoUpdate:logger.info('AutoUpdate is disabled, skip')Progress.GitShowVersion()returnif self.GitOverCdn:if self.goc_client.update():returnself.git_repository_init(repo=self.Repository,source='origin',branch=self.Branch,proxy=self.GitProxy,ssl_verify=self.SSLVerify,)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。