[Piuparts-commits] [SCM] piuparts git repository branch, master, updated. 0.51
David Steele
dsteele at gmail.com
Wed May 15 10:09:33 UTC 2013
The following commit has been merged in the master branch:
commit 032bca36c03cd78cb91cfee1121a8bdbb7f678fd
Author: David Steele <dsteele at gmail.com>
Date: Wed Jan 9 20:53:07 2013 -0500
detect_well_known_errors.py - Clean obsolete kpr and bug files.
diff --git a/master-bin/detect_well_known_errors.py b/master-bin/detect_well_known_errors.py
index 95742c9..63ff5e4 100755
--- a/master-bin/detect_well_known_errors.py
+++ b/master-bin/detect_well_known_errors.py
@@ -11,6 +11,7 @@ KPR_DIRS = ( 'pass', 'bugged', 'affected', 'fail' )
# tmp-use new extensions, so python script can be developed alongside the bash
KPR_EXT = '.kprn'
BUG_EXT = '.bug'
+LOG_EXT = '.log'
class WKE_Config( piupartslib.conf.Config ):
"""Configuration parameters for Well Known Errors"""
@@ -24,6 +25,46 @@ class WKE_Config( piupartslib.conf.Config ):
"master-directory": "/var/lib/piuparts/master/",
}, "" )
+def get_where( logpath ):
+ """Convert a path to a log file to the 'where' component (e.g. 'pass')"""
+ return( logpath.split('/')[-2] )
+
+def get_file_dict( workdirs, ext ):
+ """For files in [workdirs] with extension 'ext', create a dict of
+ <pkgname>_<version>: <path>"""
+
+ filedict = {}
+
+ for dir in workdirs:
+ for fl in os.listdir(dir):
+ if os.path.splitext(fl)[1] == ext:
+ filedict[os.path.splitext(os.path.basename(fl))[0]] \
+ = os.path.join(dir,fl)
+
+ return filedict
+
+def mtime( path ):
+ return os.path.getmtime(path)
+
+def clean_cache_files( logdict, cachedict, skipnewer=False ):
+ """Delete files in cachedict if the corresponding logdict file is missing
+ or newer"""
+
+ count = 0
+ for pkgspec in cachedict:
+ if pkgspec not in logdict \
+ or (mtime(logdict[pkgspec]) > mtime(cachedict[pkgspec])
+ and not skipnewer) \
+ or get_where(logdict[pkgspec]) != get_where(cachedict[pkgspec]):
+
+ try:
+ os.remove(cachedict[pkgspec])
+ count = count + 1
+ except OSError:
+ print "Error deleting %s" % cachedict[pkgspec]
+
+ return( count )
+
def process_section( section, config ):
""" Update .bug and .kpr files for logs in this section """
@@ -35,6 +76,12 @@ def process_section( section, config ):
[os.mkdir(x) for x in workdirs if not os.path.exists(x)]
+ (logdict, kprdict, bugdict) = [ get_file_dict(workdirs, x ) \
+ for x in [LOG_EXT, KPR_EXT, BUG_EXT] ]
+
+ del_cnt = clean_cache_files( logdict, kprdict )
+ clean_cache_files( logdict, bugdict, True )
+
def detect_well_known_errors( config ):
for section in config['sections'].split(" "):
--
piuparts git repository
More information about the Piuparts-commits
mailing list