#!/usr/bin/python2.5 """ Copyright (C) 2008 Norman Messtorff This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. """ import time import urllib import bz2 from Configuration import Configuration class Download(Configuration): """Class with methodes to download files via http""" # TODO: autom. trying to download .bz2, gzip and at least plain... def __init__(self): self.debug(4, "Class Download initialized") def get_packages(self, destination, release, component, arch): """Download and decompress Packages file from a given Debian mirror - source: HTTP URL on Debian mirror - destination: the destination filename""" # TODO: Doing some _nice_ and HTTP compatible stuff # TODO: release? arch? ubuntu? other distri? # TODO: Download Release file # TODO: check GPG signature self.debug(3, "Downloading Packages...") url=self.config["compare"]["packages_url"] packages = urllib.urlopen( url + "dists/" + release + "/" + component + "/binary-" + arch + "/Packages.bz2").read() try: self.debug(3, "Decompressing...") self.debug(4, "Open file(w): " + destination) f=file(destination, 'w') f.write(bz2.decompress(packages)) f.close() except: self.debug(1, "Could not Open file: " + destination) return 1 self.debug(3, "Packages saved.") return 0