def api(): global opt; if request.environ.get('wsgi.websocket'): ws = request.environ['wsgi.websocket'] while True: req = json.loads(ws.read_message()) print(str(req)); if (req['type'] == 'start'): startobj = {'repodir' : repodir }; #r = Repo(repodir) #r.remotes[0].fetch(); # 1: request repo branches repobranches = listOfManifestRepoBranches() ws.send(json.dumps({'type': 'mrbranches', 'data' : [ update(startobj, {'mrb' : e }) for e in repobranches['origin']]})); elif (req['type'] == 'mrbsel'): mrbsel = selobj(req['data']) r = Repo(mrbsel.repodir) r.git.checkout(mrbsel.mrb); manifestfiles = glob("%s/*xml"%(repodir)); ws.send(json.dumps({'type': 'manifestfiles', 'data' : [ update(mrbsel.tohash(), {'mfn' : e }) for e in manifestfiles]})); elif (req['type'] == 'mfnsel'): mfnsel = selobj(req['data']) r = Repo(mrbsel.repodir) r.git.checkout(mfnsel.mrb); print("Load {}\n".format(mfnsel.mfn)) m0 = manifest(opt, mfnsel.mfn); p0 = m0.get_projar(); pa = [] for e in p0.p: server=e.xml.attrib['_gitserver_'] if (server.startswith("..")): repofetchurl = [n for n in r.remotes[0].urls][0] a = repofetchurl.split("/"); a.pop() a[-1] = e.name; server = "/".join(a); else: if (not server.endswith("/")): server+="/" server+=e.name; p = e.path; if p == None: p = e.name; print(server + ": " + p) pa.append({ 'path' : p, 'server' : server}); ws.send(json.dumps({'type': 'repolist', 'data' : pa})); #ws.send(json.dumps({'type': 'manifestfiles', 'data' : manifestfiles})); time.sleep(1);
def prepareRepo(): global opt r = Repo(repodir) r.git.checkout(prepare_repobranch) m0 = manifest(opt, prepare_manifest) p0 = m0.get_projar() pa = [] for e in p0.p: server = serverFrom(r, e) d = os.path.join("/tmp/repo_work", serverUrlToPath(server)) print("Clone {} into {}".format(server, d)) rv = Repo.clone_from(server, d, mirror=True)
def main(): parser = argparse.ArgumentParser() parser.add_argument("-f", "--file", type=str, help="input manifest") args = parser.parse_args() o0 = manifest(args.file); print("Elements:"); def print_elem(e): print (str(e)); o0.traverse(['elem'], lambda x: print_elem(x)) print("Hirarchies:"); def print_hirarchy(e): print (str(e)); o0.traverse(['manifest'], lambda x: print_hirarchy(x)) print("Removes:"); def print_remove(e): print (str(e)); o0.traverse(['remove_project'], lambda x: print_remove(x))
def api(): global opt global workdir print("WS request: {}".format(str(request))) if request.environ.get('wsgi.websocket'): ws = request.environ['wsgi.websocket'] if opt.same: localprefix = "%08x" % (0) else: localprefix = "%08x" % (randrange(1 << 30)) base = os.path.join(workdir, localprefix) print("New user %s in '%s'" % (localprefix, base)) # reset local dir try: if not (opt.same): shutil.rmtree(base) except: pass try: if not os.path.exists(base): os.makedirs(base) except: pass print(str(opt.repos)) manifestpath = os.path.join(base, "__manifests__") os.makedirs(manifestpath, exist_ok=True) print("Scan manifestpath {}".format(manifestpath)) repolist = [] for d in os.listdir(manifestpath): dp = os.path.join(manifestpath, d) gp = os.path.join(dp, ".git") print("Examine {} if .git {} exist".format(dp, gp)) if os.path.isdir(gp): print("Found preallocated repo {}".format(dp)) repolist.append(dp) rv = Repo(dp) for remote in rv.remotes: remote.fetch() for e in opt.repos: #a = e.split(":"); #print(a) #n = a.pop(); #a = ":".join(a) n = e a = e print("Try clone '{}'".format(a)) p = getRepoDir(a, os.path.join(localprefix, n), nomirror=True) repolist.append(p) while True: try: try: req = ws.read_message() except: print("Websocket closed") return print("Got '{}'".format(req)) req = json.loads(req) print(str(req)) if (req['type'] == 'start'): if ('addpath' in req): addpath = req['addpath'].strip() print("Adding {} as manifest patch".format(addpath)) p = getRepoDir(addpath, manifestpath, nomirror=True) repolist.append(p) startobj = {} ws.send( json.dumps({ 'type': 'md', 'data': [ update(startobj, {'repodir': e}) for e in repolist ] })) #opt.repos elif (req['type'] == 'mdsel'): mdsel = selobj(req['data']) repobranches = listOfManifestRepoBranches(mdsel.repodir) ws.send( json.dumps({ 'type': 'mrbranches', 'id': mdsel.id, 'data': [ update(mdsel.tohash(), {'mrb': e}) for e in repobranches ] })) elif (req['type'] == 'mrbsel'): mrbsel = selobj(req['data']) ba = repoBranchComits(mrbsel.repodir, mrbsel.mrb) for e in ba: e['mrrev'] = e['sha'] ws.send( json.dumps({ 'type': 'mrrevs', 'id': mrbsel.id, 'data': [update(mrbsel.tohash(), e) for e in ba] })) elif (req['type'] == 'mrrevsel'): mrrevsel = selobj(req['data']) r = Repo(mrrevsel.repodir) r.git.checkout(mrrevsel.mrrev) manifestfiles = sorted(glob("%s/*xml" % (mrrevsel.repodir))) ws.send( json.dumps({ 'type': 'manifestfiles', 'id': mrrevsel.id, 'data': [ update(mrrevsel.tohash(), {'mfn': e}) for e in manifestfiles ] })) elif (req['type'] == 'mfnsel'): mfnsel = selobj(req['data']) r = Repo(mrbsel.repodir) r.git.checkout(mfnsel.mrrev) print("Load {}\n".format(mfnsel.mfn)) opt_copy = copy.deepcopy(opt) opt_copy.gitbase = gitbase(r) m0 = manifest(opt_copy, mfnsel.mfn) p0 = m0.get_projar() pa = [] for e in p0.p: server = serverFrom(r, e) p = e.path if p == None: p = e.name #print(server + ": " + p) u = urlparse(server) pa.append({ 'path': p, 'server': server, 'sha': e.revision, 'a_shortlog': "http://{}:8080/gitweb?p={}.git;a=shortlog;h={}". format(u.hostname, p, e.revision) }) ws.send( json.dumps( update(mfnsel.tohash(), { 'type': 'repolist', 'data': pa }))) elif (req['type'] == 'repoonoff'): repoonoff = selobj(req['data']) try: if (req['data']['onoff'] == "on"): # for diff calc only serverurl_a is used server = req['data']['server_a'] add = repodiff(server, req['data']['sha_a'], req['data']['sha_b'], localprefix) rem = repodiff(server, req['data']['sha_b'], req['data']['sha_a'], localprefix) branches = repoBranches(server, localprefix) tags = repotags(server, localprefix) u_add = urlparse(server) u_add_path = u_add.path u_add_path = re.sub(r'^/', "", u_add_path) ws.send( json.dumps({ 'type': 'repodiff', 'data': update( repoonoff.tohash(), { 'add': add, 'add_commitdiff': "http://{}:8080/gitweb?p={}.git;a=commitdiff;h=[ref]" .format(u_add.hostname, u_add_path), 'rem': rem, 'rem_commitdiff': "http://{}:8080/gitweb?p={}.git;a=commitdiff;h=[ref]" .format(u_add.hostname, u_add_path), 'branches': branches, 'tags': tags }) })) except Exception as e: print("Request:" + str(req)) print(str(e)) elif (req['type'] == 'reposha'): reposha = selobj(req['data']) try: c = repocommit(req['data']['server'], req['data']['sha'], localprefix) ws.send( json.dumps({ 'type': 'reposha', 'data': update(reposha.tohash(), c) })) except Exception as e: print(str(e)) elif (req['type'] == 'selrebasetag'): selrebasetag = selobj(req['data']) try: c = repotagsof(server, req['data']['branch'], localprefix) ws.send( json.dumps({ 'type': 'selrebasetag', 'data': update(selrebasetag.tohash(), c) })) except Exception as e: print(str(e)) except Exception as e: exc_info = sys.exc_info() traceback.print_exception(*exc_info) del (exc_info) print(str(e)) time.sleep(1)
def main(): parser = argparse.ArgumentParser(prog='step manifest') parser.add_argument('--verbose', action='store_true', help='verbose') parser.add_argument( '--addserver', action='append', default=[], help='specify upstream server: --addserver <servername>=url') parser.add_argument( '--rewriteproj', action='append', default=[], help= 'specify upstream id for project: "--rewrite <pname>=servername:upstream:sha", where servername can be specified via --addserver' ) parser.add_argument('--remove-path', '-r', dest='removepath', default=None) parser.add_argument('file', type=str, help='root maifest') parser.add_argument('output', type=str, help='flattend output') args = parser.parse_args() o0 = manifest(args, args.file) p = projar(None, args) # traverse over elements and process remove-project and project def touchproj(e): if isinstance(e, mh_project): p.add(e) elif isinstance(e, mh_remove_project): p.rem(e) o0.traverse(['elem'], lambda x: touchproj(x)) # optionally rewrite project path using option --remove-path h = {} projects = p.p for p in projects: h[p.name] = p n = str(p) print(" " + n) # add new review servers for r in args.addserver: n = r.split("=") a = n[1].split(":") name = n[0] url = a[0] print("addserver {} : server {} ".format(name, url)) m = mh_remote(args, None, ET.Element('remote')) m.addxml('name', name) m.addxml('fetch', url) o0.add_remote(m) # rewrite upstream and sha field for r in args.rewriteproj: n = r.split("=") a = n[1].split(":") name = n[0] (server, upstream, revision) = (a[0], a[1], a[2]) upstream = a[1] print("rewrite {} : server {} upstream {} sha {} ".format( name, server, upstream, revision)) if (name in h): p = h[name] if (len(server)): p.addxml('remote', server) p.addxml('upstream', upstream) p.setxml('revision', revision) else: raise ("Project {} not found".format(name)) # output o0.write(args.output)
def api(): global opt if request.environ.get('wsgi.websocket'): ws = request.environ['wsgi.websocket'] while True: req = json.loads(ws.read_message()) print(str(req)) if (req['type'] == 'start'): startobj = { 'repodir': repodir } #r = Repo(repodir) #r.remotes[0].fetch(); # 1: request repo branches repobranches = listOfManifestRepoBranches() ws.send( json.dumps({ 'type': 'mrbranches', 'data': [update(startobj, {'mrb': e}) for e in repobranches] })) elif (req['type'] == 'mrbsel'): mrbsel = selobj(req['data']) r = Repo(mrbsel.repodir) r.git.checkout(mrbsel.mrb) manifestfiles = glob("%s/*xml" % (repodir)) ws.send( json.dumps({ 'type': 'manifestfiles', 'data': [ update(mrbsel.tohash(), {'mfn': e}) for e in manifestfiles ] })) elif (req['type'] == 'mfnsel'): mfnsel = selobj(req['data']) r = Repo(mrbsel.repodir) r.git.checkout(mfnsel.mrb) print("Load {}\n".format(mfnsel.mfn)) try: m0 = manifest(opt, mfnsel.mfn) except Exception as e: print(e) p0 = m0.get_projar() pa = [] for e in p0.p: server = serverFrom(r, e) reviewserver = serverFrom(r, e, typ="review") p = e.path if p == None: p = e.name print(server + ": " + p) pa.append({ 'treepath': p, 'server': server, 'review': reviewserver }) ws.send(json.dumps({ 'type': 'repolist', 'data': pa })) elif (req['type'] == 'repoonoff'): repoonoff = selobj(req['data']) if (req['data']['onoff'] == "on"): pa = repoBranches(repoonoff.repo) ws.send( json.dumps({ 'type': 'repobranchlist', 'data': update(repoonoff.tohash(), { 'repobranches': pa, 'reviews': [] }) })) #ws.send(json.dumps({'type': 'manifestfiles', 'data' : manifestfiles})); elif (req['type'] == 'repobranch'): repobranch = selobj(req['data']) pa = repoBranchComits(repobranch.repo, repobranch.repobranch) ra = getGerritReviews(repoonoff.review, repobranch.repobranch) #print(" + Reviews found " + str(ra)); ws.send( json.dumps({ 'type': 'reposhalist', 'data': update(repobranch.tohash(), { 'sha': pa, 'reviews': ra }) })) time.sleep(1)