本文整理汇总了Python中git.Git.clear_cache方法的典型用法代码示例。如果您正苦于以下问题:Python Git.clear_cache方法的具体用法?Python Git.clear_cache怎么用?Python Git.clear_cache使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类git.Git
的用法示例。
在下文中一共展示了Git.clear_cache方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: GitWrapper
# 需要导入模块: from git import Git [as 别名]
# 或者: from git.Git import clear_cache [as 别名]
class GitWrapper(object):
"""
A wrapper for repo.git providing better stdout handling + better exeptions.
It is preferred to repo.git because it doesn't print to stdout
in real time. In addition, this wrapper provides better error
handling (it provides stdout messages inside the exception, too).
"""
def __init__(self, repo):
if repo:
#: :type: git.Repo
self.repo = repo
#: :type: git.Git
self.git = self.repo.git
else:
#: :type: git.Git
self.git = Git()
def __del__(self):
# Is the following true?
# GitPython runs persistent git processes in the working directory.
# Therefore, when we use 'git up' in something like a test environment,
# this might cause troubles because of the open file handlers (like
# trying to remove the directory right after the test has finished).
# 'clear_cache' kills the processes...
if platform.system() == 'Windows': # pragma: no cover
pass
# ... or rather "should kill", because but somehow it recently
# started to not kill cat_file_header out of the blue (I even
# tried running old code, but the once working code failed).
# Thus, we kill it manually here.
if self.git.cat_file_header is not None:
subprocess.call(("TASKKILL /F /T /PID {0} 2>nul 1>nul".format(
str(self.git.cat_file_header.proc.pid)
)), shell=True)
if self.git.cat_file_all is not None:
subprocess.call(("TASKKILL /F /T /PID {0} 2>nul 1>nul".format(
str(self.git.cat_file_all.proc.pid)
)), shell=True)
self.git.clear_cache()
def run(self, name, *args, **kwargs):
""" Run a git command specified by name and args/kwargs. """
tostdout = kwargs.pop('tostdout', False)
stdout = six.b('')
# Execute command
cmd = getattr(self.git, name)(as_process=True, *args, **kwargs)
# Capture output
while True:
output = cmd.stdout.read(1)
# Print to stdout
if tostdout:
sys.stdout.write(output.decode('utf-8'))
sys.stdout.flush()
stdout += output
if output == six.b(""):
break
# Wait for the process to quit
try:
cmd.wait()
except GitCommandError as error:
# Add more meta-information to errors
message = "'{0}' returned exit status {1}".format(
' '.join(str(c) for c in error.command),
error.status
)
raise GitError(message, stderr=error.stderr, stdout=stdout)
return stdout.strip()
def __getattr__(self, name):
return lambda *args, **kwargs: self.run(name, *args, **kwargs)
###########################################################################
# Overwrite some methods and add new ones
###########################################################################
@contextmanager
def stash(self):
"""
A stashing contextmanager.
It stashes all changes inside and unstashed when done.
"""
stashed = False
if self.repo.is_dirty(submodules=False):
if self.change_count > 1:
message = 'stashing {0} changes'
#.........这里部分代码省略.........