Commits

Wang Dingwei  committed 8264e28

multiple src dir support

  • Participants
  • Parent commits 204b7d6

Comments (0)

Files changed (5)

File btsfilter.py

-# -*- coding: utf-8 -*-
-# Author:   Joel Wang <joel_wang@wistron.com>
-
-"""The main app"""
-
-import os
-import glob
-import sys
-
-from wistron.sdrparser2 import SDR
-
-from config import cfg
-        
-
-def main(cfg):
-    rules = cfg.get_rules()
-    for x_ in glob.glob(os.path.join(cfg.srcdir, '*')):
-        try:
-            x = SDR(x_)
-        except StandardError:
-            print "%s: Invalid order file" % x_
-            continue
-        x = Order(x)
-        matched = False
-        for r in rules:
-            if r.matched(x):
-                matched = True
-                print "%s [NG] - %s" % (x_, r.name)
-        if matched == False:
-            print "%s [OK]" % x_ 
-
-
-if __name__ == '__main__':
-    try:
-        import psyco
-        psyco.full()
-    except ImportError:
-        print 'Psyco not installed, the program will just run slower'    
-    sys.exit(main(cfg))
-
 from wistron.sdrparser2 import SDR
 from wistron.oietables import AppTable, OsTable, WhiteList
 
-VERSION = '13.0'
+VERSION = '14.0'
 CONFIG_FILE = 'settings.ini'
 LOGDIR = 'LOGS'
 LOG = 'LOGS\\orderfilter.log'
         unknown = self.whitelist.missed_srvs(unknown)
 
         # Check for excluded SRV
-        for u in unknown[:]:
+        for u in unknown.copy():
             if u.pn in self.exclude_pn:
                 unknown.remove(u)
 
         
     def init_dirs(self):
         "Initiate required directories. Create them if not exist."
-        for path in (self.srcdir, self.passdir, self.sdrdir, self.faildir):
+        for path in self.srcdirs + [self.passdir, self.sdrdir, self.faildir]:
             if not os.path.exists(path):
                 os.makedirs(path)
             elif not os.path.isdir(path):
         "Load all configuartions. "
         self.cfg = ConfigParser()
         self.cfg.read(self.cfgfile)
-        self.srcdir = self.cfg.get('PATHS', 'input')
+        self.srcdirs = [s.strip() for s in 
+                self.cfg.get('PATHS', 'input').split(',')]
         self.passdir = self.cfg.get('PATHS', 'passed')
         self.sdrdir = self.cfg.get('PATHS', 'passed_sdr')
         self.faildir = self.cfg.get('PATHS', 'filtered')

File doc/src/settings_cn.rst

 程序设由settings.ini实现. 内容以及设置方式如下::
   
   [PATHS]
-  input=TEST\INPUT          ; GCF XML的输入目录
+  input=TEST\INPUT          ; GCF XML的输入目录, 多个目录可用逗号隔开
   filtered=TEST\Filtered    ; NG XML的存放目录
   passed=TEST\Passed        ; OK XML的存放目錄
+  passed_sdr=TEST\SDR_pass  ; 如果文件为SDR而非XML,过滤OK就会跑到这里来
   datefmt=%Y%m%d            ; 在OK目录下建立以指定日期格式命名的子目录存放XML. 
                             ; 如果设置为None, 将不在OK目录下建立子目录.
   
   ; NG的order会被放到section名称命名的文件夹内. 需要设置的内容有
   ; OS Mapping Table, Application Table, White List, 以及该model的市场名称.
   ; 如果包含多个名称, 则用逗号隔开.
+  ; exclude_mod 为无需检查的 shipmode,通常设置为 pilot 各个 shipmode
+  ; exclude_srv 类似白名单,用来临时忽略检查一些 srv,多个 srv 用逗号隔开。
 
   [ODM_DJ1]
   os_table=OIE_LISTS\OS Mapping table.csv
   app_table=OIE_LISTS\Nov_Arsenal_Application_table.csv
   whitelist=OIE_LISTS\whitelist_arsenal.csv
   model=N4020, M4010, N4030
+  exclude_mod=CTB,PLB
+  exclude_srv=TX271
 
   [ODM_DG15]
   os_table=OIE_LISTS\OS Mapping table.csv
   app_table=OIE_LISTS\Nov_Berry_Application_table.csv
   whitelist=OIE_LISTS\whitelist_berry.csv
   model=N5010, M5010
-  
+  exclude_mod=CTB,PLB
+  exclude_srv=TX271
+

File orderfilter.py

 from operations import pass_process, fail_process
 
 
-def multiglob(path, globs=[]):
+def multiglob(paths, globs=[]):
     "glob with multiple criterias. "
     filepaths = []
     for g in globs:
-        filepaths.extend(glob.glob(os.path.join(path, g)))
+        for path in paths:
+            filepaths.extend(glob.glob(os.path.join(path, g)))
     return filepaths
 
 
 
         report_failed(cfg)
 
-        ordernames = multiglob(cfg.srcdir, globs)
+        ordernames = multiglob(cfg.srcdirs, globs)
 
         # Reduce loop intensity and lower CPU usage.
         sleep(3)

File settings.ini

 [PATHS]
-input=TESTDIR\INPUT
+input=TESTDIR\INPUT,TESTDIR\INPUT2
 filtered=TESTDIR\Filtered
 passed=TESTDIR\PASSED
 passed_sdr = TESTDIR\PASSED_SDR