[Piuparts-commits] [SCM] piuparts git repository branch, master, updated. 0.51

David Steele dsteele at gmail.com
Wed May 15 10:09:34 UTC 2013


The following commit has been merged in the master branch:
commit 13cd7eddb058c82692443c6157948e5cd829f7bd
Author: David Steele <dsteele at gmail.com>
Date:   Wed Jan 9 21:17:02 2013 -0500

    detect_well_known_errors.py - Add class for handling known problems.

diff --git a/master-bin/detect_well_known_errors.py b/master-bin/detect_well_known_errors.py
index 63ff5e4..1b066d6 100755
--- a/master-bin/detect_well_known_errors.py
+++ b/master-bin/detect_well_known_errors.py
@@ -4,6 +4,8 @@ import ConfigParser
 import piupartslib
 import os
 import time
+import re
+import subprocess
 
 CONFIG_FILE = "/etc/piuparts/piuparts.conf"
 KPR_DIRS = ( 'pass', 'bugged', 'affected', 'fail' )
@@ -23,8 +25,45 @@ class WKE_Config( piupartslib.conf.Config ):
             {
                 "sections": "sid",
                 "master-directory": "/var/lib/piuparts/master/",
+                "known-problem-directory": "/usr/share/piuparts/known_problems",
             }, "" )
 
+class Problem():
+    """ Encapsulate a particular known problem """
+
+    def __init__(self, probpath):
+        """probpath is the path to the problem definition file"""
+
+        self.probpath = probpath
+        self.name = os.path.basename(probpath)
+        self.short_name = os.path.splitext( self.name )[0]
+
+        self.init_problem()
+
+    def init_problem(self):
+        """Load problem file parameters (HELPTEXT="foo" -> self.HELPTEXT)"""
+
+        pb = open( self.probpath, 'r' )
+        probbody = pb.read()
+        pb.close()
+
+        tagged = re.sub( "^([A-Z]+=)", "<hdr>\g<0>", probbody, 0, re.MULTILINE)
+
+        for chub in re.split( '<hdr>', tagged )[1:]:
+
+            (name,value) = re.split( "=", chub, 1, re.MULTILINE )
+
+            while value[-1] == '\n':
+                value = value[:-1]
+
+            if  re.search( "^\'.+\'$", value, re.MULTILINE|re.DOTALL ) \
+             or re.search( '^\".+\"$', value, re.MULTILINE|re.DOTALL ):
+                value = value[1:-1]
+
+            self.__dict__[name] = value
+
+        self.WHERE = self.WHERE.split(" ")
+
 def get_where( logpath ):
     """Convert a path to a log file to the 'where' component (e.g. 'pass')"""
     return( logpath.split('/')[-2] )
@@ -65,7 +104,7 @@ def clean_cache_files( logdict, cachedict, skipnewer=False ):
 
     return( count )
 
-def process_section( section, config ):
+def process_section( section, config, problem_list ):
     """ Update .bug and .kpr files for logs in this section """
 
     sectiondir = os.path.join( config['master-directory'], section )
@@ -82,19 +121,28 @@ def process_section( section, config ):
     del_cnt = clean_cache_files( logdict, kprdict )
     clean_cache_files( logdict, bugdict, True )
 
-def detect_well_known_errors( config ):
+def detect_well_known_errors( config, problem_list ):
 
     for section in config['sections'].split(" "):
         print time.strftime( "%a %b %2d %H:%M:%S %Z %Y", time.localtime() )
         print "%s:" % section
 
-        process_section( section, config )
+        process_section( section, config, problem_list )
 
     print time.strftime( "%a %b %2d %H:%M:%S %Z %Y", time.localtime() )
 
+def create_problem_list( pdir ):
+
+    pfiles = [x for x in sorted(os.listdir(pdir)) if x.endswith(".conf")]
+    plist = [Problem(os.path.join(pdir,x)) for x in pfiles]
+
+    return plist
+
 if __name__ == '__main__':
 
     conf = WKE_Config()
     conf.read( CONFIG_FILE )
 
-    detect_well_known_errors( conf )
+    problem_list = create_problem_list( conf['known-problem-directory'] )
+
+    detect_well_known_errors( conf, problem_list )

-- 
piuparts git repository



More information about the Piuparts-commits mailing list