17 |
URL="http://download.gnome.org/sources/" |
URL="http://download.gnome.org/sources/" |
18 |
PKGROOT='~/pkgs' |
PKGROOT='~/pkgs' |
19 |
|
|
20 |
|
re_version = re.compile(r'([-.]|\d+|[^-.\d]+)') |
21 |
|
|
22 |
|
def version_cmp(a, b): |
23 |
|
"""Compares two versions |
24 |
|
|
25 |
|
Returns |
26 |
|
-1 if a < b |
27 |
|
0 if a == b |
28 |
|
1 if a > b |
29 |
|
|
30 |
|
Logic from Bugzilla::Install::Util::vers_cmp""" |
31 |
|
A = re_version.findall(a.lstrip('0')) |
32 |
|
B = re_version.findall(b.lstrip('0')) |
33 |
|
|
34 |
|
while A and B: |
35 |
|
a = A.pop(0) |
36 |
|
b = B.pop(0) |
37 |
|
|
38 |
|
if a == b: |
39 |
|
continue |
40 |
|
elif a == '-': |
41 |
|
return -1 |
42 |
|
elif b == '-': |
43 |
|
return 1 |
44 |
|
elif a == '.': |
45 |
|
return -1 |
46 |
|
elif b == '.': |
47 |
|
return 1 |
48 |
|
elif a.isdigit() and b.isdigit(): |
49 |
|
c = cmp(a, b) if (a.startswith('0') or b.startswith('0')) else cmp(int(a, 10), int(b, 10)) |
50 |
|
if c: |
51 |
|
return c |
52 |
|
else: |
53 |
|
c = cmp(a.upper(), b.upper()) |
54 |
|
if c: |
55 |
|
return c |
56 |
|
|
57 |
|
return cmp(len(A), len(B)) |
58 |
|
|
59 |
|
def get_latest_version(versions, max_version=None): |
60 |
|
"""Gets the latest version number |
61 |
|
|
62 |
|
if max_version is specified, gets the latest version number before |
63 |
|
max_version""" |
64 |
|
latest = None |
65 |
|
for version in versions: |
66 |
|
if ( latest is None or version_cmp(version, latest) > 0 ) \ |
67 |
|
and ( max_version is None or version_cmp(version, max_version) < 0 ): |
68 |
|
latest = version |
69 |
|
return latest |
70 |
|
|
71 |
def line_input (file): |
def line_input (file): |
72 |
for line in file: |
for line in file: |
73 |
if line[-1] == '\n': |
if line[-1] == '\n': |
75 |
else: |
else: |
76 |
yield line |
yield line |
77 |
|
|
78 |
|
def call_editor(filename): |
79 |
|
"""Return a sequence of possible editor binaries for the current platform""" |
80 |
|
|
81 |
|
editors = [] |
82 |
|
|
83 |
|
for varname in 'VISUAL', 'EDITOR': |
84 |
|
if varname in os.environ: |
85 |
|
editors.append(os.environ[varname]) |
86 |
|
|
87 |
|
editors.extend(('/usr/bin/editor', 'vi', 'pico', 'nano', 'joe')) |
88 |
|
|
89 |
|
for editor in editors: |
90 |
|
try: |
91 |
|
ret = subprocess.call([editor, filename]) |
92 |
|
except OSError, e: |
93 |
|
if e.errno == 2: |
94 |
|
continue |
95 |
|
raise |
96 |
|
|
97 |
|
if ret == 127: |
98 |
|
continue |
99 |
|
|
100 |
|
return True |
101 |
|
|
102 |
class urllister(SGMLParser): |
class urllister(SGMLParser): |
103 |
def reset(self): |
def reset(self): |
104 |
SGMLParser.reset(self) |
SGMLParser.reset(self) |
109 |
if href: |
if href: |
110 |
self.urls.extend(href) |
self.urls.extend(href) |
111 |
|
|
112 |
|
class SpecFile(object): |
113 |
|
re_update_version = re.compile(r'^(?P<pre>Version:\s*)(?P<version>.+)(?P<post>\s*)$', re.MULTILINE + re.IGNORECASE) |
114 |
|
re_update_release = re.compile(r'^(?P<pre>Release:\s*)(?P<release>%mkrel \d+)(?P<post>\s*)$', re.MULTILINE + re.IGNORECASE) |
115 |
|
|
116 |
|
def __init__(self, path): |
117 |
|
self.path = path |
118 |
|
self.cwd = os.path.dirname(path) |
119 |
|
|
120 |
|
@property |
121 |
|
def version(self): |
122 |
|
return subprocess.check_output(["rpm", "--specfile", self.path, "--queryformat", "%{VERSION}\n"]).splitlines()[0] |
123 |
|
|
124 |
|
def update(self, version): |
125 |
|
"""Update specfile (increase version)""" |
126 |
|
cur_version = self.version |
127 |
|
|
128 |
|
compare = version_cmp(version, cur_version) |
129 |
|
|
130 |
|
if compare == 0: |
131 |
|
print >>sys.stderr, "ERROR: Already at version %s!" % (cur_version) |
132 |
|
return False |
133 |
|
|
134 |
|
if compare != 1: |
135 |
|
print >>sys.stderr, "ERROR: Version %s is older than current version %s!" % (version, cur_version) |
136 |
|
return False |
137 |
|
|
138 |
|
with open(self.path, "rw") as f: |
139 |
|
data = f.read() |
140 |
|
|
141 |
|
if data.count("%mkrel") != 1: |
142 |
|
print >>sys.stderr, "ERROR: Multiple %mkrel found; don't know what to do!" |
143 |
|
return False |
144 |
|
|
145 |
|
data, nr = self.re_update_version.subn(r'\g<pre>%s\g<post>' % version, data, 1) |
146 |
|
if nr != 1: |
147 |
|
print >>sys.stderr, "ERROR: Could not increase version!" |
148 |
|
return False |
149 |
|
|
150 |
|
data, nr = self.re_update_release.subn(r'\g<pre>%mkrel 1\g<post>', data, 1) |
151 |
|
if nr != 1: |
152 |
|
print >>sys.stderr, "ERROR: Could not reset release!" |
153 |
|
return False |
154 |
|
|
155 |
|
# Overwrite file with new version number |
156 |
|
write_file(self.path, data) |
157 |
|
|
158 |
|
|
159 |
|
# Check RPM also agrees that version number has increased |
160 |
|
if self.version != version: |
161 |
|
print "ERROR: Increased version to %s, but RPM doesn't agree!?!" % version |
162 |
|
return False |
163 |
|
|
164 |
|
try: |
165 |
|
# Download new tarball |
166 |
|
subprocess.check_call(['mgarepo', 'sync', '-d'], cwd=self.cwd) |
167 |
|
# Check patches still apply |
168 |
|
subprocess.check_call(['bm', '-p', '--nodeps'], cwd=self.cwd) |
169 |
|
except subprocess.CalledProcessError: |
170 |
|
return False |
171 |
|
|
172 |
|
return True |
173 |
|
|
174 |
class Patch(object): |
class Patch(object): |
175 |
"""Do things with patches""" |
"""Do things with patches""" |
176 |
|
|
186 |
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) |
187 |
|
|
188 |
def add_dep3(self): |
def add_dep3(self): |
189 |
|
"""Add DEP-3 headers to a patch file""" |
190 |
if self.dep3['valid']: |
if self.dep3['valid']: |
191 |
return False |
return False |
192 |
|
|
212 |
|
|
213 |
# XXX - wrap this at 80 chars |
# XXX - wrap this at 80 chars |
214 |
add_line = True |
add_line = True |
215 |
print >>fdst, "%s: %s" % (header, data) |
print >>fdst, "%s: %s" % (header, "" if data is None else data) |
216 |
|
|
217 |
if add_line: print >>fdst, "" |
if add_line: print >>fdst, "" |
218 |
# Now copy any other data and the patch |
# Now copy any other data and the patch |
221 |
fdst.flush() |
fdst.flush() |
222 |
os.rename(fdst.name, self.path) |
os.rename(fdst.name, self.path) |
223 |
|
|
224 |
|
call_editor(self.path) |
225 |
|
|
226 |
#Author: fwang |
#Author: fwang |
227 |
#Subject: Build fix: Fix glib header inclusion |
#Subject: Build fix: Fix glib header inclusion |
228 |
#Applied-Upstream: commit:30602 |
#Applied-Upstream: commit:30602 |
230 |
#Bug: http://bugzilla.abisource.com/show_bug.cgi?id=13247 |
#Bug: http://bugzilla.abisource.com/show_bug.cgi?id=13247 |
231 |
|
|
232 |
def _read_dep3(self): |
def _read_dep3(self): |
233 |
"""This will also parse git headers""" |
"""Read DEP-3 headers from an existing patch file |
234 |
|
|
235 |
|
This will also parse git headers""" |
236 |
dep3 = {} |
dep3 = {} |
237 |
headers = {} |
headers = {} |
238 |
|
|
250 |
r = self.re_dep3.match(line) |
r = self.re_dep3.match(line) |
251 |
if r: |
if r: |
252 |
info = r.groupdict() |
info = r.groupdict() |
253 |
|
|
254 |
|
# Avoid matching URLS |
255 |
|
if info['data'].startswith('//') and info['header'].lower () == info['header']: |
256 |
|
continue |
257 |
|
|
258 |
headers[info['header']] = info['data'] |
headers[info['header']] = info['data'] |
259 |
last_header = info['header'] |
last_header = info['header'] |
260 |
last_nr = nr |
last_nr = nr |
305 |
if len(fields) >= 3: |
if len(fields) >= 3: |
306 |
self._svn_author = fields[1] |
self._svn_author = fields[1] |
307 |
|
|
308 |
|
if not hasattr(self, '_svn_author'): |
309 |
|
return None |
310 |
|
|
311 |
return self._svn_author |
return self._svn_author |
312 |
|
|
313 |
def get_upstream_names(): |
def get_upstream_names(): |
362 |
|
|
363 |
return TARBALLS, FILES |
return TARBALLS, FILES |
364 |
|
|
365 |
|
|
366 |
|
def write_file(path, data): |
367 |
|
with tempfile.NamedTemporaryFile(dir=os.path.dirname(path), delete=False) as fdst: |
368 |
|
fdst.write(data) |
369 |
|
fdst.flush() |
370 |
|
os.rename(fdst.name, path) |
371 |
|
|
372 |
def cmd_co(options, parser): |
def cmd_co(options, parser): |
373 |
upstream = get_upstream_names() |
upstream = get_upstream_names() |
374 |
downstream, downstream_files = get_downstream_names() |
downstream, downstream_files = get_downstream_names() |
402 |
for srpm in downstream[module]: |
for srpm in downstream[module]: |
403 |
for filename in downstream_files[srpm]: |
for filename in downstream_files[srpm]: |
404 |
if '.patch' in filename or '.diff' in filename: |
if '.patch' in filename or '.diff' in filename: |
405 |
|
|
406 |
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) |
407 |
print "\t".join((module, srpm, str(p))) |
valid = "" |
408 |
|
forwarded = "" |
409 |
if p.dep3['headers']: |
if p.dep3['headers']: |
410 |
pprint.pprint(p.dep3['headers']) |
forwarded = p.dep3['headers'].get('Forwarded', "no") |
411 |
if p.dep3['valid']: |
if p.dep3['valid']: |
412 |
print "VALID" |
valid="VALID" |
413 |
|
print "\t".join((module, srpm, str(p), forwarded, valid)) |
414 |
|
|
415 |
def cmd_dep3(options, parser): |
def cmd_dep3(options, parser): |
416 |
p = Patch(options.patch) |
p = Patch(options.patch) |
417 |
p.add_dep3() |
p.add_dep3() |
418 |
|
|
419 |
|
def cmd_package_new_version(options, parser): |
420 |
|
cwd = os.path.expanduser(PKGROOT) |
421 |
|
package = options.package |
422 |
|
|
423 |
|
subprocess.call(['mgarepo', 'co', package], cwd=cwd) |
424 |
|
s = SpecFile(os.path.join(cwd, package, "SPECS", "%s.spec" % package)) |
425 |
|
print "%s => %s" % (s.version, options.version) |
426 |
|
if not s.update(options.version): |
427 |
|
sys.exit(1) |
428 |
|
|
429 |
|
|
430 |
def main(): |
def main(): |
431 |
description = """Mageia GNOME commands.""" |
description = """Mageia GNOME commands.""" |
432 |
epilog="""Report bugs to Olav Vitters""" |
epilog="""Report bugs to Olav Vitters""" |
458 |
func=cmd_dep3, path=False |
func=cmd_dep3, path=False |
459 |
) |
) |
460 |
|
|
461 |
|
subparser = subparsers.add_parser('increase', help='Increase version number') |
462 |
|
subparser.add_argument("package", help="Package name") |
463 |
|
subparser.add_argument("version", help="Version number") |
464 |
|
subparser.set_defaults( |
465 |
|
func=cmd_package_new_version, path=False |
466 |
|
) |
467 |
|
|
468 |
if len(sys.argv) == 1: |
if len(sys.argv) == 1: |
469 |
parser.print_help() |
parser.print_help() |
470 |
sys.exit(2) |
sys.exit(2) |