当前位置: 首页>>代码示例>>Python>>正文


Python Git.current_remote_uri方法代码示例

本文整理汇总了Python中git.Git.current_remote_uri方法的典型用法代码示例。如果您正苦于以下问题:Python Git.current_remote_uri方法的具体用法?Python Git.current_remote_uri怎么用?Python Git.current_remote_uri使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在git.Git的用法示例。


在下文中一共展示了Git.current_remote_uri方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Project

# 需要导入模块: from git import Git [as 别名]
# 或者: from git.Git import current_remote_uri [as 别名]
class Project():
	def __init__(self):
		self.tree = ElementTree();
		self.git = Git()
		if not os.path.exists(PROJECT_CONFIG_PATH):
			os.mkdir(PROJECT_CONFIG_PATH)
		try:
			self.tree.parse(PROJECT_CONFIG_FILE)
		except:
			root = Element('Project', {'name':os.path.basename(os.getcwd())})
			self.tree._setroot(root)

	def save(self):
		self.tree.write(PROJECT_CONFIG_FILE, xml_declaration=True, method="xml")

	def iter(self):
		return self.tree.iter('SubProject')

	def find(self, name):
		for i in self.iter():
			if i.get('name') == name:
				return i

	def inSubProject(self):
		cwd = os.getcwd()
		for node in self.iter():
			name = node.get('name')
			print("")
			print("On:%s" % name)
			print("***************************************")
			os.chdir("/".join([cwd, name]))
			yield
			print("***************************************")

	def clone(self):
		for module in self.iter():
			self.git.clone(module)

	def __init_module(self, module):
		if not os.path.exists(module):
			print("module %s not exists." % module)
			return None
		cwd = os.getcwd()
		os.chdir("/".join([cwd, module]))
		if self.git.is_repo():
			node = Element('SubProject')
			node.set("name", module)
			current_branch = self.git.current_branch()
			if current_branch != None:
				node.set("branch", current_branch)
			remote_uri = self.git.current_remote_uri(branch=current_branch)
			if remote_uri != None:
				node.set("uri", remote_uri)
			else:
				node = None
		else:
			print("fatal: Not a git repository")
			node = None
				
		os.chdir(cwd)
		return node

	def __append_ignore_file(self, module):
		if os.path.exists(".gitignore"):
			ignoreFile = open(".gitignore","r")
			for line in ignoreFile:
				if module == line.strip():
					return
			ignoreFile.close()
		ignoreFile = open(".gitignore", "a")
		ignoreFile.write(module + "\n")
		ignoreFile.close()

	def __remove_ignore_file(self, modules):
		if os.path.exists(".gitignore"):
			ignoreFile = open(".gitignore","r")
			print modules
			data = [line.strip() for line in ignoreFile if not (line.strip() in modules)]
			ignoreFile = open(".gitignore", "w")
			ignoreFile.write("\n".join(data)+"\n")
			ignoreFile.close()
			data = None


	def append(self, module):
		if module == None:
			return -1
		node = self.find(module)
		root = self.tree.getroot()
		if node != None:
			root.remove(node)
		node = self.__init_module(module)
		if node == None:
			return -1
		else:
			root.append(node)
			self.__append_ignore_file(module)
		self.save()
		return 0

#.........这里部分代码省略.........
开发者ID:cpsoft,项目名称:mgit,代码行数:103,代码来源:project.py


注:本文中的git.Git.current_remote_uri方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。