本文整理汇总了Python中git.repo.Repo.delete_remote方法的典型用法代码示例。如果您正苦于以下问题:Python Repo.delete_remote方法的具体用法?Python Repo.delete_remote怎么用?Python Repo.delete_remote使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类git.repo.Repo
的用法示例。
在下文中一共展示了Repo.delete_remote方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: GitSync
# 需要导入模块: from git.repo import Repo [as 别名]
# 或者: from git.repo.Repo import delete_remote [as 别名]
class GitSync(object):
def __init__(self, database):
logging.info("Initializing GitSync.")
self.database = database
self.charts = dict()
self.url = DEFAULT_GITREPO
try:
self.repo = Repo(REPO_DIRECTORY)
except InvalidGitRepositoryError:
logging.info("Cloning repository in %s", REPO_DIRECTORY)
self.repo = Repo.clone_from(self.url, REPO_DIRECTORY)
@coroutine
def update_repo(self, document):
if document['o']["charts"]["repo_url"] != self.url:
logging.info("Repo url updated to '%s'.", document['o']["charts"]["repo_url"])
self.url = document['o']["charts"]["repo_url"]
@coroutine
def sync_loop(self):
logging.info("Initializing sync loop.")
yield add_callback("Settings", self.update_repo)
synced_head = None
settings = yield Query(self.database, "Settings").find_one() or dict()
if settings["charts"]:
self.url = settings["charts"]["repo_url"]
while True:
try:
if self.url != self.repo.remotes.origin.url:
logging.info("Changing reference from '%s' to '%s'.", self.repo.remotes.origin.url, self.url)
self.repo.delete_remote('origin')
self.repo.create_remote('origin', url=self.url)
synced_head = None
self.repo.git.fetch('--all')
self.repo.git.reset('--hard', 'origin/master')
if synced_head != self.repo.head.ref.commit:
yield self.sync()
synced_head = self.repo.head.ref.commit
except:
logging.exception("Failed to pull repository.")
yield sleep(5)
@coroutine
def sync(self):
logging.info("Syncing '%s'.", REPO_DIRECTORY)
charts = yield Query(self.database, "Charts", manipulate=True).find()
for chart in charts:
path = chart["path"]
self.charts[path] = chart
discovered_charts = dict()
for subdir, _, files in os.walk(REPO_DIRECTORY):
for chart_file in files:
if chart_file == "Chart.yaml":
try:
discovered_charts[subdir] = yield self.import_chart(subdir)
except Exception:
logging.exception("Failed to import chart at '%s'", subdir)
for path, existing in self.charts.iteritems():
discovered = discovered_charts.get(path, None)
if discovered is None:
logging.debug("Deleting chart %(name)s", existing)
yield Query(self.database, 'Charts').remove(existing)
else:
discovered["_id"] = existing["_id"]
discovered["metadata"] = existing["metadata"]
if discovered["commit"] != existing["commit"]:
logging.debug("Updating existing chart %(name)s", discovered)
yield Query(self.database, "Charts", manipulate=True).update(discovered)
for path, discovered in discovered_charts.iteritems():
if discovered and "_id" not in discovered:
logging.debug("Inserting new chart %(name)s", discovered)
try:
yield Query(self.database, "Charts", manipulate=True).insert(discovered)
except:
logging.error("Failed to insert chart %(name)s", discovered)
self.charts = discovered_charts
@coroutine
def import_chart(self, directory):
chart_path = os.path.join(directory, "Chart.yaml")
with open(chart_path, "r") as stream:
chart = load(stream)
#.........这里部分代码省略.........