9 |
import urlparse |
import urlparse |
10 |
import argparse |
import argparse |
11 |
import errno |
import errno |
12 |
|
import tempfile |
13 |
|
import shutil |
14 |
from sgmllib import SGMLParser |
from sgmllib import SGMLParser |
15 |
|
|
16 |
MEDIA="Core Release Source" |
MEDIA="Core Release Source" |
24 |
else: |
else: |
25 |
yield line |
yield line |
26 |
|
|
27 |
|
def call_editor(filename): |
28 |
|
"""Return a sequence of possible editor binaries for the current platform""" |
29 |
|
|
30 |
|
editors = [] |
31 |
|
|
32 |
|
for varname in 'VISUAL', 'EDITOR': |
33 |
|
if varname in os.environ: |
34 |
|
editors.append(os.environ[varname]) |
35 |
|
|
36 |
|
editors.extend(('/usr/bin/editor', 'vi', 'pico', 'nano', 'joe')) |
37 |
|
|
38 |
|
for editor in editors: |
39 |
|
try: |
40 |
|
ret = subprocess.call([editor, filename]) |
41 |
|
except OSError, e: |
42 |
|
if e.errno == 2: |
43 |
|
continue |
44 |
|
raise |
45 |
|
|
46 |
|
if ret == 127: |
47 |
|
continue |
48 |
|
|
49 |
|
return True |
50 |
|
|
51 |
class urllister(SGMLParser): |
class urllister(SGMLParser): |
52 |
def reset(self): |
def reset(self): |
53 |
SGMLParser.reset(self) |
SGMLParser.reset(self) |
73 |
return self.path if self.show_path else os.path.basename(self.path) |
return self.path if self.show_path else os.path.basename(self.path) |
74 |
|
|
75 |
def add_dep3(self): |
def add_dep3(self): |
76 |
pass |
"""Add DEP-3 headers to a patch file""" |
77 |
|
if self.dep3['valid']: |
78 |
|
return False |
79 |
|
|
80 |
|
new_headers = ( |
81 |
|
('Author', self.svn_author), |
82 |
|
('Subject', ''), |
83 |
|
('Applied-Upstream', ''), |
84 |
|
('Forwarded', ''), |
85 |
|
('Bug', ''), |
86 |
|
) |
87 |
|
|
88 |
|
with tempfile.NamedTemporaryFile(dir=os.path.dirname(self.path), delete=False) as fdst: |
89 |
|
with open(self.path, "r") as fsrc: |
90 |
|
# Start with any existing DEP3 headers |
91 |
|
for i in range(self.dep3['last_nr']): |
92 |
|
fdst.write(fsrc.read()) |
93 |
|
|
94 |
|
# After that add the DEP3 headers |
95 |
|
add_line = False |
96 |
|
for header, data in new_headers: |
97 |
|
if header in self.dep3['headers']: |
98 |
|
continue |
99 |
|
|
100 |
|
# XXX - wrap this at 80 chars |
101 |
|
add_line = True |
102 |
|
print >>fdst, "%s: %s" % (header, "" if data is None else data) |
103 |
|
|
104 |
|
if add_line: print >>fdst, "" |
105 |
|
# Now copy any other data and the patch |
106 |
|
shutil.copyfileobj(fsrc, fdst) |
107 |
|
|
108 |
|
fdst.flush() |
109 |
|
os.rename(fdst.name, self.path) |
110 |
|
|
111 |
|
call_editor(self.path) |
112 |
|
|
113 |
#Author: fwang |
#Author: fwang |
114 |
#Subject: Build fix: Fix glib header inclusion |
#Subject: Build fix: Fix glib header inclusion |
115 |
#Applied-Upstream: commit:30602 |
#Applied-Upstream: commit:30602 |
117 |
#Bug: http://bugzilla.abisource.com/show_bug.cgi?id=13247 |
#Bug: http://bugzilla.abisource.com/show_bug.cgi?id=13247 |
118 |
|
|
119 |
def _read_dep3(self): |
def _read_dep3(self): |
120 |
"""This will also parse git headers""" |
"""Read DEP-3 headers from an existing patch file |
121 |
|
|
122 |
|
This will also parse git headers""" |
123 |
dep3 = {} |
dep3 = {} |
124 |
|
headers = {} |
125 |
|
|
126 |
last_header = None |
last_header = None |
127 |
|
last_nr = 0 |
128 |
|
nr = 0 |
129 |
try: |
try: |
130 |
with open(self.path, "r") as f: |
with open(self.path, "r") as f: |
131 |
for line in line_input(f): |
for line in line_input(f): |
132 |
# Check for start of real patch |
nr += 1 |
133 |
|
# stop trying to parse when real patch begins |
134 |
if line == '---': |
if line == '---': |
135 |
break |
break |
136 |
|
|
137 |
r = self.re_dep3.match(line) |
r = self.re_dep3.match(line) |
138 |
if r: |
if r: |
139 |
info = r.groupdict() |
info = r.groupdict() |
140 |
dep3[info['header']] = info['data'] |
headers[info['header']] = info['data'] |
141 |
last_header = info['header'] |
last_header = info['header'] |
142 |
|
last_nr = nr |
143 |
continue |
continue |
144 |
|
|
145 |
r = self.re_dep3_cont.match(line) |
r = self.re_dep3_cont.match(line) |
146 |
if r: |
if r: |
147 |
info = r.groupdict() |
info = r.groupdict() |
148 |
if last_header: |
if last_header: |
149 |
dep3[last_header] = " ".join((dep3[last_header], info['data'])) |
headers[last_header] = " ".join((headers[last_header], info['data'])) |
150 |
|
last_nr = nr |
151 |
continue |
continue |
152 |
|
|
153 |
last_header = None |
last_header = None |
154 |
except IOError: |
except IOError: |
155 |
pass |
pass |
156 |
|
|
157 |
|
dep3['valid'] = \ |
158 |
|
(('Description' in headers and headers['Description'].strip() != '') |
159 |
|
or ('Subject' in headers and headers['Subject'].strip() != '')) \ |
160 |
|
and (('Origin' in headers and headers['Origin'].strip() != '') \ |
161 |
|
or ('Author' in headers and headers['Author'].strip() != '') \ |
162 |
|
or ('From' in headers and headers['From'].strip() != '')) |
163 |
|
dep3['last_nr'] = last_nr |
164 |
|
dep3['headers'] = headers |
165 |
|
|
166 |
self._dep3 = dep3 |
self._dep3 = dep3 |
167 |
|
|
168 |
@property |
@property |
172 |
|
|
173 |
return self._dep3 |
return self._dep3 |
174 |
|
|
175 |
|
@property |
176 |
|
def svn_author(self): |
177 |
|
if not hasattr(self, '_svn_author'): |
178 |
|
p = subprocess.Popen(['svn', 'log', '-q', "--", self.path], stdout=subprocess.PIPE, close_fds=True) |
179 |
|
contents = p.stdout.read().strip("\n").splitlines() |
180 |
|
ecode = p.wait() |
181 |
|
if ecode == 0: |
182 |
|
for line in contents: |
183 |
|
if ' | ' not in line: |
184 |
|
continue |
185 |
|
|
186 |
|
fields = line.split(' | ') |
187 |
|
if len(fields) >= 3: |
188 |
|
self._svn_author = fields[1] |
189 |
|
|
190 |
|
if not hasattr(self, '_svn_author'): |
191 |
|
return None |
192 |
|
|
193 |
|
return self._svn_author |
194 |
|
|
195 |
def get_upstream_names(): |
def get_upstream_names(): |
196 |
urlopen = urllib2.build_opener() |
urlopen = urllib2.build_opener() |
279 |
if '.patch' in filename or '.diff' in filename: |
if '.patch' in filename or '.diff' in filename: |
280 |
p = Patch(os.path.join(path, srpm, "SOURCES", filename), show_path=options.path) |
p = Patch(os.path.join(path, srpm, "SOURCES", filename), show_path=options.path) |
281 |
print "\t".join((module, srpm, str(p))) |
print "\t".join((module, srpm, str(p))) |
282 |
if p.dep3: |
if p.dep3['headers']: |
283 |
pprint.pprint(p.dep3) |
pprint.pprint(p.dep3['headers']) |
284 |
|
if p.dep3['valid']: |
285 |
|
print "VALID" |
286 |
|
|
287 |
|
def cmd_dep3(options, parser): |
288 |
|
p = Patch(options.patch) |
289 |
|
p.add_dep3() |
290 |
|
|
291 |
def main(): |
def main(): |
292 |
description = """Mageia GNOME commands.""" |
description = """Mageia GNOME commands.""" |
308 |
|
|
309 |
subparser = subparsers.add_parser('patches', help='list all GNOME patches') |
subparser = subparsers.add_parser('patches', help='list all GNOME patches') |
310 |
subparser.add_argument("-p", "--path", action="store_true", dest="path", |
subparser.add_argument("-p", "--path", action="store_true", dest="path", |
311 |
help="Full path to patch") |
help="Show full path to patch") |
312 |
subparser.set_defaults( |
subparser.set_defaults( |
313 |
func=cmd_patches, path=False |
func=cmd_patches, path=False |
314 |
) |
) |
315 |
|
|
316 |
|
subparser = subparsers.add_parser('dep3', help='Add dep3 headers') |
317 |
|
subparser.add_argument("patch", help="Patch") |
318 |
|
subparser.set_defaults( |
319 |
|
func=cmd_dep3, path=False |
320 |
|
) |
321 |
|
|
322 |
if len(sys.argv) == 1: |
if len(sys.argv) == 1: |
323 |
parser.print_help() |
parser.print_help() |