1 |
#!/usr/bin/python |
#!/usr/bin/python |
2 |
|
|
3 |
|
# 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 |
import os |
import os |
9 |
import os.path |
import os.path |
10 |
import sys |
import sys |
11 |
import re |
import re |
12 |
import subprocess |
import subprocess |
13 |
import urllib2 |
|
14 |
import urlparse |
# command line parsing, error handling: |
15 |
import argparse |
import argparse |
16 |
import errno |
import errno |
17 |
|
|
18 |
|
# overwriting files by moving them (safer): |
19 |
import tempfile |
import tempfile |
20 |
import shutil |
import shutil |
21 |
|
|
22 |
|
# version comparison: |
23 |
import rpm |
import rpm |
24 |
|
|
25 |
|
# opening tarballs: |
26 |
|
import tarfile |
27 |
|
import gzip |
28 |
|
import bz2 |
29 |
|
import lzma # pyliblzma |
30 |
|
|
31 |
|
# getting links from HTML document: |
32 |
from sgmllib import SGMLParser |
from sgmllib import SGMLParser |
33 |
|
import urllib2 |
34 |
|
import urlparse |
35 |
|
|
36 |
MEDIA="Core Release Source" |
MEDIA="Core Release Source" |
37 |
URL="http://download.gnome.org/sources/" |
URL="http://download.gnome.org/sources/" |
103 |
if href: |
if href: |
104 |
self.urls.extend(href) |
self.urls.extend(href) |
105 |
|
|
106 |
|
class XzTarFile(tarfile.TarFile): |
107 |
|
|
108 |
|
OPEN_METH = tarfile.TarFile.OPEN_METH.copy() |
109 |
|
OPEN_METH["xz"] = "xzopen" |
110 |
|
|
111 |
|
@classmethod |
112 |
|
def xzopen(cls, name, mode="r", fileobj=None, **kwargs): |
113 |
|
"""Open gzip compressed tar archive name for reading or writing. |
114 |
|
Appending is not allowed. |
115 |
|
""" |
116 |
|
if len(mode) > 1 or mode not in "rw": |
117 |
|
raise ValueError("mode must be 'r' or 'w'") |
118 |
|
|
119 |
|
if fileobj is not None: |
120 |
|
fileobj = _LMZAProxy(fileobj, mode) |
121 |
|
else: |
122 |
|
fileobj = lzma.LZMAFile(name, mode) |
123 |
|
|
124 |
|
try: |
125 |
|
# lzma doesn't immediately return an error |
126 |
|
# try and read a bit of data to determine if it is a valid xz file |
127 |
|
fileobj.read(_LZMAProxy.blocksize) |
128 |
|
fileobj.seek(0) |
129 |
|
t = cls.taropen(name, mode, fileobj, **kwargs) |
130 |
|
except IOError: |
131 |
|
raise tarfile.ReadError("not a xz file") |
132 |
|
except lzma.error: |
133 |
|
raise tarfile.ReadError("not a xz file") |
134 |
|
t._extfileobj = False |
135 |
|
return t |
136 |
|
|
137 |
|
if not hasattr(tarfile.TarFile, 'xvopen'): |
138 |
|
tarfile.open = XzTarFile.open |
139 |
|
|
140 |
class SpecFile(object): |
class SpecFile(object): |
141 |
re_update_version = re.compile(r'^(?P<pre>Version:\s*)(?P<version>.+)(?P<post>\s*)$', re.MULTILINE + re.IGNORECASE) |
re_update_version = re.compile(r'^(?P<pre>Version:\s*)(?P<version>.+)(?P<post>\s*)$', re.MULTILINE + re.IGNORECASE) |
142 |
re_update_release = re.compile(r'^(?P<pre>Release:\s*)(?P<release>%mkrel \d+)(?P<post>\s*)$', re.MULTILINE + re.IGNORECASE) |
re_update_release = re.compile(r'^(?P<pre>Release:\s*)(?P<release>%mkrel \d+)(?P<post>\s*)$', re.MULTILINE + re.IGNORECASE) |