1 |
ovitters |
3121 |
#!/usr/bin/python -u |
2 |
ovitters |
2932 |
|
3 |
ovitters |
3057 |
# A lot of the code comes from ftpadmin, see |
4 |
|
|
# http://git.gnome.org/browse/sysadmin-bin/tree/ftpadmin |
5 |
|
|
# Written by Olav Vitters |
6 |
|
|
|
7 |
|
|
# basic modules: |
8 |
ovitters |
2932 |
import os |
9 |
|
|
import os.path |
10 |
|
|
import sys |
11 |
|
|
import re |
12 |
|
|
import subprocess |
13 |
ovitters |
3057 |
|
14 |
|
|
# command line parsing, error handling: |
15 |
ovitters |
2932 |
import argparse |
16 |
ovitters |
2936 |
import errno |
17 |
ovitters |
3057 |
|
18 |
|
|
# overwriting files by moving them (safer): |
19 |
ovitters |
2944 |
import tempfile |
20 |
|
|
import shutil |
21 |
ovitters |
3057 |
|
22 |
|
|
# version comparison: |
23 |
ovitters |
3045 |
import rpm |
24 |
ovitters |
3057 |
|
25 |
|
|
# opening tarballs: |
26 |
|
|
import tarfile |
27 |
|
|
import gzip |
28 |
|
|
import bz2 |
29 |
|
|
import lzma # pyliblzma |
30 |
|
|
|
31 |
|
|
# getting links from HTML document: |
32 |
ovitters |
2932 |
from sgmllib import SGMLParser |
33 |
ovitters |
3057 |
import urllib2 |
34 |
|
|
import urlparse |
35 |
ovitters |
2932 |
|
36 |
ovitters |
3115 |
# for checking hashes |
37 |
|
|
import hashlib |
38 |
|
|
|
39 |
ovitters |
3119 |
# for parsing ftp-release-list emails |
40 |
|
|
import email |
41 |
|
|
from email.mime.text import MIMEText |
42 |
|
|
|
43 |
ovitters |
3120 |
# to be able to sleep for a while |
44 |
|
|
import time |
45 |
ovitters |
3119 |
|
46 |
ovitters |
3180 |
# version freeze |
47 |
|
|
import datetime |
48 |
|
|
|
49 |
ovitters |
3653 |
# packages --sort |
50 |
|
|
import itertools |
51 |
|
|
|
52 |
ovitters |
5288 |
# check-latest |
53 |
|
|
import requests |
54 |
|
|
|
55 |
ovitters |
3557 |
SLEEP_INITIAL=180 |
56 |
ovitters |
3555 |
SLEEP_REPEAT=30 |
57 |
|
|
SLEEP_TIMES=20 |
58 |
ovitters |
2932 |
|
59 |
ovitters |
3090 |
re_majmin = re.compile(r'^([0-9]+\.[0-9]+).*') |
60 |
ovitters |
3012 |
re_version = re.compile(r'([-.]|\d+|[^-.\d]+)') |
61 |
|
|
|
62 |
|
|
def version_cmp(a, b): |
63 |
|
|
"""Compares two versions |
64 |
|
|
|
65 |
|
|
Returns |
66 |
|
|
-1 if a < b |
67 |
|
|
0 if a == b |
68 |
|
|
1 if a > b |
69 |
ovitters |
3045 |
""" |
70 |
ovitters |
3012 |
|
71 |
ovitters |
3045 |
return rpm.labelCompare(('1', a, '1'), ('1', b, '1')) |
72 |
ovitters |
3012 |
|
73 |
|
|
def get_latest_version(versions, max_version=None): |
74 |
|
|
"""Gets the latest version number |
75 |
|
|
|
76 |
|
|
if max_version is specified, gets the latest version number before |
77 |
|
|
max_version""" |
78 |
|
|
latest = None |
79 |
|
|
for version in versions: |
80 |
|
|
if ( latest is None or version_cmp(version, latest) > 0 ) \ |
81 |
|
|
and ( max_version is None or version_cmp(version, max_version) < 0 ): |
82 |
|
|
latest = version |
83 |
|
|
return latest |
84 |
|
|
|
85 |
ovitters |
5288 |
def get_safe_max_version(version): |
86 |
|
|
if not re_majmin.match(version): |
87 |
|
|
return None |
88 |
|
|
|
89 |
|
|
majmin_nr = map(long, re_majmin.sub(r'\1', version).split('.')) |
90 |
|
|
|
91 |
|
|
if majmin_nr[1] % 2 == 0: |
92 |
|
|
return "%d.%d" % (majmin_nr[0], majmin_nr[1] + 1) |
93 |
|
|
else: |
94 |
|
|
return "%d.%d" % (majmin_nr[0], majmin_nr[1] + 2) |
95 |
|
|
|
96 |
ovitters |
3088 |
def judge_version_increase(version_old, version_new): |
97 |
|
|
"""Judge quality of version increase: |
98 |
|
|
|
99 |
|
|
Returns a tuple containing judgement and message |
100 |
|
|
|
101 |
|
|
Judgement: |
102 |
|
|
Less than 0: Error |
103 |
|
|
0 to 4: Better not |
104 |
|
|
5+: Ok""" |
105 |
|
|
versions = (version_old, version_new) |
106 |
|
|
|
107 |
|
|
# First do a basic version comparison to ensure version_new is actually newer |
108 |
|
|
compare = version_cmp(version_new, version_old) |
109 |
|
|
|
110 |
|
|
if compare == 0: |
111 |
ovitters |
3125 |
# 1.0.0 -> 1.0.1 |
112 |
ovitters |
3088 |
return (-2, "Already at version %s!" % (version_old)) |
113 |
|
|
|
114 |
|
|
if compare != 1: |
115 |
ovitters |
3125 |
# 1.0.1 -> 1.0.0 |
116 |
ovitters |
3088 |
return (-3, "Version %s is older than current version %s!" % (version_new, version_old)) |
117 |
|
|
|
118 |
|
|
# Version is newer, but we don't want to see if it follows the GNOME versioning scheme |
119 |
|
|
majmins = [re_majmin.sub(r'\1', ver) for ver in versions if re_majmin.match(ver) is not None] |
120 |
|
|
|
121 |
|
|
if len(majmins) == 1: |
122 |
|
|
return (-1, "Version number scheme changes: %s" % (", ".join(versions))) |
123 |
|
|
|
124 |
|
|
if len(majmins) == 0: |
125 |
|
|
return (0, "Unsupported version numbers: %s" % (", ".join(versions))) |
126 |
|
|
|
127 |
|
|
# Follows GNOME versioning scheme |
128 |
|
|
# Meaning: x.y.z |
129 |
|
|
# x = major |
130 |
|
|
# y = minor : even if stable |
131 |
|
|
# z = micro |
132 |
|
|
|
133 |
|
|
# Major+minor the same? Then go ahead and upgrade! |
134 |
|
|
if majmins[0] == majmins[1]: |
135 |
|
|
# Majmin of both versions are the same, looks good! |
136 |
ovitters |
3125 |
# 1.1.x -> 1.1.x or 1.0.x -> 1.0.x |
137 |
ovitters |
3088 |
return (10, None) |
138 |
|
|
|
139 |
|
|
# More detailed analysis needed, so figure out the numbers |
140 |
|
|
majmin_nrs = [map(long, ver.split('.')) for ver in majmins] |
141 |
|
|
|
142 |
|
|
# Check/ensure major version number is the same |
143 |
|
|
if majmin_nrs[0][0] != majmin_nrs[1][0]: |
144 |
ovitters |
3125 |
# 1.0.x -> 2.0.x |
145 |
ovitters |
3088 |
return (1, "Major version number increase") |
146 |
|
|
|
147 |
|
|
# Minor indicates stable/unstable |
148 |
|
|
devstate = (majmin_nrs[0][1] % 2 == 0, majmin_nrs[1][1] % 2 == 0) |
149 |
|
|
|
150 |
|
|
# Upgrading to unstable is weird |
151 |
|
|
if not devstate[1]: |
152 |
|
|
if devstate[0]: |
153 |
ovitters |
3125 |
# 1.2.x -> 1.3.x |
154 |
ovitters |
3088 |
return (1, "Stable to unstable increase") |
155 |
|
|
|
156 |
ovitters |
3125 |
# 1.3.x -> 1.5.x |
157 |
ovitters |
3088 |
return (4, "Unstable to unstable version increase") |
158 |
|
|
|
159 |
|
|
# Unstable => stable is always ok |
160 |
|
|
if not devstate[0]: |
161 |
ovitters |
3125 |
# 1.1.x -> 1.2.x |
162 |
ovitters |
3088 |
return (5, "Unstable to stable") |
163 |
|
|
|
164 |
|
|
# Can only be increase of minors from one stable to the next |
165 |
ovitters |
3125 |
# 1.0.x -> 1.2.x |
166 |
ovitters |
3088 |
return (6, "Stable version increase") |
167 |
|
|
|
168 |
ovitters |
2936 |
def line_input (file): |
169 |
|
|
for line in file: |
170 |
|
|
if line[-1] == '\n': |
171 |
|
|
yield line[:-1] |
172 |
|
|
else: |
173 |
|
|
yield line |
174 |
|
|
|
175 |
ovitters |
2955 |
def call_editor(filename): |
176 |
|
|
"""Return a sequence of possible editor binaries for the current platform""" |
177 |
|
|
|
178 |
|
|
editors = [] |
179 |
|
|
|
180 |
|
|
for varname in 'VISUAL', 'EDITOR': |
181 |
|
|
if varname in os.environ: |
182 |
|
|
editors.append(os.environ[varname]) |
183 |
|
|
|
184 |
|
|
editors.extend(('/usr/bin/editor', 'vi', 'pico', 'nano', 'joe')) |
185 |
|
|
|
186 |
|
|
for editor in editors: |
187 |
|
|
try: |
188 |
|
|
ret = subprocess.call([editor, filename]) |
189 |
|
|
except OSError, e: |
190 |
|
|
if e.errno == 2: |
191 |
|
|
continue |
192 |
|
|
raise |
193 |
|
|
|
194 |
|
|
if ret == 127: |
195 |
|
|
continue |
196 |
|
|
|
197 |
|
|
return True |
198 |
|
|
|
199 |
ovitters |
2932 |
class urllister(SGMLParser): |
200 |
|
|
def reset(self): |
201 |
|
|
SGMLParser.reset(self) |
202 |
|
|
self.urls = [] |
203 |
|
|
|
204 |
|
|
def start_a(self, attrs): |
205 |
|
|
href = [v for k, v in attrs if k=='href'] |
206 |
|
|
if href: |
207 |
|
|
self.urls.extend(href) |
208 |
|
|
|
209 |
ovitters |
3057 |
class XzTarFile(tarfile.TarFile): |
210 |
|
|
|
211 |
|
|
OPEN_METH = tarfile.TarFile.OPEN_METH.copy() |
212 |
|
|
OPEN_METH["xz"] = "xzopen" |
213 |
|
|
|
214 |
|
|
@classmethod |
215 |
|
|
def xzopen(cls, name, mode="r", fileobj=None, **kwargs): |
216 |
|
|
"""Open gzip compressed tar archive name for reading or writing. |
217 |
|
|
Appending is not allowed. |
218 |
|
|
""" |
219 |
|
|
if len(mode) > 1 or mode not in "rw": |
220 |
|
|
raise ValueError("mode must be 'r' or 'w'") |
221 |
|
|
|
222 |
|
|
if fileobj is not None: |
223 |
|
|
fileobj = _LMZAProxy(fileobj, mode) |
224 |
|
|
else: |
225 |
|
|
fileobj = lzma.LZMAFile(name, mode) |
226 |
|
|
|
227 |
|
|
try: |
228 |
|
|
# lzma doesn't immediately return an error |
229 |
|
|
# try and read a bit of data to determine if it is a valid xz file |
230 |
|
|
fileobj.read(_LZMAProxy.blocksize) |
231 |
|
|
fileobj.seek(0) |
232 |
|
|
t = cls.taropen(name, mode, fileobj, **kwargs) |
233 |
|
|
except IOError: |
234 |
|
|
raise tarfile.ReadError("not a xz file") |
235 |
|
|
except lzma.error: |
236 |
|
|
raise tarfile.ReadError("not a xz file") |
237 |
|
|
t._extfileobj = False |
238 |
|
|
return t |
239 |
|
|
|
240 |
ovitters |
3082 |
if not hasattr(tarfile.TarFile, 'xzopen'): |
241 |
ovitters |
3057 |
tarfile.open = XzTarFile.open |
242 |
|
|
|
243 |
ovitters |
3115 |
def is_valid_hash(path, algo, hexdigest): |
244 |
|
|
if algo not in hashlib.algorithms: |
245 |
|
|
raise ValueError("Unknown hash algorithm: %s" % algo) |
246 |
|
|
|
247 |
|
|
local_hash = getattr(hashlib, algo)() |
248 |
|
|
|
249 |
|
|
with open(path, 'rb') as fp: |
250 |
|
|
data = fp.read(32768) |
251 |
|
|
while data: |
252 |
|
|
local_hash.update(data) |
253 |
|
|
data = fp.read(32768) |
254 |
|
|
|
255 |
|
|
return local_hash.hexdigest() == hexdigest |
256 |
|
|
|
257 |
ovitters |
3012 |
class SpecFile(object): |
258 |
|
|
re_update_version = re.compile(r'^(?P<pre>Version:\s*)(?P<version>.+)(?P<post>\s*)$', re.MULTILINE + re.IGNORECASE) |
259 |
|
|
re_update_release = re.compile(r'^(?P<pre>Release:\s*)(?P<release>%mkrel \d+)(?P<post>\s*)$', re.MULTILINE + re.IGNORECASE) |
260 |
|
|
|
261 |
|
|
def __init__(self, path): |
262 |
|
|
self.path = path |
263 |
|
|
self.cwd = os.path.dirname(path) |
264 |
|
|
|
265 |
|
|
@property |
266 |
|
|
def version(self): |
267 |
|
|
return subprocess.check_output(["rpm", "--specfile", self.path, "--queryformat", "%{VERSION}\n"]).splitlines()[0] |
268 |
ovitters |
3115 |
@property |
269 |
|
|
def sources(self): |
270 |
|
|
ts = rpm.ts() |
271 |
|
|
spec = ts.parseSpec(self.path) |
272 |
|
|
srclist = spec.sources if isinstance(spec.sources, (list, tuple)) \ |
273 |
|
|
else spec.sources() |
274 |
|
|
return dict((os.path.basename(name), name) for name, no, flags in srclist) |
275 |
ovitters |
3037 |
|
276 |
ovitters |
3555 |
def update(self, version, force=False): |
277 |
ovitters |
3012 |
"""Update specfile (increase version)""" |
278 |
|
|
cur_version = self.version |
279 |
|
|
|
280 |
ovitters |
3088 |
(judgement, msg) = judge_version_increase(cur_version, version) |
281 |
ovitters |
3037 |
|
282 |
ovitters |
3088 |
if judgement < 0: |
283 |
|
|
print >>sys.stderr, "ERROR: %s!" % (msg) |
284 |
ovitters |
3037 |
return False |
285 |
|
|
|
286 |
ovitters |
3088 |
if judgement < 5: |
287 |
ovitters |
3089 |
print "WARNING: %s!" % (msg) |
288 |
ovitters |
3555 |
if not force: return False |
289 |
ovitters |
3012 |
|
290 |
ovitters |
3039 |
# XXX - os.path.join is hackish |
291 |
ovitters |
3560 |
svn_diff_output = subprocess.check_output(["svn", "diff", os.path.join(self.path, '..')]) |
292 |
|
|
if svn_diff_output != '': |
293 |
|
|
print svn_diff_output |
294 |
ovitters |
3039 |
print >>sys.stderr, "ERROR: Package has uncommitted changes!" |
295 |
ovitters |
3560 |
if not force: |
296 |
|
|
return False |
297 |
ovitters |
3039 |
|
298 |
ovitters |
3560 |
# Forcing package submission: revert changes |
299 |
|
|
try: |
300 |
|
|
print >>sys.stderr, "WARNING: Force used; reverting svn changes" |
301 |
|
|
subprocess.check_call(["svn", "revert", "-R", os.path.join(self.path, '..')]) |
302 |
|
|
except subprocess.CalledProcessError: |
303 |
|
|
return False |
304 |
|
|
|
305 |
ovitters |
3012 |
with open(self.path, "rw") as f: |
306 |
|
|
data = f.read() |
307 |
|
|
|
308 |
|
|
if data.count("%mkrel") != 1: |
309 |
ovitters |
3037 |
print >>sys.stderr, "ERROR: Multiple %mkrel found; don't know what to do!" |
310 |
ovitters |
3012 |
return False |
311 |
|
|
|
312 |
|
|
data, nr = self.re_update_version.subn(r'\g<pre>%s\g<post>' % version, data, 1) |
313 |
|
|
if nr != 1: |
314 |
ovitters |
3037 |
print >>sys.stderr, "ERROR: Could not increase version!" |
315 |
ovitters |
3012 |
return False |
316 |
|
|
|
317 |
|
|
data, nr = self.re_update_release.subn(r'\g<pre>%mkrel 1\g<post>', data, 1) |
318 |
|
|
if nr != 1: |
319 |
ovitters |
3037 |
print >>sys.stderr, "ERROR: Could not reset release!" |
320 |
ovitters |
3012 |
return False |
321 |
|
|
|
322 |
|
|
# Overwrite file with new version number |
323 |
|
|
write_file(self.path, data) |
324 |
|
|
|
325 |
|
|
|
326 |
ovitters |
3045 |
# Verify that RPM also agrees that version number has changed |
327 |
ovitters |
3012 |
if self.version != version: |
328 |
|
|
print "ERROR: Increased version to %s, but RPM doesn't agree!?!" % version |
329 |
|
|
return False |
330 |
|
|
|
331 |
ovitters |
3555 |
|
332 |
|
|
# Try to download the new tarball various times and wait between attempts |
333 |
|
|
tries = 0 |
334 |
|
|
while tries < SLEEP_TIMES: |
335 |
|
|
tries += 1 |
336 |
ovitters |
3558 |
if tries > 1: time.sleep(SLEEP_REPEAT) |
337 |
ovitters |
3555 |
try: |
338 |
|
|
# Download new tarball |
339 |
|
|
subprocess.check_call(['mgarepo', 'sync', '-d'], cwd=self.cwd) |
340 |
ovitters |
3558 |
# success, so exit loop |
341 |
ovitters |
3555 |
break |
342 |
|
|
except subprocess.CalledProcessError, e: |
343 |
|
|
# mgarepo sync returns 1 if the tarball cannot be downloaded |
344 |
|
|
if e.returncode != 1: |
345 |
|
|
return False |
346 |
ovitters |
3558 |
else: |
347 |
|
|
return False |
348 |
ovitters |
3555 |
|
349 |
|
|
|
350 |
ovitters |
3034 |
try: |
351 |
|
|
# Check patches still apply |
352 |
|
|
subprocess.check_call(['bm', '-p', '--nodeps'], cwd=self.cwd) |
353 |
|
|
except subprocess.CalledProcessError: |
354 |
ovitters |
3568 |
logfile = os.path.join(os.path.dirname(self.path), 'log.%s' % os.path.splitext(os.path.basename(self.path))[0]) |
355 |
ovitters |
3569 |
if os.path.exists(logfile): |
356 |
ovitters |
3568 |
subprocess.call(['tail', '-n', '15', logfile]) |
357 |
ovitters |
3034 |
return False |
358 |
ovitters |
3012 |
|
359 |
|
|
return True |
360 |
|
|
|
361 |
ovitters |
2936 |
class Patch(object): |
362 |
|
|
"""Do things with patches""" |
363 |
|
|
|
364 |
|
|
re_dep3 = re.compile(r'^(?:#\s*)?(?P<header>[-A-Za-z0-9]+?):\s*(?P<data>.*)$') |
365 |
|
|
re_dep3_cont = re.compile(r'^#?\s+(?P<data>.*)$') |
366 |
|
|
|
367 |
|
|
def __init__(self, path, show_path=False): |
368 |
|
|
"""Path: path to patch (might not exist)""" |
369 |
|
|
self.path = path |
370 |
|
|
self.show_path = show_path |
371 |
|
|
|
372 |
|
|
def __str__(self): |
373 |
|
|
return self.path if self.show_path else os.path.basename(self.path) |
374 |
|
|
|
375 |
|
|
def add_dep3(self): |
376 |
ovitters |
2955 |
"""Add DEP-3 headers to a patch file""" |
377 |
ovitters |
2944 |
if self.dep3['valid']: |
378 |
|
|
return False |
379 |
|
|
|
380 |
|
|
new_headers = ( |
381 |
|
|
('Author', self.svn_author), |
382 |
|
|
('Subject', ''), |
383 |
|
|
('Applied-Upstream', ''), |
384 |
|
|
('Forwarded', ''), |
385 |
|
|
('Bug', ''), |
386 |
|
|
) |
387 |
|
|
|
388 |
|
|
with tempfile.NamedTemporaryFile(dir=os.path.dirname(self.path), delete=False) as fdst: |
389 |
|
|
with open(self.path, "r") as fsrc: |
390 |
|
|
# Start with any existing DEP3 headers |
391 |
|
|
for i in range(self.dep3['last_nr']): |
392 |
|
|
fdst.write(fsrc.read()) |
393 |
|
|
|
394 |
|
|
# After that add the DEP3 headers |
395 |
|
|
add_line = False |
396 |
|
|
for header, data in new_headers: |
397 |
|
|
if header in self.dep3['headers']: |
398 |
|
|
continue |
399 |
|
|
|
400 |
|
|
# XXX - wrap this at 80 chars |
401 |
|
|
add_line = True |
402 |
ovitters |
2955 |
print >>fdst, "%s: %s" % (header, "" if data is None else data) |
403 |
ovitters |
2944 |
|
404 |
|
|
if add_line: print >>fdst, "" |
405 |
|
|
# Now copy any other data and the patch |
406 |
|
|
shutil.copyfileobj(fsrc, fdst) |
407 |
|
|
|
408 |
|
|
fdst.flush() |
409 |
|
|
os.rename(fdst.name, self.path) |
410 |
|
|
|
411 |
ovitters |
2955 |
call_editor(self.path) |
412 |
|
|
|
413 |
ovitters |
2936 |
#Author: fwang |
414 |
|
|
#Subject: Build fix: Fix glib header inclusion |
415 |
|
|
#Applied-Upstream: commit:30602 |
416 |
|
|
#Forwarded: yes |
417 |
|
|
#Bug: http://bugzilla.abisource.com/show_bug.cgi?id=13247 |
418 |
|
|
|
419 |
|
|
def _read_dep3(self): |
420 |
ovitters |
2955 |
"""Read DEP-3 headers from an existing patch file |
421 |
|
|
|
422 |
|
|
This will also parse git headers""" |
423 |
ovitters |
2936 |
dep3 = {} |
424 |
ovitters |
2944 |
headers = {} |
425 |
ovitters |
2936 |
|
426 |
|
|
last_header = None |
427 |
ovitters |
2944 |
last_nr = 0 |
428 |
|
|
nr = 0 |
429 |
ovitters |
2936 |
try: |
430 |
|
|
with open(self.path, "r") as f: |
431 |
|
|
for line in line_input(f): |
432 |
ovitters |
2944 |
nr += 1 |
433 |
|
|
# stop trying to parse when real patch begins |
434 |
ovitters |
2936 |
if line == '---': |
435 |
|
|
break |
436 |
|
|
|
437 |
|
|
r = self.re_dep3.match(line) |
438 |
|
|
if r: |
439 |
|
|
info = r.groupdict() |
440 |
ovitters |
3012 |
|
441 |
|
|
# Avoid matching URLS |
442 |
|
|
if info['data'].startswith('//') and info['header'].lower () == info['header']: |
443 |
|
|
continue |
444 |
|
|
|
445 |
ovitters |
2944 |
headers[info['header']] = info['data'] |
446 |
ovitters |
2936 |
last_header = info['header'] |
447 |
ovitters |
2944 |
last_nr = nr |
448 |
ovitters |
2936 |
continue |
449 |
|
|
|
450 |
|
|
r = self.re_dep3_cont.match(line) |
451 |
|
|
if r: |
452 |
|
|
info = r.groupdict() |
453 |
|
|
if last_header: |
454 |
ovitters |
2944 |
headers[last_header] = " ".join((headers[last_header], info['data'])) |
455 |
|
|
last_nr = nr |
456 |
ovitters |
2936 |
continue |
457 |
|
|
|
458 |
|
|
last_header = None |
459 |
|
|
except IOError: |
460 |
|
|
pass |
461 |
ovitters |
2944 |
|
462 |
|
|
dep3['valid'] = \ |
463 |
|
|
(('Description' in headers and headers['Description'].strip() != '') |
464 |
|
|
or ('Subject' in headers and headers['Subject'].strip() != '')) \ |
465 |
|
|
and (('Origin' in headers and headers['Origin'].strip() != '') \ |
466 |
|
|
or ('Author' in headers and headers['Author'].strip() != '') \ |
467 |
|
|
or ('From' in headers and headers['From'].strip() != '')) |
468 |
|
|
dep3['last_nr'] = last_nr |
469 |
|
|
dep3['headers'] = headers |
470 |
|
|
|
471 |
ovitters |
2936 |
self._dep3 = dep3 |
472 |
|
|
|
473 |
|
|
@property |
474 |
|
|
def dep3(self): |
475 |
|
|
if not hasattr(self, '_dep3'): |
476 |
|
|
self._read_dep3() |
477 |
|
|
|
478 |
|
|
return self._dep3 |
479 |
|
|
|
480 |
ovitters |
2944 |
@property |
481 |
|
|
def svn_author(self): |
482 |
|
|
if not hasattr(self, '_svn_author'): |
483 |
ovitters |
3083 |
try: |
484 |
|
|
contents = subprocess.check_output(['svn', 'log', '-q', "--", self.path], close_fds=True).strip("\n").splitlines() |
485 |
|
|
|
486 |
ovitters |
2944 |
for line in contents: |
487 |
|
|
if ' | ' not in line: |
488 |
|
|
continue |
489 |
ovitters |
2936 |
|
490 |
ovitters |
2944 |
fields = line.split(' | ') |
491 |
|
|
if len(fields) >= 3: |
492 |
|
|
self._svn_author = fields[1] |
493 |
ovitters |
3083 |
except subprocess.CalledProcessError: |
494 |
|
|
pass |
495 |
ovitters |
2944 |
|
496 |
ovitters |
2955 |
if not hasattr(self, '_svn_author'): |
497 |
|
|
return None |
498 |
|
|
|
499 |
ovitters |
2944 |
return self._svn_author |
500 |
|
|
|
501 |
ovitters |
2932 |
|
502 |
ovitters |
3649 |
class Upstream(object): |
503 |
ovitters |
2932 |
|
504 |
ovitters |
5287 |
URL="http://download.gnome.org/sources/" |
505 |
ovitters |
3649 |
limit = None |
506 |
ovitters |
5288 |
_cache_versions = {} |
507 |
ovitters |
2932 |
|
508 |
ovitters |
3649 |
def __init__(self): |
509 |
|
|
urlopen = urllib2.build_opener() |
510 |
ovitters |
2932 |
|
511 |
ovitters |
3649 |
good_dir = re.compile('^[-A-Za-z0-9_+.]+/$') |
512 |
ovitters |
2932 |
|
513 |
ovitters |
3649 |
# Get the files |
514 |
ovitters |
5287 |
usock = urlopen.open(self.URL) |
515 |
ovitters |
3649 |
parser = urllister() |
516 |
|
|
parser.feed(usock.read()) |
517 |
|
|
usock.close() |
518 |
|
|
parser.close() |
519 |
|
|
files = parser.urls |
520 |
|
|
|
521 |
|
|
tarballs = set([filename.replace('/', '') for filename in files if good_dir.search(filename)]) |
522 |
|
|
if self.limit is not None: |
523 |
|
|
tarballs.intersection_update(self.limit) |
524 |
|
|
|
525 |
|
|
self.names = tarballs |
526 |
|
|
|
527 |
ovitters |
5288 |
@classmethod |
528 |
|
|
def versions(cls, module): |
529 |
|
|
# XXX - ugly |
530 |
|
|
if module not in cls._cache_versions: |
531 |
|
|
versions = None |
532 |
|
|
|
533 |
|
|
url = '%s%s/cache.json' % (cls.URL, module) |
534 |
|
|
r = requests.get(url) |
535 |
|
|
j = r.json |
536 |
|
|
if j is not None and len(j) > 2 and module in j[2]: |
537 |
|
|
versions = j[2][module] |
538 |
|
|
|
539 |
|
|
cls._cache_versions[module] = versions |
540 |
|
|
|
541 |
|
|
return cls._cache_versions[module] |
542 |
|
|
|
543 |
ovitters |
3650 |
class Downstream(object): |
544 |
ovitters |
2932 |
re_file = re.compile(r'^(?P<module>.*?)[_-](?:(?P<oldversion>([0-9]+[\.])*[0-9]+)-)?(?P<version>([0-9]+[\.\-])*[0-9]+)\.(?P<format>(?:tar\.|diff\.)?[a-z][a-z0-9]*)$') |
545 |
|
|
|
546 |
ovitters |
5287 |
MEDIA="Core Release Source" |
547 |
|
|
PKGROOT='~/pkgs' |
548 |
|
|
DISTRO=None |
549 |
|
|
|
550 |
ovitters |
3650 |
def __init__(self): |
551 |
ovitters |
5287 |
contents = subprocess.check_output(['urpmf', '--qf', '%name|%version|%files', '.', "--media", self.MEDIA], close_fds=True).strip("\n").splitlines() |
552 |
ovitters |
2932 |
|
553 |
ovitters |
3650 |
FILES = {} |
554 |
|
|
TARBALLS = {} |
555 |
ovitters |
2932 |
|
556 |
ovitters |
3650 |
for line in contents: |
557 |
|
|
try: |
558 |
|
|
srpm, version, filename = line.split("|") |
559 |
|
|
except ValueError: |
560 |
|
|
print >>sys.stderr, line |
561 |
|
|
continue |
562 |
ovitters |
2932 |
|
563 |
ovitters |
3650 |
if '.tar' in filename: |
564 |
|
|
r = self.re_file.match(filename) |
565 |
|
|
if r: |
566 |
|
|
fileinfo = r.groupdict() |
567 |
|
|
module = fileinfo['module'] |
568 |
ovitters |
2932 |
|
569 |
ovitters |
3650 |
if module not in TARBALLS: |
570 |
|
|
TARBALLS[module] = {} |
571 |
|
|
TARBALLS[module][srpm] = version |
572 |
ovitters |
2932 |
|
573 |
ovitters |
3650 |
if srpm not in FILES: |
574 |
|
|
FILES[srpm] = set() |
575 |
|
|
FILES[srpm].add(filename) |
576 |
ovitters |
2932 |
|
577 |
ovitters |
3650 |
self.tarballs = TARBALLS |
578 |
|
|
self.files = FILES |
579 |
ovitters |
2932 |
|
580 |
ovitters |
5287 |
@classmethod |
581 |
|
|
def co(cls, package, cwd=None): |
582 |
|
|
if cwd is None: |
583 |
|
|
cwd = os.path.expanduser(cls.PKGROOT) |
584 |
|
|
|
585 |
|
|
cmd = ['mgarepo', 'co'] |
586 |
|
|
if cls.DISTRO: |
587 |
|
|
cmd.extend(('-d', cls.DISTRO)) |
588 |
|
|
cmd.append(package) |
589 |
|
|
return subprocess.check_call(cmd, cwd=cwd) |
590 |
|
|
|
591 |
ovitters |
3652 |
def get_downstream_from_upstream(self, upstream, version): |
592 |
|
|
if upstream not in self.tarballs: |
593 |
|
|
raise ValueError("No packages for upstream name: %s" % upstream) |
594 |
ovitters |
3012 |
|
595 |
ovitters |
3652 |
if len(self.tarballs[upstream]) == 1: |
596 |
|
|
return self.tarballs[upstream].keys() |
597 |
ovitters |
3119 |
|
598 |
ovitters |
3652 |
# Directories packages are located in |
599 |
ovitters |
5287 |
root = os.path.expanduser(self.PKGROOT) |
600 |
ovitters |
3119 |
|
601 |
ovitters |
3652 |
packages = {} |
602 |
|
|
for package in self.tarballs[upstream].keys(): |
603 |
|
|
cwd = os.path.join(root, package) |
604 |
ovitters |
3119 |
|
605 |
ovitters |
3652 |
# Checkout package to ensure the checkout reflects the latest changes |
606 |
|
|
try: |
607 |
ovitters |
5287 |
self.co(package, cwd=root) |
608 |
ovitters |
3652 |
except subprocess.CalledProcessError: |
609 |
|
|
raise ValueError("Multiple packages found and cannot checkout %s" % package) |
610 |
ovitters |
3559 |
|
611 |
ovitters |
3652 |
# Determine version from spec file |
612 |
|
|
try: |
613 |
|
|
packages[package] = SpecFile(os.path.join(cwd, "SPECS", "%s.spec" % package)).version |
614 |
|
|
except subprocess.CalledProcessError: |
615 |
|
|
raise ValueError("Multiple packages found and cannot determine version of %s" % package) |
616 |
ovitters |
3559 |
|
617 |
ovitters |
3652 |
# Return all packages reflecting the current version |
618 |
|
|
matches = [package for package in packages if packages[package] == version] |
619 |
|
|
if len(matches): |
620 |
|
|
return matches |
621 |
ovitters |
3559 |
|
622 |
ovitters |
3652 |
# Return all packages reflecting the version before the current version |
623 |
|
|
latest_version = get_latest_version(packages.values(), max_version=version) |
624 |
|
|
matches = [package for package in packages if packages[package] == latest_version] |
625 |
|
|
if len(matches): |
626 |
|
|
return matches |
627 |
ovitters |
3559 |
|
628 |
ovitters |
3652 |
# Give up |
629 |
|
|
raise ValueError("Multiple packages found and cannot determine package for version %s" % version) |
630 |
ovitters |
3559 |
|
631 |
ovitters |
3012 |
def write_file(path, data): |
632 |
|
|
with tempfile.NamedTemporaryFile(dir=os.path.dirname(path), delete=False) as fdst: |
633 |
|
|
fdst.write(data) |
634 |
|
|
fdst.flush() |
635 |
|
|
os.rename(fdst.name, path) |
636 |
|
|
|
637 |
ovitters |
2932 |
def cmd_co(options, parser): |
638 |
ovitters |
3502 |
for package, module, package_version, spec_version, downstream_files in sorted(join_streams()): |
639 |
ovitters |
3501 |
print "%s => %s" % (module, package) |
640 |
ovitters |
5287 |
try: |
641 |
|
|
Downstream.co(package) |
642 |
|
|
except subprocess.CalledProcessError: |
643 |
|
|
pass |
644 |
ovitters |
2932 |
|
645 |
ovitters |
3501 |
def join_streams(show_version=False, only_diff_version=False): |
646 |
ovitters |
5287 |
root = os.path.expanduser(Downstream.PKGROOT) |
647 |
ovitters |
2932 |
|
648 |
ovitters |
3649 |
upstream = Upstream().names |
649 |
ovitters |
3650 |
downstream = Downstream() |
650 |
ovitters |
2932 |
|
651 |
ovitters |
3650 |
matches = upstream & set(downstream.tarballs.keys()) |
652 |
ovitters |
2932 |
for module in matches: |
653 |
ovitters |
3650 |
for package in downstream.tarballs[module].keys(): |
654 |
|
|
package_version = downstream.tarballs[module][package] |
655 |
ovitters |
3501 |
spec_version = None |
656 |
|
|
if show_version or only_diff_version: |
657 |
|
|
cwd = os.path.join(root, package) |
658 |
|
|
try: |
659 |
|
|
spec_version = SpecFile(os.path.join(cwd, "SPECS", "%s.spec" % package)).version |
660 |
|
|
except subprocess.CalledProcessError: |
661 |
|
|
spec_version = 'N/A' |
662 |
ovitters |
2932 |
|
663 |
ovitters |
3501 |
if only_diff_version and package_version == spec_version: |
664 |
|
|
continue |
665 |
|
|
|
666 |
ovitters |
3650 |
yield (package, module, package_version, spec_version, downstream.files[package]) |
667 |
ovitters |
3501 |
|
668 |
ovitters |
3114 |
def cmd_ls(options, parser): |
669 |
ovitters |
3653 |
streams = join_streams(show_version=options.show_version, only_diff_version=options.diff) |
670 |
|
|
if options.sort: |
671 |
|
|
SORT=dict(zip(options.sort.read().splitlines(), itertools.count())) |
672 |
|
|
|
673 |
|
|
streams = sorted(streams, key=lambda a: (SORT.get(a[1], 9999), a[0])) |
674 |
|
|
else: |
675 |
|
|
streams = sorted(streams) |
676 |
|
|
|
677 |
|
|
for package, module, package_version, spec_version, downstream_files in streams: |
678 |
ovitters |
3648 |
sys.stdout.write(package) |
679 |
|
|
if options.upstream: sys.stdout.write("\t%s" % module) |
680 |
ovitters |
3649 |
if options.show_version: sys.stdout.write("\t%s\t%s" % (spec_version, package_version)) |
681 |
ovitters |
3501 |
print |
682 |
ovitters |
3114 |
|
683 |
ovitters |
5288 |
def cmd_check_latest(options, parser): |
684 |
|
|
streams = join_streams(show_version=True) |
685 |
|
|
|
686 |
|
|
for package, module, package_version, spec_version, downstream_files in streams: |
687 |
|
|
sys.stdout.write(package) |
688 |
|
|
sys.stdout.write("\t%s\t%s" % (spec_version, package_version)) |
689 |
|
|
|
690 |
|
|
safe_max_version = get_safe_max_version(spec_version) |
691 |
|
|
|
692 |
|
|
versions = Upstream.versions(module) |
693 |
|
|
if versions: |
694 |
|
|
latest_version = get_latest_version(versions) |
695 |
|
|
safe_version = get_latest_version(versions, safe_max_version) |
696 |
|
|
|
697 |
|
|
if version_cmp(latest_version, spec_version) < 0: latest_version = 'N/A' |
698 |
|
|
if version_cmp(safe_version, spec_version) < 0: safe_version = 'N/A' |
699 |
|
|
|
700 |
|
|
sys.stdout.write("\t%s" % latest_version) |
701 |
|
|
sys.stdout.write("\t%s" % safe_version) |
702 |
|
|
print |
703 |
|
|
|
704 |
ovitters |
2932 |
def cmd_patches(options, parser): |
705 |
ovitters |
5287 |
root = os.path.expanduser(Downstream.PKGROOT) |
706 |
ovitters |
2932 |
|
707 |
ovitters |
3502 |
for package, module, package_version, spec_version, downstream_files in sorted(join_streams()): |
708 |
|
|
for filename in downstream_files: |
709 |
|
|
if '.patch' in filename or '.diff' in filename: |
710 |
ovitters |
2932 |
|
711 |
ovitters |
3502 |
p = Patch(os.path.join(root, package, "SOURCES", filename), show_path=options.path) |
712 |
|
|
valid = "" |
713 |
|
|
forwarded = "" |
714 |
|
|
if p.dep3['headers']: |
715 |
|
|
forwarded = p.dep3['headers'].get('Forwarded', "no") |
716 |
|
|
if p.dep3['valid']: |
717 |
|
|
valid="VALID" |
718 |
|
|
print "\t".join((module, package, str(p), forwarded, valid)) |
719 |
ovitters |
2936 |
|
720 |
ovitters |
2944 |
def cmd_dep3(options, parser): |
721 |
|
|
p = Patch(options.patch) |
722 |
|
|
p.add_dep3() |
723 |
|
|
|
724 |
ovitters |
3012 |
def cmd_package_new_version(options, parser): |
725 |
ovitters |
3087 |
# Determine the package name |
726 |
ovitters |
3086 |
if options.upstream: |
727 |
ovitters |
3119 |
try: |
728 |
ovitters |
3652 |
package = Downstream().get_downstream_from_upstream(options.package, options.version)[0] |
729 |
ovitters |
3119 |
except ValueError, e: |
730 |
|
|
print >>sys.stderr, "ERROR: %s" % e |
731 |
ovitters |
3086 |
sys.exit(1) |
732 |
|
|
else: |
733 |
|
|
package = options.package |
734 |
|
|
|
735 |
ovitters |
3087 |
# Directories packages are located in |
736 |
ovitters |
5287 |
root = os.path.expanduser(Downstream.PKGROOT) |
737 |
ovitters |
3044 |
cwd = os.path.join(root, package) |
738 |
ovitters |
3038 |
|
739 |
ovitters |
3087 |
# Checkout package to ensure the checkout reflects the latest changes |
740 |
ovitters |
3044 |
try: |
741 |
ovitters |
5287 |
Downstream.co(package, cwd=root) |
742 |
ovitters |
3044 |
except subprocess.CalledProcessError: |
743 |
|
|
sys.exit(1) |
744 |
ovitters |
3087 |
|
745 |
|
|
# SpecFile class handles the actual version+release change |
746 |
ovitters |
3038 |
s = SpecFile(os.path.join(cwd, "SPECS", "%s.spec" % package)) |
747 |
ovitters |
3037 |
print "%s => %s" % (s.version, options.version) |
748 |
ovitters |
3555 |
if not s.update(options.version, force=options.force): |
749 |
ovitters |
3012 |
sys.exit(1) |
750 |
|
|
|
751 |
ovitters |
3115 |
# Check hash, if given |
752 |
|
|
if options.hexdigest is not None: |
753 |
|
|
sources = [name for name, origname in s.sources.iteritems() if '://' in origname] |
754 |
|
|
if not len(sources): |
755 |
|
|
print >>sys.stderr, "ERROR: Cannot determine source file (for hash check)!" |
756 |
|
|
sys.stderr(1) |
757 |
|
|
|
758 |
|
|
for filename in sources: |
759 |
ovitters |
3597 |
path = os.path.join(cwd, "SOURCES", filename) |
760 |
|
|
if not is_valid_hash(path, options.algo, options.hexdigest): |
761 |
ovitters |
3115 |
print >>sys.stderr, "ERROR: Hash file failed check for %s!" % path |
762 |
|
|
print >>sys.stderr, "ERROR: Reverting changes!" |
763 |
|
|
subprocess.call(['svn', 'revert', '-R', cwd], cwd=cwd) |
764 |
|
|
sys.exit(1) |
765 |
|
|
|
766 |
ovitters |
3654 |
try: |
767 |
|
|
# If we made it this far, checkin the changes |
768 |
|
|
subprocess.check_call(['mgarepo', 'ci', '-m', 'new version %s' % options.version], cwd=cwd) |
769 |
ovitters |
3012 |
|
770 |
ovitters |
3654 |
# Submit is optional |
771 |
|
|
if options.submit: |
772 |
|
|
subprocess.check_call(['mgarepo', 'submit'], cwd=cwd) |
773 |
|
|
except subprocess.CalledProcessError: |
774 |
|
|
sys.exit(1) |
775 |
|
|
|
776 |
ovitters |
3119 |
def cmd_parse_ftp_release_list(options, parser): |
777 |
ovitters |
3596 |
def _send_reply_mail(contents, orig_msg, to, packages=[], error=False): |
778 |
ovitters |
3119 |
"""Send an reply email""" |
779 |
|
|
contents.seek(0) |
780 |
|
|
msg = MIMEText(contents.read(), _charset='utf-8') |
781 |
ovitters |
3596 |
|
782 |
ovitters |
3384 |
if error: |
783 |
|
|
# XXX - ugly |
784 |
|
|
contents.seek(0) |
785 |
ovitters |
3567 |
lastline = contents.read().rstrip().splitlines()[-1] |
786 |
ovitters |
3384 |
# Remove things like "ERROR: " and so on from the last line |
787 |
|
|
lastline = re.sub(r'^(?:[^ :]+:\s+)+', '', lastline) |
788 |
ovitters |
3570 |
# Remove things like " - " (youri output from mgarepo submit) |
789 |
|
|
lastline = re.sub(r'^\s+-\s+', '', lastline) |
790 |
ovitters |
3397 |
subjecterror = " (ERROR: %s)" % lastline if lastline else " (ERROR)" |
791 |
ovitters |
3384 |
else: |
792 |
|
|
subjecterror = "" |
793 |
ovitters |
3596 |
|
794 |
|
|
if packages: |
795 |
|
|
subject = "%s %s%s" % (", ".join(packages), orig_msg['X-Module-Version'], subjecterror) |
796 |
|
|
else: |
797 |
|
|
subject = "Re: %s%s" % (orig_msg['Subject'], subjecterror) |
798 |
|
|
|
799 |
|
|
msg['Subject'] = subject |
800 |
ovitters |
3119 |
msg['To'] = to |
801 |
|
|
msg["In-Reply-To"] = orig_msg["Message-ID"] |
802 |
|
|
msg["References"] = orig_msg["Message-ID"] |
803 |
ovitters |
3038 |
|
804 |
ovitters |
3119 |
# Call sendmail program directly so it doesn't matter if the service is running |
805 |
|
|
cmd = ['/usr/sbin/sendmail', '-oi', '--'] |
806 |
|
|
cmd.extend([to]) |
807 |
|
|
p = subprocess.Popen(cmd, stdin=subprocess.PIPE) |
808 |
|
|
p.stdin.write(msg.as_string()) |
809 |
|
|
p.stdin.flush() |
810 |
|
|
p.stdin.close() |
811 |
|
|
p.wait() |
812 |
|
|
|
813 |
|
|
|
814 |
|
|
msg = email.email.message_from_file(sys.stdin) |
815 |
|
|
|
816 |
|
|
if options.mail: |
817 |
ovitters |
3176 |
stdout = tempfile.TemporaryFile() |
818 |
ovitters |
3119 |
stderr = stdout |
819 |
|
|
else: |
820 |
|
|
stdout = sys.stdout |
821 |
|
|
stderr = sys.stderr |
822 |
|
|
|
823 |
|
|
try: |
824 |
|
|
module = msg['X-Module-Name'] |
825 |
|
|
version = msg['X-Module-Version'] |
826 |
|
|
hexdigest = msg['X-Module-SHA256-tar.xz'] |
827 |
|
|
except KeyError, e: |
828 |
|
|
print >>stderr, "ERROR: %s" % e |
829 |
ovitters |
3180 |
if options.mail: _send_reply_mail(stdout, msg, options.mail, error=True) |
830 |
ovitters |
3119 |
sys.exit(1) |
831 |
|
|
|
832 |
|
|
try: |
833 |
ovitters |
3652 |
packages = Downstream().get_downstream_from_upstream(module, version) |
834 |
ovitters |
3119 |
except ValueError, e: |
835 |
|
|
print >>stderr, "ERROR: %s" % e |
836 |
ovitters |
3180 |
if options.mail: _send_reply_mail(stdout, msg, options.mail, error=True) |
837 |
ovitters |
3119 |
sys.exit(1) |
838 |
|
|
|
839 |
ovitters |
3120 |
if options.wait: |
840 |
ovitters |
3122 |
# maildrop aborts and will try to deliver after 5min |
841 |
|
|
# fork to avoid this |
842 |
|
|
if os.fork() != 0: sys.exit(0) |
843 |
ovitters |
3556 |
# wait SLEEP_INITIAL after the message was sent |
844 |
|
|
secs = SLEEP_INITIAL |
845 |
|
|
t = email.utils.parsedate_tz(msg['Date']) |
846 |
|
|
if t is not None: |
847 |
|
|
msg_time = email.utils.mktime_tz(t) |
848 |
|
|
secs = SLEEP_INITIAL - (time.time() - msg_time) |
849 |
ovitters |
3120 |
|
850 |
ovitters |
3556 |
if secs > 0: time.sleep(secs) |
851 |
|
|
|
852 |
ovitters |
3180 |
error = False |
853 |
ovitters |
3119 |
for package in packages: |
854 |
ovitters |
3654 |
cmd = ['mga-gnome', 'increase', '--hash', hexdigest] |
855 |
|
|
if options.submit: |
856 |
|
|
cmd.append('--submit') |
857 |
ovitters |
3561 |
if options.force: |
858 |
|
|
cmd.append('--force') |
859 |
|
|
cmd.extend((package, version)) |
860 |
|
|
if subprocess.call(cmd, stdout=stdout, stderr=stderr): |
861 |
ovitters |
3180 |
error = True |
862 |
ovitters |
3119 |
|
863 |
ovitters |
3596 |
if options.mail: _send_reply_mail(stdout, msg, options.mail, packages=packages, error=error) |
864 |
ovitters |
3119 |
|
865 |
ovitters |
2932 |
def main(): |
866 |
|
|
description = """Mageia GNOME commands.""" |
867 |
|
|
epilog="""Report bugs to Olav Vitters""" |
868 |
|
|
parser = argparse.ArgumentParser(description=description,epilog=epilog) |
869 |
ovitters |
3649 |
parser.add_argument("-l", "--limit", type=argparse.FileType('r', 0), |
870 |
|
|
dest="limit_upstream", metavar="FILE", |
871 |
|
|
help="File containing upstream names") |
872 |
ovitters |
5287 |
parser.add_argument("-d", "--distro", action="store", dest="distro", |
873 |
|
|
help="Distribution release") |
874 |
ovitters |
2932 |
|
875 |
|
|
# SUBPARSERS |
876 |
|
|
subparsers = parser.add_subparsers(title='subcommands') |
877 |
|
|
# install |
878 |
|
|
subparser = subparsers.add_parser('co', help='checkout all GNOME modules') |
879 |
|
|
subparser.set_defaults( |
880 |
|
|
func=cmd_co |
881 |
|
|
) |
882 |
|
|
|
883 |
|
|
subparser = subparsers.add_parser('packages', help='list all GNOME packages') |
884 |
ovitters |
3114 |
subparser.add_argument("-m", "--m", action="store_true", dest="upstream", |
885 |
|
|
help="Show upstream module") |
886 |
ovitters |
3501 |
subparser.add_argument( "--version", action="store_true", dest="show_version", |
887 |
|
|
help="Show version numbers") |
888 |
|
|
subparser.add_argument( "--diff", action="store_true", dest="diff", |
889 |
|
|
help="Only show packages with different version") |
890 |
ovitters |
3653 |
subparser.add_argument( "--sort", type=argparse.FileType('r', 0), |
891 |
|
|
dest="sort", metavar="FILE", |
892 |
|
|
help="Sort packages according to order in given FILE") |
893 |
|
|
|
894 |
ovitters |
2932 |
subparser.set_defaults( |
895 |
ovitters |
3501 |
func=cmd_ls, upstream=False, show_version=False, diff=False |
896 |
ovitters |
2932 |
) |
897 |
|
|
|
898 |
ovitters |
5288 |
subparser = subparsers.add_parser('check-latest', help='check for latest version of packages') |
899 |
|
|
subparser.set_defaults( |
900 |
|
|
func=cmd_check_latest |
901 |
|
|
) |
902 |
|
|
|
903 |
ovitters |
2932 |
subparser = subparsers.add_parser('patches', help='list all GNOME patches') |
904 |
|
|
subparser.add_argument("-p", "--path", action="store_true", dest="path", |
905 |
ovitters |
2944 |
help="Show full path to patch") |
906 |
ovitters |
2932 |
subparser.set_defaults( |
907 |
|
|
func=cmd_patches, path=False |
908 |
|
|
) |
909 |
|
|
|
910 |
ovitters |
2944 |
subparser = subparsers.add_parser('dep3', help='Add dep3 headers') |
911 |
|
|
subparser.add_argument("patch", help="Patch") |
912 |
|
|
subparser.set_defaults( |
913 |
|
|
func=cmd_dep3, path=False |
914 |
|
|
) |
915 |
ovitters |
2932 |
|
916 |
ovitters |
3012 |
subparser = subparsers.add_parser('increase', help='Increase version number') |
917 |
|
|
subparser.add_argument("package", help="Package name") |
918 |
|
|
subparser.add_argument("version", help="Version number") |
919 |
ovitters |
3555 |
subparser.add_argument("-f", "--force", action="store_true", dest="force", |
920 |
|
|
help="Override warnings, just do it") |
921 |
ovitters |
3086 |
subparser.add_argument("-u", "--upstream", action="store_true", dest="upstream", |
922 |
|
|
help="Package name reflects the upstream name") |
923 |
ovitters |
3038 |
subparser.add_argument("-s", "--submit", action="store_true", dest="submit", |
924 |
|
|
help="Commit changes and submit") |
925 |
ovitters |
3115 |
subparser.add_argument("-a", "--algorithm", choices=hashlib.algorithms, dest="algo", |
926 |
|
|
help="Hash algorithm") |
927 |
|
|
subparser.add_argument("--hash", dest="hexdigest", |
928 |
|
|
help="Hexdigest of the hash") |
929 |
ovitters |
3012 |
subparser.set_defaults( |
930 |
ovitters |
5095 |
func=cmd_package_new_version, submit=True, upstream=False, hexdigest=None, algo="sha256", |
931 |
ovitters |
3555 |
force=False |
932 |
ovitters |
3012 |
) |
933 |
|
|
|
934 |
ovitters |
3119 |
subparser = subparsers.add_parser('gnome-release-email', help='Submit packages based on GNOME ftp-release-list email') |
935 |
|
|
subparser.add_argument("-m", "--mail", help="Email address to send the progress to") |
936 |
ovitters |
3120 |
subparser.add_argument("-w", "--wait", action="store_true", |
937 |
|
|
help="Wait before trying to retrieve the new version") |
938 |
ovitters |
3654 |
subparser.add_argument("-s", "--submit", action="store_true", dest="submit", |
939 |
|
|
help="Commit changes and submit") |
940 |
ovitters |
3561 |
subparser.add_argument("-f", "--force", action="store_true", |
941 |
|
|
help="Force submission") |
942 |
ovitters |
3119 |
subparser.set_defaults( |
943 |
ovitters |
3561 |
func=cmd_parse_ftp_release_list, force=False, wait=False |
944 |
ovitters |
3119 |
) |
945 |
|
|
|
946 |
ovitters |
2932 |
if len(sys.argv) == 1: |
947 |
|
|
parser.print_help() |
948 |
|
|
sys.exit(2) |
949 |
|
|
|
950 |
|
|
options = parser.parse_args() |
951 |
ovitters |
3649 |
if options.limit_upstream: |
952 |
|
|
Upstream.limit = set(options.limit_upstream.read().strip("\n").splitlines()) |
953 |
ovitters |
2932 |
|
954 |
ovitters |
5287 |
if options.distro: |
955 |
|
|
Downstream.PKGROOT = os.path.join('~/pkgs', options.distro) |
956 |
|
|
Downstream.MEDIA = "Core Release %s Source" % options.distro |
957 |
|
|
Downstream.DISTRO = options.distro |
958 |
|
|
|
959 |
ovitters |
2932 |
try: |
960 |
|
|
options.func(options, parser) |
961 |
|
|
except KeyboardInterrupt: |
962 |
|
|
print('Interrupted') |
963 |
|
|
sys.exit(1) |
964 |
|
|
except EOFError: |
965 |
|
|
print('EOF') |
966 |
|
|
sys.exit(1) |
967 |
|
|
except IOError, e: |
968 |
|
|
if e.errno != errno.EPIPE: |
969 |
|
|
raise |
970 |
|
|
sys.exit(0) |
971 |
|
|
|
972 |
|
|
if __name__ == "__main__": |
973 |
ovitters |
3567 |
os.environ['PYTHONUNBUFFERED'] = '1' |
974 |
ovitters |
2932 |
main() |