Commits

Wang Dingwei committed 85dbd84

fixed sdr/gcf coexist issue

Comments (0)

Files changed (4)

 from wistron.sdrparser2 import SDR
 from wistron.oietables import AppTable, OsTable, WhiteList
 
-VERSION = '12.1'
+VERSION = '13.0'
 CONFIG_FILE = 'settings.ini'
 LOGDIR = 'LOGS'
 LOG = 'LOGS\\orderfilter.log'
         
     def match(self, order):
         "Returns a match object if matched, else None."
-        ordername = os.path.split(order.filepath)[1]
-        if (order.model() not in self.models or    # Not ODM model
-            order.ostype2() == 'UBX' or    # Ubuntu
-            order.ostype2() == 'NOS' or    # NOS/FreeDOS
-            order.shipmode() in self.exclude): # Excluded order types
+        if (order.model not in self.models or    # Not ODM model
+            order.ostype2 == 'UBX' or    # Ubuntu
+            order.ostype2 == 'NOS' or    # NOS/FreeDOS
+            (order.shipmode != '' and order.shipmode in self.exclude)):
             return None
-        sdr = SDR(order.sdrlines())
+        sdr = SDR(order.sdrlines)
         # compare with OS mapping table
         if not self.os_table.matches(sdr):
             e = "Unsupported OS type."
 
     if order.type == "GCF":
     # Remove db item if exists.
-        session.query(Order).filter(Order.po==order.po()).delete()
+        session.query(Order).filter(Order.po==order.po).delete()
         session.commit()
         # Report to web service
         if cfg.report_cfg.toweb:
             this_rule = session.merge(Rule(match.name, match.message, None))
             session.commit()
         
-        session.merge(Order(order.po(), this_rule.id))
+        session.merge(Order(order.po, this_rule.id))
         session.commit()
         
         # Report to web service
 import os
 import sys
 import glob
+from fnmatch import fnmatch
 from time import sleep
 
-from wistron.gcf import GCF
-from wistron.sdrparser2 import SDRError
+from wistron.gcf import GCF, GCFError
+from wistron.sdrparser2 import SDR2, SDRError
 
 from config import cfg, VERSION, MatchObj
 from reporter import report_failed
 from operations import pass_process, fail_process
 
+
+def multiglob(path, globs=[]):
+    "glob with multiple criterias. "
+    filepaths = []
+    for g in globs:
+        filepaths.extend(glob.glob(os.path.join(path, g)))
+    return filepaths
+
+
 class Invalid:
     """An adapter class or invalid XML files, used in fail_process()"""
-    def __init__(self, xml):
-        self.filepath = xml
+    def __init__(self, filepath):
+        self.filepath = filepath
+        if fnmatch(filepath, '*.xml'):
+            self.type = 'GCF'
+        elif fnmatch(filepath, '*.txt') or fnmatch(filepath, '*.sdr'):
+            self.type = 'SDR'
+        else:
+            self.type = ''
 
 
 class OrderError(Exception):
 
 
 class Order(object):
+    "Adapter for GCF and SDR"
     def __init__(self, order):
         if fnmatch(order, '*.xml'):
             self.type = 'GCF'
                 self.obj = GCF(order)
             except GCFError, e:
                 raise OrderError(e)
+            self.po = self.obj.po
         elif fnmatch(order, '*.sdr') or fnmatch(order, "*.txt"):
-            self.type = SDR
+            self.type = "SDR"
             self.filepath = order
             try:
-                self.obj = SDR(order)
+                self.obj = SDR2(order)
             except SDRError, e:
                 raise OrderError(e)
         else:
             raise OrderError("Unknown order type")
+    def sdrlines(self):
+        if self.type == 'GCF':
+            return self.obj.sdrlines()
+        elif self.type == 'SDR':
+            return self.obj.sdrlines
 
 
 def main(cfg):
     print "Order filter (version %s) started." % VERSION
+    globs = ['*.xml', '*.txt', '*.sdr']
     cfg.init_dirs()
     while True:
 
             print "Rules loaded."
 
         report_failed(cfg)
-        
-        ordernames = glob.iglob(os.path.join(cfg.srcdir, '*'))
+
+        ordernames = multiglob(cfg.srcdir, globs)
 
         # Reduce loop intensity and lower CPU usage.
-        sleep(5)
+        sleep(3)
 
         for orderpath in ordernames:
             try:
-[PATHS_GCF]
+[PATHS]
 input=TESTDIR\INPUT
 filtered=TESTDIR\Filtered
 passed=TESTDIR\PASSED