一个类似repo的小程序
Posted 身带吴钩
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了一个类似repo的小程序相关的知识,希望对你有一定的参考价值。
#! /usr/bin/env python # -*- coding: utf-8 -*- # usage : python EasyRepo.py -u "13051041" -v "v6.0.0" # by (13051041) 20160909 import os try: import xml.etree.cElementTree as ET except ImportError: import xml.etree.ElementTree as ET import sys projectList = [] class Project: def __init__(self,n,b): self.name = n self.branch = b def downloadManifest(username,version): manifest = "git clone ssh://%[email protected]:29418/manifest"%(username) os.system(manifest) path = os.path.join(os.getcwd(),"manifest") for parent,dirnames,filenames in os.walk(path): for filename in filenames: if version in str(filename): print "the version xml file is:" + os.path.join(parent,filename) return os.path.join(parent,filename) pass def analyzerXml(path): global projectList try: tree = ET.parse(path) root = tree.getroot() except Exception, e: print "Error:cannot parse file:country.xml." sys.exit(1) for project in root.findall(‘project‘): name = project.get(‘name‘) version = project.get(‘revision‘) p = Project(name,version) projectList.append(p) print name, version def syncProject(username): global projectList for p in projectList: cmd = ‘‘‘ git clone ssh://%[email protected]:29418/%s && scp -p -P 29418 %[email protected]:hooks/commit-msg %s/.git/hooks/ cd %s git pull git checkout %s ‘‘‘% (username,p.name,username,p.name,p.name,p.branch) os.system(cmd) if __name__ == ‘__main__‘: help = ‘‘‘usage : python easyRepo.py -u 13051041 -v v6.0.0 ‘‘‘ username = "" version = "" numU = 0 numV = 0 numH = 0 for i in range(1, len(sys.argv)): if "-v" in sys.argv[i]: numV = i if "-u" in sys.argv[i]: numU = i if "-h" in sys.argv[i]: numH = i if numU != 0 and i== numU+1: username = sys.argv[i] if numV != 0 and i== numV+1: version = sys.argv[i] if numH !=0: print help if numU == 0: print "参数有问题 没有 -u" print help sys.exit(1) if numV == 0: print "参数有问题 没有 -v" print help sys.exit(1) print "user name is ",username print "version name is ",version path = downloadManifest(username,version) analyzerXml(path) syncProject(username)
以上是关于一个类似repo的小程序的主要内容,如果未能解决你的问题,请参考以下文章
ubuntu16.04 yum报错:There are no enabled repos. Run “yum repolist all“ to see the repos you have.(代码片段
在android studio中升级repo v9后,片段必须是公共静态类崩溃错误