1. Wang Dingwei
  2. check_os

Commits

Wang Dingwei  committed d047c49

Added SDR display and SOP link

  • Participants
  • Parent commits e24d6d5
  • Branches default

Comments (0)

Files changed (8)

File .hgignore

View file
  • Ignore whitespace
 syntax: glob
 *.pyc
 *~
-
+*.zip
+PartData
 syntax: regexp

File check_os.py

View file
  • Ignore whitespace
 # Author: Joel Wang <Joel_Wang@wistron.com>
 #
 # History:
+# 2010-12-14, V7.0, Support to link to SOP
+# 2010-12-07, V6.0, Supporting SDR dissection
+# 2010-10-19, V5.1, Fixes language comparison.
 # 2010-10-15, V5.0, uses MVC pattern. Fixed MUI ordering caused false positive.
 # 2010-09-17, V4.0, output as html, opens in browser instead of cmd
 # 2010-08-25, V3.0, colorful output
 """
 import pickle
 import sys
+import os
 import optparse
+import csv
+import re
+from ConfigParser import ConfigParser
 
 from constants import VERSION
 from model import Result
 from view import display
 
+cfgfile = 'settings.ini'
+
+class Platform(object):
+    models = set()
+    whitelist = set()
+
+class ConfigError(Exception):
+    pass
+
+class Config(object):
+    def __init__(self, cfgfile):
+        self.cfg = ConfigParser()
+        self.cfg.read(cfgfile)
+    def platforms(self):
+        platforms = []
+        for sect in self.cfg.sections():
+            if sect.startswith('MODEL_'):
+                p = Platform()
+                fname = sect.split('_')[1]
+                models = self.cfg.get('MODELS', fname)
+                models = models.strip().split(',')
+                p.models = set([m.strip() for m in models])
+                wfile = self.cfg.get('MODEL_'+fname, 'whitelist')
+                p.whitelist = self._getwlist(wfile)
+                platforms.append(p)
+        return platforms
+    def keywords(self):
+        keywords = self.cfg.defaults()['keywords']
+        keywords = keywords.split(',')
+        return [k.strip() for k in keywords]
+    def known_infos(self):
+        infos = []
+        infofile = self.cfg.defaults()['infodict']
+        if not os.path.exists(infofile):
+            return infos
+        for record in csv.reader(open(infofile)):
+            if len(record) > 2:
+                infos.append(record[2].strip().upper())
+        return infos
+    def sop_links(self):
+        res = {}
+        sopcfgfile = self.cfg.defaults()['sopconfig']
+        sopdir = self.cfg.defaults()['sopdir']
+        sopcfg = [s.strip() for s in open(sopcfgfile) if s.strip() != '']
+        for s in sopcfg:
+            c = s.split('\t')
+            if len(c) >= 2:
+                parts = [s.strip() for s in c[1].split(',')]
+                link = (c[0] if c[0].lower().endswith('.html')
+                        else c[0] + '.html')
+                pagedir = os.path.join(os.getcwd(), sopdir, link)
+                res[pagedir] = parts
+            else:
+                raise ConfigError('SOP config error.')
+        return res
+                    
+    def _getwlist(self, f):
+        wlist = set()
+        for record in csv.reader(open(f)):
+            srv = record[0].strip()
+            if srv.isalnum() and len(srv) == 5:
+                wlist.add(srv)
+        return wlist
+
 def main():
     """Parses optional arguments, gets OS information from System and SDR,
     compare and display the results. """
         res.msg.append(e)
         if options.DEBUG:
             raise
+    try:
+        cfg = Config(cfgfile)
+        platforms = cfg.platforms()
+        for platform in platforms:
+            if res.sdrobj.model() in platform.models:
+                res.dissection(cfg.keywords(),
+                               platform.whitelist,
+                               cfg.known_infos(),
+                               cfg.sop_links())
+    except Exception, e:
+        res.msg.append(e)
+        res.msg.append("Config error, running without config")
+        if options.DEBUG:
+            raise
 
     if options.VERBOSE:
         print "Result:", res.result

File constants.py

View file
  • Ignore whitespace
 "Constants for other modules."
 
-VERSION = 5.0
+VERSION = 7.0
 SDR_PATH = 'C:\\dell.sdr'
 

File model.py

View file
  • Ignore whitespace
 from wistron import ostype, sdrparser
 from constants import SDR_PATH
 
-def lang_matched(sdr_lang, os_lang):
+def lang_matched(os_lang, sdr_lang):
     """Return True if sdr_lang matches os_lang.
+    os_lang  -> ('LANG_STR', 'REGION')
     sdr_lang -> ('LANG_STR', ['REGION_1', 'REGION2'])
-    os_lang  -> ('LANG_STR', 'REGION')"""
-    if sdr_lang[0] == os_lang[0]:               # Same language
-        if not sdr_lang[1] or not os_lang[1]:   # region undefined
+    """
+    if os_lang[0] == sdr_lang[0]:               # Same language
+        if not os_lang[1] or not sdr_lang[1]:   # region undefined
             return True
-        elif sdr_lang[1] in os_lang[1]:         # same region
+        elif os_lang[1] in sdr_lang[1]:         # same region
             return True
-        else:
+        else:                                   # Other situations
             return False
-    else:
+    else:                                       # Different language
         return False
 
-def mui_matched(sdr_mui, os_mui):
+def mui_matched(os_mui, sdr_mui):
     "Compares all mui parts with registry info, return True if OK."
     if len(os_mui) != len(sdr_mui):
         return False
     match_count = 0
     for o in os_mui:
         for s in sdr_mui:
-            if lang_matched(s, o):
+            if lang_matched(o, s):
                 match_count += 1
                 continue
     return match_count == len(sdr_mui)
 
-
 class Result(object):
     "OS and SDR comparison result."
     def __init__(self):
         self.os_lang_str = ''       # Installed language
         self.sdr_lang_str = ''      # SDR language
         self.po = ''            # PO number
+        self.sdr_dissection = []     # SDR lines with properties
 
     def os_string(self, li):
         "Convert os def tuple into a string"
             self.msg.append(e)
             raise
 
+    def dissection(self, kwds, wlist, infolist, links):
+        "Returns a list of (sdr_line, keyword, sop_link) tuples."
+        self.sdr_dissection = []
+        sdr_dissection = self.sdrobj.dissection(kwds, wlist, infolist)
+        for (line, kwd) in sdr_dissection:
+            link = ''
+            if kwd in ['WLIST', 'KWD', 'QFE', 'NORMAL']:
+                for k, v in links.iteritems():
+                    if self.sdrobj._get_pn(line) in v:
+                        link = k
+            self.sdr_dissection.append((line, kwd, link))
+
     def compare(self):
         "Compare between OS and SDR and updates the result."
         if self.sdrobj.is_mui():
                            else 'NG')
         else:
             if (self.os_type == self.sdr_type and 
-                lang_matched(self.sdr_lang, self.os_lang)):
+                lang_matched(self.os_lang, self.sdr_lang)):
                 self.result = 'OK'
             else:
                 self.result = 'NG'
-        
+

File settings.ini

View file
  • Ignore whitespace
+[DEFAULT]
+keywords = LS,IJ,TOOLBAR,PTR,MISC,HTML,DRVR
+infodict = partdata\infoparts.csv
+sopconfig = sop_config.txt
+sopdir = SOP
+
+[MODELS]
+DG15 = N5010, M5010
+DJ1 = N4020, N4030, M4030
+DJ2 = N5020, N5030, M5030
+DR13 = VostroV130
+ 
+[MODEL_DG15]
+whitelist = partdata\whitelist_berry.csv
+
+[MODEL_DJ1]
+whitelist = partdata\whitelist_arsenal.csv
+
+[MODEL_DJ2]
+whitelist = partdata\whitelist_chelsea.csv
+
+;[MODEL_DR13]
+;whitelist = partdata\DR13_Whitelist.csv

File sop_config.txt

View file
  • Ignore whitespace
+PAGE1	T649H, TX271
+PAGE2	NNJVM
+PAGE3	5XDYN

File test.py

View file
  • Ignore whitespace
+import unittest
+from model import *
+
+os_lang_1 = ('English', 'United States')
+sdr_lang_1 = ('English', [])
+os_lang_2 = ('Portuguese', 'Brazil')
+sdr_lang_2 = ('Portuguese', ['Brazil'])
+os_lang_3 = ('Hebrew', None)
+sdr_lang_3 = ('Hebrew', [])
+os_lang_4 = ('Chinese', 'Taiwan')
+sdr_lang_4 = ('Chinese', ['Taiwan'])
+os_lang_5 = ('Chinese', "PRC")
+sdr_lang_5 = ('Chinese', ['PRC', 'Singapore'])
+
+class TestModel(unittest.testcase):
+    def setUp(self):
+        self.result = Result()
+    def testLangMatched(self):
+        pass

File view.py

View file
  • Ignore whitespace
 HTML = 'osinfo.html'
 TEMPLATE = '''<html>
 <head><title>OS Check Utility v${version}</title></head>
-<body>
+<body style="font-family:consolas, courier, courier new, monospace">
 
 % if res.result == 'OK':
     <b style="font-size:96px; color:green">${res.result}</b>
     <b>Required language: </b>${res.sdr_lang_str}
     <br>
 % endif
-</body></html>'''
+
+<hr>
+
+%if len(res.sdr_dissection) > 0:
+    <b>SDR Content</b>
+    <br>
+    <div style="font-size:12px">
+    % for (line, prop, link) in res.sdr_dissection:
+        ${makeline(line, prop, link)}
+    % endfor
+    </div>
+% endif
+</body></html>
+
+<%def name="makeline(line, prop, link)">
+    % if link:
+        <div><a href="${link}" 
+    % else:
+        <div 
+    % endif
+    
+    % if prop == 'INFO':
+        style="color:dimgray">
+    % elif prop == 'KNOWNINFO':
+        style="color:red">
+    % elif prop == 'MUIINFO':
+        style="color:blue">
+    % elif prop == 'OSSRV':
+        style="color:black">
+    % elif prop == 'WLIST':
+        style="color:green">
+    % elif prop == 'KWD':
+        style="color:blue">
+    % elif prop == 'QFE':
+        style="color:dodgerblue">
+    % elif prop == 'NORMAL':
+        style="color:red">
+    % else:
+        style="color:dimgray">
+    % endif
+    
+    ${line}
+    
+    % if link:
+        </a></div>
+    % else:
+        </div>
+    % endif
+</%def>
+'''
 
 def display(res):
     "Display results in a web browser."