66
77import sys
88import os
9+ import md5
910# modulefinder does all the heavy lifting
1011import modulefinder
1112sys .path .append ('/opt/lsb/lib/appchk' )
12- import tet
13+ import tetj
1314
1415# re-define the report class for our needs
1516class lsbmf (modulefinder .ModuleFinder ):
1617 def report (self ):
1718 return self .modules
1819
20+ def sumfile (fobj ):
21+ m = md5 .new ()
22+ while True :
23+ d = fobj .read (8096 )
24+ if not d :
25+ break
26+ m .update (d )
27+ return m .hexdigest ()
28+
29+ def file_info (journal , tfile ):
30+ fsize = os .path .getsize (tfile )
31+ wstr = "FILE_SIZE %d" % (fsize )
32+ journal .purpose_start ('File information' )
33+ journal .testcase_info (1 ,0 ,0 ,wstr )
34+ f = file (tfile , 'rb' )
35+ md5sum = sumfile (f )
36+ f .close ()
37+ wstr = "BINARY_MD5SUM %s" % (md5sum )
38+ journal .testcase_info (0 ,0 ,0 ,wstr )
39+ journal .result (tetj .TETJ_PASS )
40+ journal .purpose_end ()
41+
1942# compare the found modules to the LSB list and report
2043# if the import uses a /opt path, just warn
2144def check_modules (journal , modules , lsb_modules , syspath_org ):
@@ -25,11 +48,11 @@ def check_modules(journal, modules, lsb_modules, syspath_org):
2548 keys .sort ()
2649 tcount = 0 ;
2750 for key in keys :
28- jresult = 'PASS'
51+ jresult = tetj . TETJ_PASS
2952 tcount = tcount + 1
3053 if journal :
31- tet . istart ( tcount )
32- tet . info ( tcount , 'Check ' + key )
54+ journal . purpose_start ( 'Check ' + key )
55+
3356 if key not in lsb_modules :
3457 if key != '__main__' and key != '__builtin__' :
3558 # warn if we're getting modules from outside sys.path
@@ -43,16 +66,17 @@ def check_modules(journal, modules, lsb_modules, syspath_org):
4366 mdir = syspath_org [0 ]
4467 if mdir not in syspath_org :
4568 tresult = key + twarn + mdir
46- jresult = 'UNRESOLVED'
69+ jresult = tetj . TETJ_UNRESOLVED
4770 else :
4871 tresult = key + tfail
49- jresult = 'FAIL'
72+ jresult = tetj . TETJ_FAIL
5073 print tresult
5174 if journal :
52- tet .info (tcount , tresult )
75+ journal .testcase_info (0 ,0 ,0 ,tresult )
76+
5377 if journal :
54- tet .result (tcount , jresult )
55- tet . iend ( tcount )
78+ journal .result (jresult )
79+ journal . purpose_end ( )
5680
5781def main (argv ):
5882 if len (argv ) == 1 :
@@ -82,11 +106,9 @@ def main(argv):
82106 # prep the journal header
83107 if journal :
84108 myname = os .path .basename (argv [0 ])
85- journal_file = tet .open_journal ('journal.' + myname + '.' + jsuffix )
86- tet .write_header (journal_file )
87- vfile = sharepath + '/VERSION.' + myname
88- tet .write_version (journal_file ,vfile )
89- tet .file_info (journal_file , testapp )
109+ journal = tetj .Journal ('journal.' + myname + '.' + jsuffix , testapp )
110+ journal .add_config ("VSX_NAME=lsb-tetjtest.py 0.1 (%s)" % journal .machine )
111+ journal .config_end ()
90112
91113 path = sys .path [:]
92114 debug = 0
@@ -116,9 +138,14 @@ def main(argv):
116138
117139 print testapp + ":"
118140 if journal :
119- tet .tstart (testapp )
141+ journal .testcase_start (testapp )
142+ file_info (journal , testapp )
143+
120144 modules = mf .report ()
121145 check_modules (journal , modules , lsb_modules , syspath_org )
146+ if journal :
147+ journal .testcase_end (testapp )
148+ journal .close ()
122149
123150if __name__ == '__main__' :
124151 main (sys .argv )
0 commit comments