Permalink
Browse files

Initial support for keywording bugs (also via -b)

  • Loading branch information...
1 parent 355f9b1 commit 1a6a5103526b8eba5869ecbb3a2fc86188f29345 @tom111 committed Feb 4, 2012
Showing with 129 additions and 73 deletions.
  1. +57 −31 scripts/tatt
  2. +8 −6 tatt/bugbrowser.py
  3. +20 −0 tatt/job.py
  4. +41 −33 tatt/scriptwriter.py
  5. +2 −2 templates/commit-snippet
  6. +1 −1 templates/commit-snippet-2
View
88 scripts/tatt
@@ -15,6 +15,7 @@ from tatt.scriptwriter import writecommitscript as writeCommit
from tatt.scriptwriter import writeCleanUpScript as writeCleanup
from tatt.bugbrowser import launch_browser as launch_browser
from tatt.tattConfig import tattConfig as tattConfig
+from tatt.job import job as job
##### Generate a global config obj, reading from ~/.tatt #####
config = tattConfig()
@@ -77,8 +78,12 @@ parser.add_option("-o", "--overview" "--browse",
(options,args) = parser.parse_args()
-# We copy some options to the config
+## Messing with the configuration:
+# Save verbosity level
config['verbose']=options.verbose
+# Normalize the template dir:
+config['template-dir']=os.path.abspath(config['template-dir'])+os.sep
+
## Checking for root, tatt should be run as a user, I guess.
## Remove on occasion.
@@ -104,8 +109,8 @@ if options.bugbrowser:
launch_browser (config)
exit (0)
-# Will eventuall contain packages to handle:
-packs=None
+# get a job object to save things to
+myJob = job()
## If -f and a filename have been given:
if options.infile:
@@ -116,34 +121,47 @@ if options.infile:
exit(1)
packraw = packfile.read()
packfile.close()
- packs = packageFinder.findPackages(packraw, re.compile(config['atom-regexp']))
+ myJob.packageList = packageFinder.findPackages(packraw, re.compile(config['atom-regexp']))
## -b and a bugnumber was given ?
if options.bugnum:
print("Bugnumber: " + options.bugnum)
- # If packs is still empty we search in the bug-title
- if packs==None:
- p1 = Popen(['bugz', 'get', options.bugnum, '-n'], stdout=PIPE)
- bugraw = Popen(['grep', 'Title'], stdin=p1.stdout, stdout=PIPE).communicate()[0]
- if not re.search('[Ss][Tt][Aa][Bb]', bugraw):
- print("Does not look like a stable request bug !")
- print(bugraw)
- packs = packageFinder.findPackages(bugraw, re.compile(config['atom-regexp']))
+ myJob.bugnumber=options.bugnum
+ # If myJob.packageList is still empty we search in the bug-title
+ if myJob.packageList==None:
+ p1 = Popen(['bugz', 'get', myJob.bugnumber, '-n'], stdout=PIPE)
+ #This old call would just fetch the title
+ #bugraw = Popen(['grep', 'Title'], stdin=p1.stdout, stdout=PIPE).communicate()[0]
+ # Instead we now capture everything:
+ bugraw = p1.communicate()[0]
+ if re.search('KEYWORDREQ', bugraw):
+ # This is a keywording bug:
+ print ("Keywording bug detected.")
+ myJob.type="keyword"
+ elif re.search('STABLEREQ', bugraw):
+ # Stablebug
+ print ("Stabilization bug detected.")
+ myJob.type="stable"
+ else:
+ print ("Could not detect bug's type, is the 'Keywords' field set?")
+ exit(1)
+ myJob.packageList = packageFinder.findPackages(bugraw, re.compile(config['atom-regexp']))
# joint code for -f and -b
##########################
-if not packs==None:
+if not myJob.packageList==None:
## Assigning jobname
if options.jobname:
- jobname = options.jobname
+ myJob.name = options.jobname
elif options.infile:
- jobname = options.infile
+ myJob.name = options.infile
else:
- jobname = packs[0].packageName()
- print ("Jobname: " + jobname)
+ myJob.name = myJob.packageList[0].packageName()
+ print ("Jobname: " + myJob.name)
+ ## Determine jobtype
- for p in packs:
+ for p in myJob.packageList:
print("Found the following package atom : " + p.packageString())
# Unmasking:
@@ -159,25 +177,32 @@ if not packs==None:
unmaskfile=open(config['unmaskfile'], 'r+')
unmaskfileContent = unmaskfile.read()
- for p in packs:
+ for p in myJob.packageList:
# Test if unmaskfile already contains the atom
if re.search(p.packageString(), unmaskfileContent):
print (p.packageString() + " already in "+config['unmaskfile'])
else:
- unmaskfile.write("\n" + p.packageString() + "\n")
- print ("Appended " + p.packageString()+ " to "+config['unmaskfile'])
+ unmaskfile.write(p.packageString())
+ if myJob.type=="stable":
+ unmaskfile.write("\n")
+ elif myJob.type=="keyword":
+ unmaskfile.write(" ** \n")
+ else:
+ print ("Uh Oh, no job.type? Tell tomka@gentoo.org to fix this!")
+ unmaskfile.write("\n")
+ print ("Unmasked " + p.packageString()+ " in "+config['unmaskfile'])
unmaskfile.close()
else:
print ("You are not root, your unmaskstring would be:")
- print ("\n".join([p.packageString() for p in packs]) + "\n")
+ print ("\n".join([p.packageString() for p in myJob.packageList]) + "\n")
## Write the scripts
- writeUSE(jobname, packs, config)
- writeRdeps(jobname, packs, config)
- writeCleanup (jobname, config)
+ writeUSE(myJob, config)
+ writeRdeps(myJob, config)
+ writeCleanup (myJob, config)
## Config and Successscript can only be written if we have a bugnumber
- if options.bugnum:
- writeSuccess(jobname, options.bugnum, config)
- writeCommit(jobname, options.bugnum, packs, config)
+ if myJob.bugnumber:
+ writeSuccess(myJob, config)
+ writeCommit(myJob, config)
exit (0)
# Code for resolving bugs (-r and -m)
@@ -201,15 +226,16 @@ if options.resolvenum:
## If we arrive here then a package atom should be given
try:
- pack = gP(args[0])
+ myJob.packageList=gP(args[0])
+ myJob.name=myJob.packageList[0].packageName()
except IndexError:
print("Please call with package atom as argument")
exit (1)
if options.depend:
- writeRdeps(pack.packageName(), [pack])
+ writeRdeps(myJob, config)
if options.usecombi:
- writeUSE(pack.packageName(), [pack], config["ignoreprefix"])
+ writeUSE(myJob, config)
## That's all folks ##
View
14 tatt/bugbrowser.py
@@ -337,9 +337,11 @@ def launch_browser (config):
print "Writing stabilization list to %s" % config['unmaskfile']
for b in bug_queue.get_bugs():
- packages = [gP.gentooPackage(s) for s in b.cpvs()]
- jobname = packages[0].packageName()
- scripts.writeusecombiscript(jobname, packages, config)
- scripts.writerdepscript (jobname, packages, config)
- scripts.writecommitscript (jobname, str(b.id_number()), packages, config)
- scripts.writeCleanUpScript (jobname, config)
+ myJob=job();
+ myJob.packageList = [gP.gentooPackage(s) for s in b.cpvs()]
+ myJob.name = packages[0].packageName()
+ myJob.bugnumber=str(b.id_number())
+ scripts.writeusecombiscript(job, config)
+ scripts.writerdepscript (job, config)
+ scripts.writecommitscript (job, config)
+ scripts.writeCleanUpScript (job, config)
View
20 tatt/job.py
@@ -0,0 +1,20 @@
+"""Abstraction of a tatt job"""
+
+class job(object):
+ """A tatt job can have a
+ - bugnumber
+ - name
+ - type (either 'stable', 'keyword')
+ - list of packages
+ """
+
+ def __init__(self,
+ name="",
+ bugnumber=0,
+ type="stable",
+ packageList=None):
+ self.name=name
+ self.bugnumber=bugnumber
+ self.type=type
+ self.packageList=packageList
+
View
74 tatt/scriptwriter.py
@@ -29,23 +29,22 @@ def useCombiTestString(pack, config):
s = s + localsnippet
return s
-def writeusecombiscript(job, packlist, config):
- # job is a jobname
- # packlist is a list of packages
+def writeusecombiscript(job, config):
+ # job is a tatt job object
# config is a tatt configuration
try:
useheaderfile=open(config['template-dir'] + "use-header", 'r')
except IOError:
print("use-header not found in " + config['template-dir'])
exit(1)
- useheader=useheaderfile.read().replace("@@JOB@@", job)
- outfilename = (job + "-useflags.sh")
- reportname = (job + ".report")
+ useheader=useheaderfile.read().replace("@@JOB@@", job.name)
+ outfilename = (job.name + "-useflags.sh")
+ reportname = (job.name + ".report")
if os.path.isfile(outfilename):
print(("WARNING: Will overwrite " + outfilename))
outfile = open(outfilename, 'w')
outfile.write(useheader)
- for p in packlist:
+ for p in job.packageList:
outfile.write("# Code for " + p.packageCatName() + "\n")
outfile.write(useCombiTestString(p, config).replace("@@REPORTFILE@@",reportname))
outfile.close()
@@ -67,13 +66,13 @@ def rdepTestString(rdep, config):
snip = snip.replace("@@CPV@@", rdep[0] )
return snip
-def writerdepscript(job, packlist, config):
+def writerdepscript(job, config):
# Populate the list of rdeps
rdeps = []
- for p in packlist:
+ for p in job.packageList:
rdeps = rdeps + stablerdeps (p, config)
if len(rdeps) == 0:
- print("No stable rdeps for " + job)
+ print("No stable rdeps for " + job.name)
return
# If there are rdeps, write the script
@@ -82,9 +81,9 @@ def writerdepscript(job, packlist, config):
except IOError:
print("revdep-header not found in " + config['template-dir'])
exit(1)
- rdepheader=rdepheaderfile.read().replace("@@JOB@@", job)
- outfilename = (job + "-rdeps.sh")
- reportname = (job + ".report")
+ rdepheader=rdepheaderfile.read().replace("@@JOB@@", job.name)
+ outfilename = (job.name + "-rdeps.sh")
+ reportname = (job.name + ".report")
if os.path.isfile(outfilename):
print(("WARNING: Will overwrite " + outfilename))
outfile = open(outfilename,'w')
@@ -98,23 +97,23 @@ def writerdepscript(job, packlist, config):
#######Write report script############
-def writesucessreportscript (job, bugnum, config):
- outfilename = (job + "-success.sh")
- reportname = (job + ".report")
+def writesucessreportscript (job, config):
+ outfilename = (job.name + "-success.sh")
+ reportname = (job.name + ".report")
if os.path.isfile(outfilename):
print(("WARNING: Will overwrite " + outfilename))
outfile = open(outfilename,'w')
outfile.write("#!/bin/sh" + '\n')
outfile.write("if grep failed " + reportname + " >> /dev/null; then echo Failure found;\n")
succmess = config['successmessage'].replace("@@ARCH@@", config['arch'])
- outfile.write("else bugz modify " + bugnum + ' -c' + "\"" + succmess + "\";\n")
+ outfile.write("else bugz modify " + job.bugnumber + ' -c' + "\"" + succmess + "\";\n")
outfile.write("fi;")
outfile.close()
print(("Success Report script written to " + outfilename))
####### Write the commit script #########
-def writecommitscript (job, bugnum, packlist, config):
+def writecommitscript (job, config):
try:
commitheaderfile=open(config['template-dir'] + "commit-header", 'r')
commitsnippetfile=open(config['template-dir'] + "commit-snippet", 'r')
@@ -123,31 +122,40 @@ def writecommitscript (job, bugnum, packlist, config):
except IOError:
print("Some commit template not found in " + config['template-dir'])
exit(1)
- csnippet = commitsnippetfile.read().replace("@@JOB@@", job)
- csnippet2 = commitsnippetfile2.read().replace("@@JOB@@", job)
- outfilename = (job + "-commit.sh")
+ csnippet = commitsnippetfile.read().replace("@@JOB@@", job.name)
+ csnippet2 = commitsnippetfile2.read().replace("@@JOB@@", job.name)
+ outfilename = (job.name + "-commit.sh")
if os.path.isfile(outfilename):
print(("WARNING: Will overwrite " + outfilename))
outfile = open(outfilename,'w')
- cheader = commitheaderfile.read().replace("@@JOB@@", job)
- cheader = cheader.replace(@@REPODIR@@, config['repodir'])
+ cheader = commitheaderfile.read().replace("@@JOB@@", job.name)
+ cheader = cheader.replace("@@REPODIR@@", config['repodir'])
outfile.write (cheader)
# First round (ekeyword)
- for pack in packlist:
- s = csnippet.replace("@@BUG@@", bugnum)
+ for pack in job.packageList:
+ s = csnippet.replace("@@BUG@@", job.bugnumber)
s = s.replace("@@ARCH@@", config['arch'])
+ if job.type=="stable":
+ newkeyword=config['arch']
+ elif job.type=="keyword":
+ newkeyword="~"+config['arch']
+ else:
+ print "No job type? Can't continue. This is a bug"
+ exit(1)
+ s = s.replace("@@NEWKEYWORD@@", newkeyword)
s = s.replace("@@EBUILD@@", pack.packageName()+"-"+pack.packageVersion()+".ebuild")
s = s.replace("@@CP@@", pack.packageCatName())
outfile.write(s)
# Second round (repoman -d full checks)
- for pack in packlist:
- s = csnippet2.replace("@@BUG@@", bugnum)
+ for pack in job.packageList:
+ s = csnippet2.replace("@@BUG@@", job.bugnumber)
s = s.replace("@@ARCH@@", config['arch'])
+ s = s.replace("@@NEWKEYWORD@@", newkeyword)
s = s.replace("@@EBUILD@@", pack.packageName()+"-"+pack.packageVersion()+".ebuild")
s = s.replace("@@CP@@", pack.packageCatName())
outfile.write(s)
# Footer (committing)
- outfile.write (commitfooterfile.read().replace("@@ARCH@@", config['arch']).replace("@@BUG@@", bugnum))
+ outfile.write (commitfooterfile.read().replace("@@ARCH@@", config['arch']).replace("@@BUG@@", job.bugnumber))
outfile.close()
print(("Commit script written to " + outfilename))
@@ -158,13 +166,13 @@ def writeCleanUpScript (job, config):
cleanUpTemplate=open(config['template-dir'] + "cleanup", 'r')
except IOError:
print("Clean-Up template not found in" + config['template-dir'])
- exit(1)
- script = cleanUpTemplate.read().replace("@@JOB@@", job)
- script = script.replace("@@CPV@@", job)
+ print "No clean-up script written"
+ return
+ script = cleanUpTemplate.read().replace("@@JOB@@", job.name)
+ script = script.replace("@@CPV@@", job.name)
script = script.replace("@@KEYWORDFILE@@", config['unmaskfile'])
- outfilename = (job + "-cleanup.sh")
+ outfilename = (job.name + "-cleanup.sh")
if os.path.isfile(outfilename):
print(("WARNING: Will overwrite " + outfilename))
outfile = open(outfilename,'w')
outfile.write(script)
-
View
4 templates/commit-snippet
@@ -1,8 +1,8 @@
# Code for keywording @@EBUILD@@
cd @@CP@@
-ekeyword @@ARCH@@ @@EBUILD@@
-echangelog "@@ARCH@@ stable per bug @@BUG@@" || {
+ekeyword @@NEWKEYWORD@@ @@EBUILD@@
+echangelog "marked @@NEWKEYWORD@@ per bug @@BUG@@" || {
echo " *** echangelog failed"
exit 1
}
View
2 templates/commit-snippet-2
@@ -2,7 +2,7 @@
cd @@CP@@
repoman -d full || exit 1
-repoman -m "@@ARCH@@ stable per bug @@BUG@@" commit || exit 1
+repoman -m "marked @@NEWKEYWORD@@ per bug @@BUG@@" commit || exit 1
cd ../..
## @@CP@@ done

0 comments on commit 1a6a510

Please sign in to comment.