--- mga-gnome/trunk/mga-gnome 2012/02/24 12:26:02 3045 +++ mga-gnome/trunk/mga-gnome 2012/02/25 19:58:52 3057 @@ -1,18 +1,37 @@ #!/usr/bin/python +# A lot of the code comes from ftpadmin, see +# http://git.gnome.org/browse/sysadmin-bin/tree/ftpadmin +# Written by Olav Vitters + +# basic modules: import os import os.path import sys import re import subprocess -import urllib2 -import urlparse + +# command line parsing, error handling: import argparse import errno + +# overwriting files by moving them (safer): import tempfile import shutil + +# version comparison: import rpm + +# opening tarballs: +import tarfile +import gzip +import bz2 +import lzma # pyliblzma + +# getting links from HTML document: from sgmllib import SGMLParser +import urllib2 +import urlparse MEDIA="Core Release Source" URL="http://download.gnome.org/sources/" @@ -84,6 +103,40 @@ if href: self.urls.extend(href) +class XzTarFile(tarfile.TarFile): + + OPEN_METH = tarfile.TarFile.OPEN_METH.copy() + OPEN_METH["xz"] = "xzopen" + + @classmethod + def xzopen(cls, name, mode="r", fileobj=None, **kwargs): + """Open gzip compressed tar archive name for reading or writing. + Appending is not allowed. + """ + if len(mode) > 1 or mode not in "rw": + raise ValueError("mode must be 'r' or 'w'") + + if fileobj is not None: + fileobj = _LMZAProxy(fileobj, mode) + else: + fileobj = lzma.LZMAFile(name, mode) + + try: + # lzma doesn't immediately return an error + # try and read a bit of data to determine if it is a valid xz file + fileobj.read(_LZMAProxy.blocksize) + fileobj.seek(0) + t = cls.taropen(name, mode, fileobj, **kwargs) + except IOError: + raise tarfile.ReadError("not a xz file") + except lzma.error: + raise tarfile.ReadError("not a xz file") + t._extfileobj = False + return t + +if not hasattr(tarfile.TarFile, 'xvopen'): + tarfile.open = XzTarFile.open + class SpecFile(object): re_update_version = re.compile(r'^(?P
Version:\s*)(?P.+)(?P\s*)$', re.MULTILINE + re.IGNORECASE)
     re_update_release = re.compile(r'^(?P
Release:\s*)(?P%mkrel \d+)(?P\s*)$', re.MULTILINE + re.IGNORECASE)