From 73db2d5b857380001ff672f4d85fd2744c1d086b Mon Sep 17 00:00:00 2001 From: Anders Blomdell <anders.blomdell@control.lth.se> Date: Tue, 28 Aug 2007 13:47:25 +0100 Subject: [PATCH] Version 2007-08-28 14:47 --- src/mio/exception.py | 8 +++++++- src/mio/filecache.py | 18 ++++++++++++++---- src/mio/installer.py | 9 +++++++-- src/mio/yum.py | 4 ++-- 4 files changed, 30 insertions(+), 9 deletions(-) diff --git a/src/mio/exception.py b/src/mio/exception.py index 94e2328..b831988 100755 --- a/src/mio/exception.py +++ b/src/mio/exception.py @@ -89,7 +89,13 @@ class CircularDependencyException(MioException): MioException.__init__(self, "Circular declaration", detail) - +class NonLocalPath(Exception): + def __init__(self, path): + self.path = path + + def __str__(self): + return "Non local path %s" % self.path + def Report(err, decl, action=None): traceback.print_exc() message = "%s:%s" % (decl._url, decl._line) diff --git a/src/mio/filecache.py b/src/mio/filecache.py index 201b8a0..8838d48 100755 --- a/src/mio/filecache.py +++ b/src/mio/filecache.py @@ -1,11 +1,14 @@ import atexit +import calendar import os import os.path import re import sys import tempfile -import urllib +import time +import urllib2 import urlparse +import mio.exception def join(elements): """join and normalize elements to a proper (url) path""" @@ -69,11 +72,18 @@ def loadfile(path): if file: cache[name] = file else: + u = urllib2.urlopen(name) f = createfile() - u = urllib.urlopen(name) f.write(u.read()) u.close() f.close() + try: + modified = u.info()["Last-Modified"] + mtime = calendar.timegm( + time.strptime(modified, "%a, %d %b %Y %H:%M:%S %Z")) + os.utime(f.name, (mtime, mtime)) + except: + pass cache[name] = f.name return cache[name] @@ -90,13 +100,13 @@ def locatefile(path): if file: cache[name] = file else: - raise Exception("File is not local") + raise mio.exception.NonLocalPath(join(path)) return cache[name] def locatedir(path): dir = getfile(join(path)) if not dir: - raise Exception("Dir is not local") + raise mio.exception.NonLocalPath(join(path)) return dir diff --git a/src/mio/installer.py b/src/mio/installer.py index 8d70f2f..8d05d5c 100755 --- a/src/mio/installer.py +++ b/src/mio/installer.py @@ -105,8 +105,12 @@ class Installer: def add_rpm(self, rpm): - dir = mio.filecache.locatefile([ os.path.dirname(rpm.decl._url), - rpm.decl.rpms[0:] ]) + try: + dir = mio.filecache.locatedir([ os.path.dirname(rpm.decl._url), + rpm.decl.rpms[0:] ]) + except mio.exception.NonLocalPath, e: + dir = e.path + if not dir in self.rpmdir: self.rpmdir.append(dir) if rpm in self.rpm: @@ -149,6 +153,7 @@ class Installer: rpm.append(r.name) rpm.sort() mio.yum.run(path + self.rpmdir, rpm) + #mio.yum.run(self.rpmdir, rpm) version_db = mio.rpmDB.VersionDB() for r in self.rpm: r.new_version = version_db[r.name] diff --git a/src/mio/yum.py b/src/mio/yum.py index 78c0245..ab9d34e 100755 --- a/src/mio/yum.py +++ b/src/mio/yum.py @@ -18,7 +18,7 @@ def newest_rpm(name): def yumdir(path): result = [] for d in path: - header_date = 0 + repo_date = 0 try: file = mio.filecache.loadfile([ d, 'repodata/repomd.xml' ]) if os.path.exists(file): @@ -29,7 +29,7 @@ def yumdir(path): except IOError: pass - repo_date = 0 + header_date = 0 try: file = mio.filecache.loadfile([ d, 'headers/header.info' ]) if os.path.exists(file): -- GitLab