8 |
import urllib2 |
import urllib2 |
9 |
import urlparse |
import urlparse |
10 |
import argparse |
import argparse |
11 |
|
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" |
17 |
URL="http://download.gnome.org/sources/" |
URL="http://download.gnome.org/sources/" |
18 |
PKGROOT='~/pkgs' |
PKGROOT='~/pkgs' |
19 |
|
|
20 |
|
def line_input (file): |
21 |
|
for line in file: |
22 |
|
if line[-1] == '\n': |
23 |
|
yield line[:-1] |
24 |
|
else: |
25 |
|
yield line |
26 |
|
|
27 |
class urllister(SGMLParser): |
class urllister(SGMLParser): |
28 |
def reset(self): |
def reset(self): |
29 |
SGMLParser.reset(self) |
SGMLParser.reset(self) |
34 |
if href: |
if href: |
35 |
self.urls.extend(href) |
self.urls.extend(href) |
36 |
|
|
37 |
|
class Patch(object): |
38 |
|
"""Do things with patches""" |
39 |
|
|
40 |
|
re_dep3 = re.compile(r'^(?:#\s*)?(?P<header>[-A-Za-z0-9]+?):\s*(?P<data>.*)$') |
41 |
|
re_dep3_cont = re.compile(r'^#?\s+(?P<data>.*)$') |
42 |
|
|
43 |
|
def __init__(self, path, show_path=False): |
44 |
|
"""Path: path to patch (might not exist)""" |
45 |
|
self.path = path |
46 |
|
self.show_path = show_path |
47 |
|
|
48 |
|
def __str__(self): |
49 |
|
return self.path if self.show_path else os.path.basename(self.path) |
50 |
|
|
51 |
|
def add_dep3(self): |
52 |
|
if self.dep3['valid']: |
53 |
|
return False |
54 |
|
|
55 |
|
new_headers = ( |
56 |
|
('Author', self.svn_author), |
57 |
|
('Subject', ''), |
58 |
|
('Applied-Upstream', ''), |
59 |
|
('Forwarded', ''), |
60 |
|
('Bug', ''), |
61 |
|
) |
62 |
|
|
63 |
|
with tempfile.NamedTemporaryFile(dir=os.path.dirname(self.path), delete=False) as fdst: |
64 |
|
with open(self.path, "r") as fsrc: |
65 |
|
# Start with any existing DEP3 headers |
66 |
|
for i in range(self.dep3['last_nr']): |
67 |
|
fdst.write(fsrc.read()) |
68 |
|
|
69 |
|
# After that add the DEP3 headers |
70 |
|
add_line = False |
71 |
|
for header, data in new_headers: |
72 |
|
if header in self.dep3['headers']: |
73 |
|
continue |
74 |
|
|
75 |
|
# XXX - wrap this at 80 chars |
76 |
|
add_line = True |
77 |
|
print >>fdst, "%s: %s" % (header, data) |
78 |
|
|
79 |
|
if add_line: print >>fdst, "" |
80 |
|
# Now copy any other data and the patch |
81 |
|
shutil.copyfileobj(fsrc, fdst) |
82 |
|
|
83 |
|
fdst.flush() |
84 |
|
os.rename(fdst.name, self.path) |
85 |
|
|
86 |
|
#Author: fwang |
87 |
|
#Subject: Build fix: Fix glib header inclusion |
88 |
|
#Applied-Upstream: commit:30602 |
89 |
|
#Forwarded: yes |
90 |
|
#Bug: http://bugzilla.abisource.com/show_bug.cgi?id=13247 |
91 |
|
|
92 |
|
def _read_dep3(self): |
93 |
|
"""This will also parse git headers""" |
94 |
|
dep3 = {} |
95 |
|
headers = {} |
96 |
|
|
97 |
|
last_header = None |
98 |
|
last_nr = 0 |
99 |
|
nr = 0 |
100 |
|
try: |
101 |
|
with open(self.path, "r") as f: |
102 |
|
for line in line_input(f): |
103 |
|
nr += 1 |
104 |
|
# stop trying to parse when real patch begins |
105 |
|
if line == '---': |
106 |
|
break |
107 |
|
|
108 |
|
r = self.re_dep3.match(line) |
109 |
|
if r: |
110 |
|
info = r.groupdict() |
111 |
|
headers[info['header']] = info['data'] |
112 |
|
last_header = info['header'] |
113 |
|
last_nr = nr |
114 |
|
continue |
115 |
|
|
116 |
|
r = self.re_dep3_cont.match(line) |
117 |
|
if r: |
118 |
|
info = r.groupdict() |
119 |
|
if last_header: |
120 |
|
headers[last_header] = " ".join((headers[last_header], info['data'])) |
121 |
|
last_nr = nr |
122 |
|
continue |
123 |
|
|
124 |
|
last_header = None |
125 |
|
except IOError: |
126 |
|
pass |
127 |
|
|
128 |
|
dep3['valid'] = \ |
129 |
|
(('Description' in headers and headers['Description'].strip() != '') |
130 |
|
or ('Subject' in headers and headers['Subject'].strip() != '')) \ |
131 |
|
and (('Origin' in headers and headers['Origin'].strip() != '') \ |
132 |
|
or ('Author' in headers and headers['Author'].strip() != '') \ |
133 |
|
or ('From' in headers and headers['From'].strip() != '')) |
134 |
|
dep3['last_nr'] = last_nr |
135 |
|
dep3['headers'] = headers |
136 |
|
|
137 |
|
self._dep3 = dep3 |
138 |
|
|
139 |
|
@property |
140 |
|
def dep3(self): |
141 |
|
if not hasattr(self, '_dep3'): |
142 |
|
self._read_dep3() |
143 |
|
|
144 |
|
return self._dep3 |
145 |
|
|
146 |
|
@property |
147 |
|
def svn_author(self): |
148 |
|
if not hasattr(self, '_svn_author'): |
149 |
|
p = subprocess.Popen(['svn', 'log', '-q', "--", self.path], stdout=subprocess.PIPE, close_fds=True) |
150 |
|
contents = p.stdout.read().strip("\n").splitlines() |
151 |
|
ecode = p.wait() |
152 |
|
if ecode == 0: |
153 |
|
for line in contents: |
154 |
|
if ' | ' not in line: |
155 |
|
continue |
156 |
|
|
157 |
|
fields = line.split(' | ') |
158 |
|
if len(fields) >= 3: |
159 |
|
self._svn_author = fields[1] |
160 |
|
|
161 |
|
return self._svn_author |
162 |
|
|
163 |
def get_upstream_names(): |
def get_upstream_names(): |
164 |
urlopen = urllib2.build_opener() |
urlopen = urllib2.build_opener() |
165 |
|
|
238 |
|
|
239 |
path = os.path.expanduser(PKGROOT) |
path = os.path.expanduser(PKGROOT) |
240 |
|
|
241 |
|
import pprint |
242 |
|
|
243 |
matches = upstream & set(downstream.keys()) |
matches = upstream & set(downstream.keys()) |
244 |
for module in sorted(matches): |
for module in sorted(matches): |
245 |
for srpm in downstream[module]: |
for srpm in downstream[module]: |
246 |
for filename in downstream_files[srpm]: |
for filename in downstream_files[srpm]: |
247 |
if '.patch' in filename or '.diff' in filename: |
if '.patch' in filename or '.diff' in filename: |
248 |
print "\t".join((module,srpm, os.path.join(path, srpm, "SOURCES", filename) if options.path else filename)) |
p = Patch(os.path.join(path, srpm, "SOURCES", filename), show_path=options.path) |
249 |
|
print "\t".join((module, srpm, str(p))) |
250 |
|
if p.dep3['headers']: |
251 |
|
pprint.pprint(p.dep3['headers']) |
252 |
|
if p.dep3['valid']: |
253 |
|
print "VALID" |
254 |
|
|
255 |
|
def cmd_dep3(options, parser): |
256 |
|
p = Patch(options.patch) |
257 |
|
p.add_dep3() |
258 |
|
|
259 |
def main(): |
def main(): |
260 |
description = """Mageia GNOME commands.""" |
description = """Mageia GNOME commands.""" |
276 |
|
|
277 |
subparser = subparsers.add_parser('patches', help='list all GNOME patches') |
subparser = subparsers.add_parser('patches', help='list all GNOME patches') |
278 |
subparser.add_argument("-p", "--path", action="store_true", dest="path", |
subparser.add_argument("-p", "--path", action="store_true", dest="path", |
279 |
help="Full path to patch") |
help="Show full path to patch") |
280 |
subparser.set_defaults( |
subparser.set_defaults( |
281 |
func=cmd_patches, path=False |
func=cmd_patches, path=False |
282 |
) |
) |
283 |
|
|
284 |
|
subparser = subparsers.add_parser('dep3', help='Add dep3 headers') |
285 |
|
subparser.add_argument("patch", help="Patch") |
286 |
|
subparser.set_defaults( |
287 |
|
func=cmd_dep3, path=False |
288 |
|
) |
289 |
|
|
290 |
if len(sys.argv) == 1: |
if len(sys.argv) == 1: |
291 |
parser.print_help() |
parser.print_help() |