Skip to content
This repository
Browse code

Initial support for keywording bugs (also via -b)

  • Loading branch information...
commit 1a6a5103526b8eba5869ecbb3a2fc86188f29345 1 parent 355f9b1
Thomas Kahle authored
88 scripts/tatt
@@ -15,6 +15,7 @@ from tatt.scriptwriter import writecommitscript as writeCommit
15 15 from tatt.scriptwriter import writeCleanUpScript as writeCleanup
16 16 from tatt.bugbrowser import launch_browser as launch_browser
17 17 from tatt.tattConfig import tattConfig as tattConfig
  18 +from tatt.job import job as job
18 19
19 20 ##### Generate a global config obj, reading from ~/.tatt #####
20 21 config = tattConfig()
@@ -77,8 +78,12 @@ parser.add_option("-o", "--overview" "--browse",
77 78
78 79 (options,args) = parser.parse_args()
79 80
80   -# We copy some options to the config
  81 +## Messing with the configuration:
  82 +# Save verbosity level
81 83 config['verbose']=options.verbose
  84 +# Normalize the template dir:
  85 +config['template-dir']=os.path.abspath(config['template-dir'])+os.sep
  86 +
82 87
83 88 ## Checking for root, tatt should be run as a user, I guess.
84 89 ## Remove on occasion.
@@ -104,8 +109,8 @@ if options.bugbrowser:
104 109 launch_browser (config)
105 110 exit (0)
106 111
107   -# Will eventuall contain packages to handle:
108   -packs=None
  112 +# get a job object to save things to
  113 +myJob = job()
109 114
110 115 ## If -f and a filename have been given:
111 116 if options.infile:
@@ -116,34 +121,47 @@ if options.infile:
116 121 exit(1)
117 122 packraw = packfile.read()
118 123 packfile.close()
119   - packs = packageFinder.findPackages(packraw, re.compile(config['atom-regexp']))
  124 + myJob.packageList = packageFinder.findPackages(packraw, re.compile(config['atom-regexp']))
120 125
121 126 ## -b and a bugnumber was given ?
122 127 if options.bugnum:
123 128 print("Bugnumber: " + options.bugnum)
124   - # If packs is still empty we search in the bug-title
125   - if packs==None:
126   - p1 = Popen(['bugz', 'get', options.bugnum, '-n'], stdout=PIPE)
127   - bugraw = Popen(['grep', 'Title'], stdin=p1.stdout, stdout=PIPE).communicate()[0]
128   - if not re.search('[Ss][Tt][Aa][Bb]', bugraw):
129   - print("Does not look like a stable request bug !")
130   - print(bugraw)
131   - packs = packageFinder.findPackages(bugraw, re.compile(config['atom-regexp']))
  129 + myJob.bugnumber=options.bugnum
  130 + # If myJob.packageList is still empty we search in the bug-title
  131 + if myJob.packageList==None:
  132 + p1 = Popen(['bugz', 'get', myJob.bugnumber, '-n'], stdout=PIPE)
  133 + #This old call would just fetch the title
  134 + #bugraw = Popen(['grep', 'Title'], stdin=p1.stdout, stdout=PIPE).communicate()[0]
  135 + # Instead we now capture everything:
  136 + bugraw = p1.communicate()[0]
  137 + if re.search('KEYWORDREQ', bugraw):
  138 + # This is a keywording bug:
  139 + print ("Keywording bug detected.")
  140 + myJob.type="keyword"
  141 + elif re.search('STABLEREQ', bugraw):
  142 + # Stablebug
  143 + print ("Stabilization bug detected.")
  144 + myJob.type="stable"
  145 + else:
  146 + print ("Could not detect bug's type, is the 'Keywords' field set?")
  147 + exit(1)
  148 + myJob.packageList = packageFinder.findPackages(bugraw, re.compile(config['atom-regexp']))
132 149
133 150 # joint code for -f and -b
134 151 ##########################
135 152
136   -if not packs==None:
  153 +if not myJob.packageList==None:
137 154 ## Assigning jobname
138 155 if options.jobname:
139   - jobname = options.jobname
  156 + myJob.name = options.jobname
140 157 elif options.infile:
141   - jobname = options.infile
  158 + myJob.name = options.infile
142 159 else:
143   - jobname = packs[0].packageName()
144   - print ("Jobname: " + jobname)
  160 + myJob.name = myJob.packageList[0].packageName()
  161 + print ("Jobname: " + myJob.name)
  162 + ## Determine jobtype
145 163
146   - for p in packs:
  164 + for p in myJob.packageList:
147 165 print("Found the following package atom : " + p.packageString())
148 166
149 167 # Unmasking:
@@ -159,25 +177,32 @@ if not packs==None:
159 177 unmaskfile=open(config['unmaskfile'], 'r+')
160 178
161 179 unmaskfileContent = unmaskfile.read()
162   - for p in packs:
  180 + for p in myJob.packageList:
163 181 # Test if unmaskfile already contains the atom
164 182 if re.search(p.packageString(), unmaskfileContent):
165 183 print (p.packageString() + " already in "+config['unmaskfile'])
166 184 else:
167   - unmaskfile.write("\n" + p.packageString() + "\n")
168   - print ("Appended " + p.packageString()+ " to "+config['unmaskfile'])
  185 + unmaskfile.write(p.packageString())
  186 + if myJob.type=="stable":
  187 + unmaskfile.write("\n")
  188 + elif myJob.type=="keyword":
  189 + unmaskfile.write(" ** \n")
  190 + else:
  191 + print ("Uh Oh, no job.type? Tell tomka@gentoo.org to fix this!")
  192 + unmaskfile.write("\n")
  193 + print ("Unmasked " + p.packageString()+ " in "+config['unmaskfile'])
169 194 unmaskfile.close()
170 195 else:
171 196 print ("You are not root, your unmaskstring would be:")
172   - print ("\n".join([p.packageString() for p in packs]) + "\n")
  197 + print ("\n".join([p.packageString() for p in myJob.packageList]) + "\n")
173 198 ## Write the scripts
174   - writeUSE(jobname, packs, config)
175   - writeRdeps(jobname, packs, config)
176   - writeCleanup (jobname, config)
  199 + writeUSE(myJob, config)
  200 + writeRdeps(myJob, config)
  201 + writeCleanup (myJob, config)
177 202 ## Config and Successscript can only be written if we have a bugnumber
178   - if options.bugnum:
179   - writeSuccess(jobname, options.bugnum, config)
180   - writeCommit(jobname, options.bugnum, packs, config)
  203 + if myJob.bugnumber:
  204 + writeSuccess(myJob, config)
  205 + writeCommit(myJob, config)
181 206 exit (0)
182 207
183 208 # Code for resolving bugs (-r and -m)
@@ -201,15 +226,16 @@ if options.resolvenum:
201 226
202 227 ## If we arrive here then a package atom should be given
203 228 try:
204   - pack = gP(args[0])
  229 + myJob.packageList=gP(args[0])
  230 + myJob.name=myJob.packageList[0].packageName()
205 231 except IndexError:
206 232 print("Please call with package atom as argument")
207 233 exit (1)
208 234
209 235 if options.depend:
210   - writeRdeps(pack.packageName(), [pack])
  236 + writeRdeps(myJob, config)
211 237
212 238 if options.usecombi:
213   - writeUSE(pack.packageName(), [pack], config["ignoreprefix"])
  239 + writeUSE(myJob, config)
214 240
215 241 ## That's all folks ##
14 tatt/bugbrowser.py
@@ -337,9 +337,11 @@ def launch_browser (config):
337 337 print "Writing stabilization list to %s" % config['unmaskfile']
338 338
339 339 for b in bug_queue.get_bugs():
340   - packages = [gP.gentooPackage(s) for s in b.cpvs()]
341   - jobname = packages[0].packageName()
342   - scripts.writeusecombiscript(jobname, packages, config)
343   - scripts.writerdepscript (jobname, packages, config)
344   - scripts.writecommitscript (jobname, str(b.id_number()), packages, config)
345   - scripts.writeCleanUpScript (jobname, config)
  340 + myJob=job();
  341 + myJob.packageList = [gP.gentooPackage(s) for s in b.cpvs()]
  342 + myJob.name = packages[0].packageName()
  343 + myJob.bugnumber=str(b.id_number())
  344 + scripts.writeusecombiscript(job, config)
  345 + scripts.writerdepscript (job, config)
  346 + scripts.writecommitscript (job, config)
  347 + scripts.writeCleanUpScript (job, config)
20 tatt/job.py
... ... @@ -0,0 +1,20 @@
  1 +"""Abstraction of a tatt job"""
  2 +
  3 +class job(object):
  4 + """A tatt job can have a
  5 + - bugnumber
  6 + - name
  7 + - type (either 'stable', 'keyword')
  8 + - list of packages
  9 + """
  10 +
  11 + def __init__(self,
  12 + name="",
  13 + bugnumber=0,
  14 + type="stable",
  15 + packageList=None):
  16 + self.name=name
  17 + self.bugnumber=bugnumber
  18 + self.type=type
  19 + self.packageList=packageList
  20 +
74 tatt/scriptwriter.py
@@ -29,23 +29,22 @@ def useCombiTestString(pack, config):
29 29 s = s + localsnippet
30 30 return s
31 31
32   -def writeusecombiscript(job, packlist, config):
33   - # job is a jobname
34   - # packlist is a list of packages
  32 +def writeusecombiscript(job, config):
  33 + # job is a tatt job object
35 34 # config is a tatt configuration
36 35 try:
37 36 useheaderfile=open(config['template-dir'] + "use-header", 'r')
38 37 except IOError:
39 38 print("use-header not found in " + config['template-dir'])
40 39 exit(1)
41   - useheader=useheaderfile.read().replace("@@JOB@@", job)
42   - outfilename = (job + "-useflags.sh")
43   - reportname = (job + ".report")
  40 + useheader=useheaderfile.read().replace("@@JOB@@", job.name)
  41 + outfilename = (job.name + "-useflags.sh")
  42 + reportname = (job.name + ".report")
44 43 if os.path.isfile(outfilename):
45 44 print(("WARNING: Will overwrite " + outfilename))
46 45 outfile = open(outfilename, 'w')
47 46 outfile.write(useheader)
48   - for p in packlist:
  47 + for p in job.packageList:
49 48 outfile.write("# Code for " + p.packageCatName() + "\n")
50 49 outfile.write(useCombiTestString(p, config).replace("@@REPORTFILE@@",reportname))
51 50 outfile.close()
@@ -67,13 +66,13 @@ def rdepTestString(rdep, config):
67 66 snip = snip.replace("@@CPV@@", rdep[0] )
68 67 return snip
69 68
70   -def writerdepscript(job, packlist, config):
  69 +def writerdepscript(job, config):
71 70 # Populate the list of rdeps
72 71 rdeps = []
73   - for p in packlist:
  72 + for p in job.packageList:
74 73 rdeps = rdeps + stablerdeps (p, config)
75 74 if len(rdeps) == 0:
76   - print("No stable rdeps for " + job)
  75 + print("No stable rdeps for " + job.name)
77 76 return
78 77
79 78 # If there are rdeps, write the script
@@ -82,9 +81,9 @@ def writerdepscript(job, packlist, config):
82 81 except IOError:
83 82 print("revdep-header not found in " + config['template-dir'])
84 83 exit(1)
85   - rdepheader=rdepheaderfile.read().replace("@@JOB@@", job)
86   - outfilename = (job + "-rdeps.sh")
87   - reportname = (job + ".report")
  84 + rdepheader=rdepheaderfile.read().replace("@@JOB@@", job.name)
  85 + outfilename = (job.name + "-rdeps.sh")
  86 + reportname = (job.name + ".report")
88 87 if os.path.isfile(outfilename):
89 88 print(("WARNING: Will overwrite " + outfilename))
90 89 outfile = open(outfilename,'w')
@@ -98,23 +97,23 @@ def writerdepscript(job, packlist, config):
98 97
99 98
100 99 #######Write report script############
101   -def writesucessreportscript (job, bugnum, config):
102   - outfilename = (job + "-success.sh")
103   - reportname = (job + ".report")
  100 +def writesucessreportscript (job, config):
  101 + outfilename = (job.name + "-success.sh")
  102 + reportname = (job.name + ".report")
104 103 if os.path.isfile(outfilename):
105 104 print(("WARNING: Will overwrite " + outfilename))
106 105 outfile = open(outfilename,'w')
107 106 outfile.write("#!/bin/sh" + '\n')
108 107 outfile.write("if grep failed " + reportname + " >> /dev/null; then echo Failure found;\n")
109 108 succmess = config['successmessage'].replace("@@ARCH@@", config['arch'])
110   - outfile.write("else bugz modify " + bugnum + ' -c' + "\"" + succmess + "\";\n")
  109 + outfile.write("else bugz modify " + job.bugnumber + ' -c' + "\"" + succmess + "\";\n")
111 110 outfile.write("fi;")
112 111 outfile.close()
113 112 print(("Success Report script written to " + outfilename))
114 113
115 114
116 115 ####### Write the commit script #########
117   -def writecommitscript (job, bugnum, packlist, config):
  116 +def writecommitscript (job, config):
118 117 try:
119 118 commitheaderfile=open(config['template-dir'] + "commit-header", 'r')
120 119 commitsnippetfile=open(config['template-dir'] + "commit-snippet", 'r')
@@ -123,31 +122,40 @@ def writecommitscript (job, bugnum, packlist, config):
123 122 except IOError:
124 123 print("Some commit template not found in " + config['template-dir'])
125 124 exit(1)
126   - csnippet = commitsnippetfile.read().replace("@@JOB@@", job)
127   - csnippet2 = commitsnippetfile2.read().replace("@@JOB@@", job)
128   - outfilename = (job + "-commit.sh")
  125 + csnippet = commitsnippetfile.read().replace("@@JOB@@", job.name)
  126 + csnippet2 = commitsnippetfile2.read().replace("@@JOB@@", job.name)
  127 + outfilename = (job.name + "-commit.sh")
129 128 if os.path.isfile(outfilename):
130 129 print(("WARNING: Will overwrite " + outfilename))
131 130 outfile = open(outfilename,'w')
132   - cheader = commitheaderfile.read().replace("@@JOB@@", job)
133   - cheader = cheader.replace(@@REPODIR@@, config['repodir'])
  131 + cheader = commitheaderfile.read().replace("@@JOB@@", job.name)
  132 + cheader = cheader.replace("@@REPODIR@@", config['repodir'])
134 133 outfile.write (cheader)
135 134 # First round (ekeyword)
136   - for pack in packlist:
137   - s = csnippet.replace("@@BUG@@", bugnum)
  135 + for pack in job.packageList:
  136 + s = csnippet.replace("@@BUG@@", job.bugnumber)
138 137 s = s.replace("@@ARCH@@", config['arch'])
  138 + if job.type=="stable":
  139 + newkeyword=config['arch']
  140 + elif job.type=="keyword":
  141 + newkeyword="~"+config['arch']
  142 + else:
  143 + print "No job type? Can't continue. This is a bug"
  144 + exit(1)
  145 + s = s.replace("@@NEWKEYWORD@@", newkeyword)
139 146 s = s.replace("@@EBUILD@@", pack.packageName()+"-"+pack.packageVersion()+".ebuild")
140 147 s = s.replace("@@CP@@", pack.packageCatName())
141 148 outfile.write(s)
142 149 # Second round (repoman -d full checks)
143   - for pack in packlist:
144   - s = csnippet2.replace("@@BUG@@", bugnum)
  150 + for pack in job.packageList:
  151 + s = csnippet2.replace("@@BUG@@", job.bugnumber)
145 152 s = s.replace("@@ARCH@@", config['arch'])
  153 + s = s.replace("@@NEWKEYWORD@@", newkeyword)
146 154 s = s.replace("@@EBUILD@@", pack.packageName()+"-"+pack.packageVersion()+".ebuild")
147 155 s = s.replace("@@CP@@", pack.packageCatName())
148 156 outfile.write(s)
149 157 # Footer (committing)
150   - outfile.write (commitfooterfile.read().replace("@@ARCH@@", config['arch']).replace("@@BUG@@", bugnum))
  158 + outfile.write (commitfooterfile.read().replace("@@ARCH@@", config['arch']).replace("@@BUG@@", job.bugnumber))
151 159 outfile.close()
152 160 print(("Commit script written to " + outfilename))
153 161
@@ -158,13 +166,13 @@ def writeCleanUpScript (job, config):
158 166 cleanUpTemplate=open(config['template-dir'] + "cleanup", 'r')
159 167 except IOError:
160 168 print("Clean-Up template not found in" + config['template-dir'])
161   - exit(1)
162   - script = cleanUpTemplate.read().replace("@@JOB@@", job)
163   - script = script.replace("@@CPV@@", job)
  169 + print "No clean-up script written"
  170 + return
  171 + script = cleanUpTemplate.read().replace("@@JOB@@", job.name)
  172 + script = script.replace("@@CPV@@", job.name)
164 173 script = script.replace("@@KEYWORDFILE@@", config['unmaskfile'])
165   - outfilename = (job + "-cleanup.sh")
  174 + outfilename = (job.name + "-cleanup.sh")
166 175 if os.path.isfile(outfilename):
167 176 print(("WARNING: Will overwrite " + outfilename))
168 177 outfile = open(outfilename,'w')
169 178 outfile.write(script)
170   -
4 templates/commit-snippet
... ... @@ -1,8 +1,8 @@
1 1 # Code for keywording @@EBUILD@@
2 2 cd @@CP@@
3 3
4   -ekeyword @@ARCH@@ @@EBUILD@@
5   -echangelog "@@ARCH@@ stable per bug @@BUG@@" || {
  4 +ekeyword @@NEWKEYWORD@@ @@EBUILD@@
  5 +echangelog "marked @@NEWKEYWORD@@ per bug @@BUG@@" || {
6 6 echo " *** echangelog failed"
7 7 exit 1
8 8 }
2  templates/commit-snippet-2
@@ -2,7 +2,7 @@
2 2 cd @@CP@@
3 3
4 4 repoman -d full || exit 1
5   -repoman -m "@@ARCH@@ stable per bug @@BUG@@" commit || exit 1
  5 +repoman -m "marked @@NEWKEYWORD@@ per bug @@BUG@@" commit || exit 1
6 6
7 7 cd ../..
8 8 ## @@CP@@ done

0 comments on commit 1a6a510

Please sign in to comment.
Something went wrong with that request. Please try again.