From 82dd49e573a59ab79fa70e6578a8158c58aca34b Mon Sep 17 00:00:00 2001 From: Kito Date: Fri, 3 Feb 2006 05:52:37 +0000 Subject: [PATCH] svn/alt hack for repoman. svn path=/main/branches/prefix/; revision=2636 --- bin/repoman | 396 +++++++++++++++++++++++++++++++++++----------------- 1 file changed, 266 insertions(+), 130 deletions(-) diff --git a/bin/repoman b/bin/repoman index d47e18f7b..50c6f8b79 100755 --- a/bin/repoman +++ b/bin/repoman @@ -56,7 +56,7 @@ def exithandler(signum=None,frame=None): os.kill(0,signal.SIGKILL) signal.signal(signal.SIGINT,exithandler) -REPOROOTS=["gentoo-x86"] +REPOROOTS=["gentoo-x86","gentoo-alt/trunk/prefix"] shortmodes={"ci":"commit"} modeshelp={ "scan" : "Scan directory tree for QA issues (default)", @@ -278,10 +278,12 @@ def help(exitstatus=1,helpfulness=1): def last(): try: #Retrieve and unpickle stats and fails from saved files - savedf=open('/var/cache/edb/repo.stats','r') + mystats=os.path.normpath(portage_const.CACHE_DIR+'/repo.stats') + myfails=os.path.normpath(portage_const.CACHE_DIR+'/repo.fails') + savedf=open(mystat,'r') stats = pickle.load(savedf) savedf.close() - savedf=open('/var/cache/edb/repo.fails','r') + savedf=open(myfails,'r') fails = pickle.load(savedf) savedf.close() except SystemExit, e: @@ -434,9 +436,31 @@ if os.path.isdir("CVS"): print sys.exit(123) -if not "--pretend" in myoptions and not isCvs: +isSvn=False +myreporoot=None +if os.path.isdir(".svn"): + repoman_settings["PORTDIR_OVERLAY"]="" + if "svn" not in portage.features: + print + print + print red('!!! You do not have ')+bold('FEATURES="svn" ')+red("enabled...") + print red("!!! ")+bold("Adding \"svn\" to FEATURES") + print + os.environ["FEATURES"]=repoman_settings["FEATURES"]+" svn" + + try: + isSvn=True + myrepoinfo=os.popen("svn info").readlines() + myreporoot=myrepoinfo[1].split("var/svnroot/")[1].rstrip() + myreporootpath=os.path.normpath(myrepoinfo[1].split("svn.gentoo.org")[1].rstrip().replace(myreporoot,'')) + except SystemExit, e: + raise # Need to propogate this + except: + err("Error grabbing repository information; exiting.") + +if not "--pretend" in myoptions and not isCvs and not isSvn: print - print darkgreen("Not in a CVS repository; enabling pretend mode.") + print darkgreen("Not in a CVS or SVN repository; enabling pretend mode.") myoptions.append("--pretend"); @@ -503,21 +527,25 @@ if not myreporoot: myreporoot = os.path.basename(portdir_overlay) myreporoot += mydir[len(portdir_overlay):-1] -if isCvs: +if isCvs or isSvn: reporoot=None for x in REPOROOTS: if myreporoot[0:len(x)]==x: reporoot=myreporoot if not reporoot: err("Couldn't recognize repository type. Supported repositories:\n"+repr(REPOROOTS)) -reposplit=string.split(myreporoot,"/") +if isSvn: + reposplit=string.split(os.path.normpath(myrepoinfo[1].split("svn.gentoo.org")[1].rstrip().replace("/var/svnroot",'')).replace(x,'')[2:],"/") + reposplit.insert(0,myrepo) +else: + reposplit=string.split(myreporoot,"/") repolevel=len(reposplit) # check if it's in $PORTDIR/$CATEGORY/$PN , otherwise bail if commiting. # Reason for this is if they're trying to commit in just $FILESDIR/*, the Manifest needs updating. # this check ensure that repoman knows where it is, and the manifest recommit is at least possible. if mymode == "commit" and repolevel not in [1,2,3]: - print red("***")+" Commit attempts *must* be from within a cvs co, category, or package directory." + print red("***")+" Commit attempts *must* be from within a cvs or svn co, category, or package directory." print red("***")+" Attempting to commit from a packages files directory will be blocked for instance." print red("***")+" This is intended behaviour, to ensure the manifest is recommited for a package." print red("***") @@ -580,7 +608,7 @@ except SystemExit, e: except: err("Couldn't read KEYWORDS from arch.list") if not kwlist: - kwlist=["alpha","arm","hppa","mips","ppc","sparc","x86"] + kwlist=["alpha","arm","hppa","mips","ppc","ppc-macos","sparc","x86"] scanlist=[] if repolevel==2: @@ -590,7 +618,7 @@ if repolevel==2: caterror(catdir) mydirlist=os.listdir(startdir) for x in mydirlist: - if x=="CVS": + if x=="CVS" or x==".svn": continue if os.path.isdir(startdir+"/"+x): scanlist.append(catdir+"/"+x) @@ -599,7 +627,7 @@ elif repolevel==1: if not os.path.isdir(startdir+"/"+x): continue for y in os.listdir(startdir+"/"+x): - if y=="CVS": + if y=="CVS" or y==".svn": continue if os.path.isdir(startdir+"/"+x+"/"+y): scanlist.append(x+"/"+y) @@ -769,7 +797,7 @@ for x in scanlist: s = s[s.rfind("\n") + 1:] fails["file.UTF8"].append("%s/%s: line %i, just after: '%s'" % (checkdir, y, line, s)) - if isCvs: + if isCvs or isSvn: try: mystat=os.stat(checkdir+"/files")[0] if len(ebuildlist) and not S_ISDIR(mystat): @@ -781,41 +809,57 @@ for x in scanlist: fails["filedir.missing"].append(checkdir) continue try: - myf=open(checkdir+"/CVS/Entries","r") - myl=myf.readlines() + if isCvs: + myf=open(checkdir+"/CVS/Entries","r") + if isSvn: + myf=os.popen("svn list") + myl=myf.readlines() + myf.close() for l in myl: if l[0]!="/": + lname=l.split() + else: + lname=l[1:].split("/") + if not len(lname): continue - splitl=l[1:].split("/") - if not len(splitl): - continue - objsadded.append(splitl[0]) - if splitl[0][-7:]==".ebuild": - eadded.append(splitl[0][:-7]) - if splitl[0]=="ChangeLog": + objsadded.append(lname[0]) + if lname[0][-7:]==".ebuild": + eadded.append(lname[0][:-7]) + if lname[0]=="ChangeLog": cladded=1 except IOError: - if mymode=="commit": + if mymode=="commit" and isCvs: stats["CVS/Entries.IO_error"] += 1 fails["CVS/Entries.IO_error"].append(checkdir+"/CVS/Entries") + if mymode=="commit" and isSvn: + stats["svn.IO_error"] += 1 + fails["svn.IO_error"].append(checkdir+"svn info") continue try: - myf=open(checkdir+"/files/CVS/Entries","r") + if isCvs: + myf=open(checkdir+"/files/CVS/Entries","r") + if isSvn: + myf=os.popen("svn list "+os.path.normpath(checkdir+"/files")) myl=myf.readlines() + myf.close() for l in myl: if l[0]!="/": + lname=l.split() + else: + lname=l[1:].split("/") + if not len(lname): continue - splitl=l[1:].split("/") - if not len(splitl): - continue - objsadded.append(splitl[0]) - if splitl[0][:7]=="digest-": - dadded.append(splitl[0][7:]) + objsadded.append(lname[0]) + if lname[0][:7]=="digest-": + dadded.append(lname[0][7:]) except IOError: - if mymode=="commit": + if mymode=="commit" and isCvs: stats["CVS/Entries.IO_error"] += 1 fails["CVS/Entries.IO_error"].append(checkdir+"/files/CVS/Entries") + if mymode=="commit" and isSvn: + stats["svn.IO_error"] += 1 + fails["svn.IO_error"].append(checkdir+"/files svn info") continue if os.path.exists(checkdir+"/files"): @@ -823,7 +867,7 @@ for x in scanlist: for y in filesdirlist: if y[:7]=="digest-": if y[7:] not in dadded: - #digest not added to cvs + #digest not added to cvs or svn stats["digest.notadded"]=stats["digest.notadded"]+1 fails["digest.notadded"].append(x+"/files/"+y) if y[7:] in eadded: @@ -840,10 +884,15 @@ for x in scanlist: if y[7:] not in ebuildlist: #stray digest if mymode=="fix": + if isCvs: + vcsrm="cvs rm -f" + if isSvn: + vcsrm="svn rm" if "--pretend" in myoptions: - print "(cd "+repodir+"/"+x+"/files; cvs rm -f "+y+")" + print "(cd "+repodir+"/"+x+"/files; "+vcsrm+" "+y+")" + else: - os.system("(cd "+repodir+"/"+x+"/files; cvs rm -f "+y+")") + os.system("(cd "+repodir+"/"+x+"/files; "+vcsrm+" "+y+")") else: stats["digest.stray"]=stats["digest.stray"]+1 fails["digest.stray"].append(x+"/files/"+y) @@ -898,7 +947,7 @@ for x in scanlist: else: raise oe if S_ISDIR(mystat.st_mode): - if y == "CVS": + if y == "CVS" or y == ".svn": continue for z in os.listdir(checkdir+"/files/"+y): filesdirlist.append(y+"/"+z) @@ -950,9 +999,9 @@ for x in scanlist: if mymode=="fix": if "--pretend" in myoptions: print "You will need to run:" - print " "+"portage_const.PORTAGE_BASE+"/usr/sbin/ebuild "+repodir+"/"+x+"/"+y+".ebuild digest" + print " "+portage_const.PORTAGE_BASE+"/bin/ebuild "+repodir+"/"+x+"/"+y+".ebuild digest" else: - retval=os.system(portage_const.PORTAGE_BASE+"/usr/sbin/ebuild "+repodir+"/"+x+"/"+y+".ebuild digest") + retval=os.system(portage_const.PORTAGE_BASE+"/bin/ebuild "+repodir+"/"+x+"/"+y+".ebuild digest") if retval: print "!!! Exiting on ebuild digest (shell) error code:",retval sys.exit(retval) @@ -1175,7 +1224,7 @@ for x in scanlist: fails[mykey].append(x+"/"+y+".ebuild: "+keyword+"("+prof[0]+") "+repr(mydep[1])) # this check needs work, it won't catch (\ndie) - if not os.system("@EGREP@ '^[^#]*\([^)]*\' "+checkdir+"/"+y+".ebuild >/dev/null 2>&1"): + if not os.system(portage_const.PREFIX+"/usr/bin/grep -E '^[^#]*\([^)]*\' "+checkdir+"/"+y+".ebuild >/dev/null 2>&1"): stats["ebuild.nesteddie"]=stats["ebuild.nesteddie"]+1 fails["ebuild.nesteddie"].append(x+"/"+y+".ebuild") # uselist checks - global @@ -1313,20 +1362,21 @@ for x in scanlist: fails["ebuild.allmasked"].append(x) #Pickle and save results for instant reuse in last and lfull -savef=open('/var/cache/edb/repo.stats','w') +statsfile=os.path.normpath(portage_const.CACHE_PATH+"/repo.stats") +failsfile=os.path.normpath(portage_const.CACHE_PATH+"/repo.fails") +savef=open(statsfile,'w') pickle.dump(stats,savef) savef.close() -savef=open('/var/cache/edb/repo.fails','w') +savef=open(failsfile,'w') pickle.dump(fails,savef) savef.close() -if not (os.stat('/var/cache/edb/repo.stats')[ST_GID] == getgrnam('portage')[2]): - os.chown('/var/cache/edb/repo.stats',os.geteuid(),getgrnam('portage')[2]) - os.chmod('/var/cache/edb/repo.stats',0664) -if not (os.stat('/var/cache/edb/repo.fails')[ST_GID] == getgrnam('portage')[2]): - os.chown('/var/cache/edb/repo.fails',os.geteuid(),getgrnam('portage')[2]) - os.chmod('/var/cache/edb/repo.fails',0664) -if quiet < 2: - print +if not (os.stat(statsfile)[ST_GID] == getgrnam('portage')[2]): + os.chown(statsfile,os.geteuid(),getgrnam('portage')[2]) + os.chmod(statsfile,0664) +if not (os.stat(failsfile)[ST_GID] == getgrnam('portage')[2]): + os.chown(failsfile,os.geteuid(),getgrnam('portage')[2]) + os.chmod(failsfile,0664) +print #dofail will be set to 1 if we have failed in at least one non-warning category dofail=0 #dowarn will be set to 1 if we tripped any warnings @@ -1334,7 +1384,7 @@ dowarn=0 #dofull will be set if we should print a "repoman full" informational message dofull=0 for x in qacats: - if not isCvs and (string.find(x, "notadded") != -1): + if not isCvs and not isSvn and (string.find(x, "notadded") != -1): stats[x] = 0 if stats[x]: dowarn=1 @@ -1414,12 +1464,23 @@ else: print "!!! Exiting on ebuild digest (shell) error code:",retval sys.exit(retval) - mycvstree=cvstree.getentries("./",recursive=1) - if isCvs and not mycvstree: - print "!!! It seems we don't have a cvs tree?" - sys.exit(3) + if isCvs: + try: + myvcstree=cvstree.getentries("./",recursive=1) + myunadded=cvstree.findunadded(myvcstree,recursive=1,basedir="./") + except SystemExit, e: + raise # TODO propogate this + except: + err("Error retrieving CVS tree; exiting.") - myunadded=cvstree.findunadded(mycvstree,recursive=1,basedir="./") + if isSvn: + try: + svnstatus=os.popen("svn status").readlines() + myunadded = [ "./"+elem.rstrip().split()[1] for elem in svnstatus if elem.startswith("?") ] + except SystemExit, e: + raise # TODO propogate this + except: + err("Error retrieving SVN info; exiting.") myautoadd=[] if myunadded: for x in range(len(myunadded)-1,-1,-1): @@ -1443,70 +1504,69 @@ else: if myautoadd: print ">>> Auto-Adding missing digests..." if "--pretend" in myoptions: - print "(cvs add "+string.join(myautoadd)+")" + if isCvs: + print "(cvs add "+string.join(myautoadd)+")" + if isSvn: + print "(svn add "+string.join(myautoadd)+")" retval=0 else: - retval=os.system("cvs add "+string.join(myautoadd)) + if isCvs: + retval=os.system("cvs add "+string.join(myautoadd)) + if isSvn: + retval=os.system("svn add "+string.join(myautoadd)) if retval: - print "!!! Exiting on cvs (shell) error code:",retval + print "!!! Exiting on vcs (shell) error code:",retval sys.exit(retval) if myunadded: - print red("!!! The following files are in your cvs tree but are not added to the master") - print red("!!! tree. Please remove them from the cvs tree or add them to the master tree.") + print red("!!! The following files are in your local tree but are not added to the master") + print red("!!! tree. Please remove them from the local tree or add them to the master tree.") for x in myunadded: print " ",x print print sys.exit(1) + + myheaders=[] + mychanged=[] + mydirty=[] + mynew=[] + myupdates=[] + myremoved=[] mymissing=None - if mymissing: - print "The following files are obviously missing from your cvs tree" - print "and are being fetched so we can continue:" - for x in mymissing: - print " ",x - if "--pretend" in myoptions: - print "(cvs -q up "+string.join(mymissing)+")" - retval=0 - else: - retval=os.system("cvs -q up "+string.join(mymissing)) - if retval: - print "!!! Exiting on cvs (shell) error code:",retval - sys.exit(retval) - del mymissing - - retval=["",""] if isCvs: + if mymissing: + print "The following files are obviously missing from your cvs tree" + print "and are being fetched so we can continue:" + for x in mymissing: + print " ",x + if "--pretend" in myoptions: + print "(cvs -q up "+string.join(mymissing)+")" + retval=0 + else: + retval=os.system("cvs -q up "+string.join(mymissing)) + if retval: + print "!!! Exiting on cvs (shell) error code:",retval + sys.exit(retval) + del mymissing + retval=["",""] print "Performing a "+green("cvs -n up")+" with a little magic grep to check for updates." - retval=getstatusoutput("cvs -n up 2>&1 | @EGREP@ '^[^\?] .*' | @EGREP@ -v '^. .*/digest-[^/]+|^cvs server: .* -- ignored$'") - - mylines=string.split(retval[1], "\n") - myupdates=[] - for x in mylines: - if not x: - continue - if x[0] not in "UPMAR": # Updates,Patches,Modified,Added,Removed - print red("!!! Please fix the following issues reported from cvs: ")+green("(U,P,M,A,R are ok)") - print red("!!! Note: This is a pretend/no-modify pass...") - print retval[1] - print - sys.exit(1) - elif x[0] in ["U","P"]: - myupdates+=[x[2:]] - - if myupdates: - print green("Fetching trivial updates...") - if "--pretend" in myoptions: - print "(cvs up "+string.join(myupdates)+")" - retval=0 - else: - retval=os.system("cvs up "+string.join(myupdates)) - if retval!=0: - print "!!! cvs exited with an error. Terminating." - sys.exit(retval) + retval=getstatusoutput("cvs -n up 2>&1 | "+portage_const.PREFIX+"/bin/grep -E '^[^\?] .*' | "+portage_const.PREFIX+"/bin/grep -E -v '^. .*/digest-[^/]+|^cvs server: .* -- ignored$'") + mylines=string.split(retval[1], "\n") + + for x in mylines: + if not x: + continue + if x[0] not in "UPMAR": # Updates,Patches,Modified,Added,Removed + print red("!!! Please fix the following issues reported from cvs: ")+green("(U,P,M,A,R are ok)") + print red("!!! Note: This is a pretend/no-modify pass...") + print retval[1] + print + sys.exit(1) + elif x[0] in ["U","P"]: + myupdates+=[x[2:]] - if isCvs: mycvstree=cvstree.getentries("./",recursive=1) mychanged=cvstree.findchanged(mycvstree,recursive=1,basedir="./") mynew=cvstree.findnew(mycvstree,recursive=1,basedir="./") @@ -1518,32 +1578,90 @@ else: print "(Didn't find any changed files...)" print sys.exit(0) + if myupdates: + print green("Fetching trivial updates...") + if "--pretend" in myoptions: + print "(cvs up "+string.join(myupdates)+")" + retval=0 + else: + retval=os.system("cvs up "+string.join(myupdates)) + if retval!=0: + print "!!! cvs exited with an error. Terminating." + sys.exit(retval) + myupdates=mychanged+mynew + headerstring="'\$(Header|Id)" + headerstring+=".*\$'" + for myfile in myupdates: + myout=getstatusoutput(portage_const.PREFIX+"/bin/grep -E -q "+headerstring+" "+myfile) + if myout[0]==0: + myheaders.append(myfile) + + print "*",green(str(len(myupdates))),"files being committed...",green(str(len(myheaders))),"have headers that will change." + print "*","Files with headers will cause the manifests to be made and recommited." + print "myupdates:",myupdates + print "myheaders:",myheaders + print + unlinkfile=0 + + # TODO svn check for UPMAR + if isSvn: + + myconflicts=[] + print "Checking "+green("svn -u status")+" to check for updates." + mylines=[ elem.strip().split() for elem in getstatusoutput("svn -u status")[1].split("\n") ][:-1] + if not mylines: + print green("Repoman sez:"), "\n\"Yeah....You want me to do nothing? Very Zen.\"\n" + print "(Didn't find any changed files...)\n" + sys.exit(0) + for x in mylines: + print x[0] + if x[0] not in "ADM!*": + myconflicts.append(x[0]+" "+x[-1]) + elif x[0] in "*!": + myupdates+=x[-1] + elif x[0]=="A": + mynew+=x[-1] + elif x[0]=="D": + print x[-1] + myremoved.append(x[2]) + elif x[0]=="M": + print x[-1] + mychanged.append(x[-1]) + if myconflicts: + print red("!!! Please fix the following issues reported from svn: ")+green("type `svn help status` for help") + print red("!!! Note: No files have been modified.") + for x in myconflicts: + print red(x) + sys.exit(1) + if myupdates: + print green("Fetching trivial updates...") + if "--pretend" in myoptions: + print "(svn -u status "+string.join(myupdates)+")" + retval=0 + else: + retval=os.system("svn up "+string.join(myupdates)) + if reval!=0: + print red("!!! svn error. Terminating.") + sys.exit(retval) + myupdates=mychanged+mynew+myremoved + if myremoved: + print "*",red(str(len(myremoved))),"file(s) being removed..." + if mynew: + print "*",green(str(len(mynew))),"file(s) being added..." + if mychanged: + print "*",green(str(len(mychanged))),"modified..." + print "*",green(str(len(myupdates))),"file(s) total being committed..." + print "myupdates:",myupdates - myupdates=mychanged+mynew - myheaders=[] - mydirty=[] - headerstring="'\$(Header|Id)" - headerstring+=".*\$'" - for myfile in myupdates: - myout=getstatusoutput("@EGREP@ -q "+headerstring+" "+myfile) - if myout[0]==0: - myheaders.append(myfile) - - print "*",green(str(len(myupdates))),"files being committed...",green(str(len(myheaders))),"have headers that will change." - print "*","Files with headers will cause the manifests to be made and recommited." - print "myupdates:",myupdates - print "myheaders:",myheaders - print - unlinkfile=0 if not (commitmessage or commitmessagefile): - print "Please enter a CVS commit message at the prompt:" + print "Please enter a commit message at the prompt:" while not commitmessage: try: commitmessage=raw_input(green("> ")) except KeyboardInterrupt: exithandler() try: - commitmessage+="\n(Portage version: "+str(portage.VERSION)+")" + commitmessage+="\n(Portage version: "+str(portage.VERSION)+"-prefix)" except: print "Failed to insert portage version in message!" commitmessage+="\n(Portage version: Unknown)" @@ -1564,12 +1682,18 @@ else: print if "--pretend" in myoptions: - print "(cvs -q commit -F "+commitmessagefile+")" + if isCvs: + print "(cvs -q commit -F "+commitmessagefile+")" + if isSvn: + print "(svn -q commit -F "+commitmessagefile+")" retval=0 else: - retval=os.system("cvs -q commit -F "+commitmessagefile) + if isCvs: + retval=os.system("cvs -q commit -F "+commitmessagefile) + if isSvn: + retval=os.system("svn -q commit -F "+commitmessagefile) if retval: - print "!!! Exiting on cvs (shell) error code:",retval + print "!!! Exiting on vcs (shell) error code:",retval sys.exit(retval) # Setup the GPG commands @@ -1620,13 +1744,19 @@ else: sys.exit(1) if "--pretend" in myoptions: - print "(cvs -q commit -F "+commitmessagefile+")" + if isCvs: + print "(cvs -q commit -F "+commitmessagefile+")" + if isSvn: + print "(svn -q commit -F "+commitmessagefile+")" else: mymsg=open(commitmessagefile,"w") mymsg.write(commitmessage) mymsg.write("\n (Unsigned Manifest commit)") mymsg.close() - retval=os.system("cvs -q commit -F "+commitmessagefile) + if isCvs: + retval=os.system("cvs -q commit -F "+commitmessagefile) + if isSvn: + retval=os.system("svn -q commit -F "+commitmessagefile) if retval: print "!!! Exiting on cvs (shell) error code:",retval sys.exit(retval) @@ -1668,24 +1798,30 @@ else: time.sleep(3) if "--pretend" in myoptions: - print "(cvs -q commit -F "+commitmessagefile+")" + if isCvs: + print "(cvs -q commit -F "+commitmessagefile+")" + if isSvn: + print "(svn -q commit -F "+commitmessagefile+")" else: mymsg=open(commitmessagefile,"w") mymsg.write(commitmessage) mymsg.write("\n (Signed Manifest commit)") mymsg.close() - retval=os.system("cvs -q commit -F "+commitmessagefile) + if isCvs: + retval=os.system("cvs -q commit -F "+commitmessagefile) + if isSvn: + retval=os.system("svn -q commit -F "+commitmessagefile) if retval: - print "!!! Exiting on cvs (shell) error code:",retval + print "!!! Exiting on vcs (shell) error code:",retval sys.exit(retval) if unlinkfile: os.unlink(commitmessagefile) print - if isCvs: - print "CVS commit complete." + if isCvs or isSvn: + print "Commit complete." else: - print "repoman was too scared by not seeing any familiar cvs file that he forgot to commit anything" + print "repoman was too scared by not seeing any familiar version control file that he forgot to commit anything" print green("RepoMan sez:"), "\"If everyone were like you, I'd be out of business!\"\n" sys.exit(0) -- 2.26.2