From 3ace8ceb2343621ada4a72fc60e8e03a570fd389 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Wed, 22 Jun 2011 14:39:50 -0500 Subject: pactest: make pmfile a bit more pythonic Signed-off-by: Dan McGee --- test/pacman/pmfile.py | 24 +++++++++++++++--------- test/pacman/pmtest.py | 2 +- test/pacman/util.py | 13 ------------- 3 files changed, 16 insertions(+), 23 deletions(-) (limited to 'test') diff --git a/test/pacman/pmfile.py b/test/pacman/pmfile.py index bd03a24e..638b451e 100644 --- a/test/pacman/pmfile.py +++ b/test/pacman/pmfile.py @@ -17,38 +17,44 @@ import os +import stat import util -class pmfile(object): +class PacmanFile(object): """File object """ def __init__(self, root, name): - self.name = name self.root = root + self.name = name self.filename = os.path.join(self.root, self.name) self.checksum = util.getmd5sum(self.filename) - self.mtime = util.getmtime(self.filename) + self.mtime = self.getmtime() def __str__(self): return "%s (%s / %lu)" % (self.name, self.checksum, self.mtime) + def getmtime(self): + if not os.path.exists(self.filename): + return None, None + statbuf = os.lstat(self.filename) + return (statbuf[stat.ST_MTIME], statbuf[stat.ST_CTIME]) + def ismodified(self): - """ - """ checksum = util.getmd5sum(self.filename) - mtime = util.getmtime(self.filename) + mtime = self.getmtime() util.vprint("\tismodified(%s)" % self.name) util.vprint("\t\told: %s / %s" % (self.checksum, self.mtime)) util.vprint("\t\tnew: %s / %s" % (checksum, mtime)) if self.checksum != checksum \ - or (self.mtime[1], self.mtime[2]) != (mtime[1], mtime[2]): - return 1 + or self.mtime[0] != mtime[0] \ + or self.mtime[1] != mtime[1]: + return True - return 0 + return False # vim: set ts=4 sw=4 et: diff --git a/test/pacman/pmtest.py b/test/pacman/pmtest.py index 64e56da7..105a841c 100644 --- a/test/pacman/pmtest.py +++ b/test/pacman/pmtest.py @@ -188,7 +188,7 @@ class pmtest(object): for roots, dirs, files in os.walk(self.root): for i in files: filename = os.path.join(roots, i) - f = pmfile.pmfile(self.root, filename.replace(self.root + "/", "")) + f = pmfile.PacmanFile(self.root, filename.replace(self.root + "/", "")) self.files.append(f) vprint("\t%s" % f.name) diff --git a/test/pacman/util.py b/test/pacman/util.py index bc8e3500..f971afd1 100644 --- a/test/pacman/util.py +++ b/test/pacman/util.py @@ -19,7 +19,6 @@ import os import re import hashlib -import stat # ALPM @@ -156,18 +155,6 @@ def mkmd5sum(data): return checksum.hexdigest() -# -# Mtime helpers -# - -def getmtime(filename): - """ - """ - if not os.path.exists(filename): - return None, None, None - st = os.lstat(filename) - return st[stat.ST_ATIME], st[stat.ST_MTIME], st[stat.ST_CTIME] - # # Miscellaneous # -- cgit v1.2.3-70-g09d2