1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
|
#!/usr/bin/env python
# Global Modules
from subprocess import *
import sys
import re
import os
# from configobj
from configobj import ConfigObj
from validate import Validator
# To access the specfile:
from pkg_resources import resource_filename
from tatt.gentooPackage import gentooPackage as gP
from tatt.packageFinder import *
from tatt.scriptwriter import writeusecombiscript as writeUSE
from tatt.scriptwriter import writerdepscript as writeRdeps
from tatt.scriptwriter import writesucessreportscript as writeSuccess
from tatt.scriptwriter import writecommitscript as writeCommit
########### Generate a global config obj, reading from ~/.tatt ################
# resource_filename will give us platform-independent access to the specfile
specfile = resource_filename('tatt', 'dot-tatt-spec')
# Read the config from ~/.tatt
config = ConfigObj(os.path.join(os.path.expanduser("~"), ".tatt"), configspec=specfile)
# this validator will also do type conversion according to the spec file!
validator = Validator()
result = config.validate(validator)
if result != True:
print('Config file validation failed!')
sys.exit(1)
######### Main program starts here ###############
### USAGE and OPTIONS ###
from optparse import OptionParser
parser=OptionParser()
parser.add_option("-d", "--depend",
help="Determine stable rdeps",
dest="depend",
action="store_true",
default = False)
parser.add_option("-u", "--use", "--usecombis",
help="Determine use flag combinations",
dest="usecombi",
action="store_true",
default = False)
parser.add_option("-f", "--file",
help="Input File containing packages",
dest="infile",
action="store"
)
# parser.add_option("-t", "--test",
# help="run emerge commands with FEATURES=\"test\"",
# dest="feature_test",
# action="store_true",
# default = True)
parser.add_option("-j", "--jobname",
help="name for the job, prefix of output files",
dest="jobname",
action="store")
parser.add_option("-b", "--bug",
help="do the full program for a given stable request bug",
dest="bugnum",
action="store")
parser.add_option("-s", "--success",
help="Comment that the program was successfully tested",
dest="succbugnum",
action="store")
parser.add_option("-r", "--resolve",
help="Resolve the given bugnumber, needs a message",
dest="resolvenum",
action="store")
parser.add_option("-c", "--close",
help="Resolve the given bugnumber with closing it, needs to be combined with -r",
dest="close",
action="store_true")
parser.add_option("-m", "--message",
help="Message for bug resolution.",
dest="resolvemessage",
action="store")
(options,args) = parser.parse_args()
if (Popen(['whoami'], stdout=PIPE).communicate()[0].rstrip() == 'root'):
isroot=True
else:
print("You're not root!")
isroot=False
## -s and a bugnumber was given ?
if options.succbugnum:
print("Reporting success for bug number " + options.succbugnum)
retcode = call(['bugz', 'modify', options.succbugnum, '-c', config['successmessage']])
if retcode == 0:
print("Success!");
exit (0)
else:
print("Failure commenting on Bugzilla")
exit(1)
# Will eventuall contain packages to handle:
packs=None
## If -f and a filename have been given:
if options.infile:
try:
packfile=open(options.infile, 'r')
except IOError:
print("Given filename not found !")
exit(1)
packraw = packfile.read()
packfile.close()
packs = 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 = findPackages(bugraw, re.compile(config['atom-regexp']))
# joint code for -f and -b
##########################
if not packs==None:
## Assigning jobname
if options.jobname:
jobname = options.jobname
elif options.infile:
jobname = options.infile
else:
jobname = packs[0].packageName()
print ("Jobname: " + jobname)
for p in packs:
print("Found the following package atom : " + p.packageString())
# Unmasking:
if isroot:
# If we are root, then we can write to package.keywords
try:
keywordfile=open("/etc/portage/package.keywords/arch", 'r+')
except IOError:
# create an empty file, this should be beautified
keywordfile=open("/etc/portage/package.keywords/arch", 'w')
keywordfile.write(" ")
keywordfile.close()
keywordfile=open("/etc/portage/package.keywords/arch", 'r+')
keywordfilecontent = keywordfile.read()
for p in packs:
# Test if keywordfile already contains the atom
if re.search(p.packageString(), keywordfilecontent):
print (p.packageString() + " already in package.keywords.")
else:
keywordfile.write("\n" + p.packageString() + "\n")
print ("Appended " + p.packageString()+ " to /etc/portage/package.keywords/arch")
keywordfile.close()
else:
print ("You are not root, your unmaskstring would be:")
print ("\n".join([p.packageString() for p in packs]) + "\n")
## Write the scripts
writeUSE(jobname, packs, config)
writeRdeps(jobname, packs, config)
## Config and Successscript can only be written if we have a bugnumber
if options.bugnum:
writeSuccess(jobname, options.bugnum, config["successmessage"])
writeCommit(jobname, options.bugnum, packs, config)
exit (0)
# Code for resolving bugs (-r and -m)
#####################################
if options.resolvenum:
if not options.resolvemessage:
print("Please call with a message per -m")
exit (1)
print("Resolving bug number " + options.resolvenum)
calllist = ['bugz', 'modify', options.resolvenum, '-c', options.resolvemessage, '--remove-cc', config['arch']+"@gentoo.org"]
if options.close:
calllist = calllist + ['--fixed']
retcode = call(calllist)
if retcode == 0:
print("Success!");
exit (0)
else:
print("Failure accessing bugzilla.")
exit(1)
## If we arrive here then a package atom should be given
try:
pack = gP(args[0])
except IndexError:
print("Please call with package atom as argument")
exit (1)
if options.depend:
writeRdeps(pack.packageName(), [pack])
if options.usecombi:
writeUSE(pack.packageName(), [pack], config["ignoreprefix"])
## That's all folks ##
|