1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/usr/bin/python
# -*- coding: GBK -*-
#---------------------------------------------------------------------
#Writer £ºhch
#---------------------------------------------------------------------
# ½Å±¾ËµÃ÷---
# ¼ì²éÅäÖÃÎļþÊÇ·ñÕýÈ·
#---------------------------------------------------------------------
import md5
import os
import shutil
 
resultPath = '.\HashCheckerResult'
 
def RMHashCheckerResult():
    if os.path.isdir(resultPath):
        shutil.rmtree(resultPath)
 
#¶ÁÈ¡×ܸÙ,ÓÃÓÚ½âÎöÀ©Õ¹ÎļþÃû
def CheckMD5IsOK():
#===============================================================================
#    È±Ê§Îļþ±¨´í£¬Ìí¼ÓÑéÖ¤ÎļþÊÇ·ñ´æÔÚ--2010-02-26
#===============================================================================
 
#===============================================================================
#    if not os.path.isdir(resultPath):
#        os.mkdir(resultPath)
#    wfile = open(resultPath+'\\OK.txt', 'w')
#    wfile.close()
#    print 'Check File OK!'
#    return
# #===============================================================================
# #   2009.12.16 È¡ÏûMD5ÑéÖ¤£¬QAÐèÇó¡£
# #===============================================================================
#===============================================================================
        
    curPath = os.getcwd() + '\\' + "GeneralProgramme.txt"
 
    if not os.path.isfile( curPath ):
        raise Exception ( 'ÎÞ·¨·¢ÏÖ×ܸ٠= %s'%(curPath) )
    
    file = open( curPath , 'r' )
    
    #¶ÁÈ¡Êý¾Ý
    data = [ line.split('\t')[:3] for line in file.readlines() ]
    
    file.close()
    
    if not os.path.isdir(resultPath):
        os.mkdir(resultPath)
        
    if not data:
        wfile = open(resultPath+'\\OK.txt', 'w')
        wfile.close()
        print 'Check File OK!'
        return
    
    #ɾ³ýµÚÒ»ÐÐ×¢ÊÍÁÐ
    data.pop( 0 )
    wholeStr = ''
    count = 0
    allCount = len(data)
 
#ÑéÖ¤ÎļþÊÇ·ñ´æÔÚ
    for dataList in data:
        wholeStr = CheckFilePath(os.getcwd(), dataList, wholeStr)
        count += 1
        print 'Checking File: %s/%s'%(count,allCount)
 
 
#===============================================================================
#    ÑéÖ¤MD5
#    for dataList in data:
#        wholeStr = compareMD5(os.getcwd(), dataList, wholeStr)
#        count += 1
#        print 'Checking File: %s/%s'%(count,allCount)
#===============================================================================
    
    if not wholeStr:
        wfile = open(resultPath+'\\OK.txt', 'w')
        wfile.close()
        print 'Check File OK!'
    else:
        wfile = open(resultPath+'\\Diff.txt', 'w')
        wfile.write(wholeStr + '\n')
        wfile.close
        print 'Check File Faile!'
    return
 
#ÑéÖ¤ÎļþÊÇ·ñ´æÔÚ
def CheckFilePath(path, curList, wholeStr):
    tmpPath = path + curList[1]+'.txt'
#    print tmpPath
    if not os.path.exists(tmpPath):
        wholeStr += (tmpPath + '\n')
 
    return wholeStr
 
#ÑéÖ¤MD5
def compareMD5(path, curList, wholeStr):
    tmpPath = path + curList[1]+'.txt'
    try:
        rfile = open( tmpPath , 'rb' )
        txtStr = rfile.read()
        rfile.close()
    except:
        txtStr = 'FK'
    
    md5Src = md5.md5(txtStr).hexdigest()
 
    #ÎļþÖеÄMD5
    md5Dst = curList[2]
    
    if md5Src != md5Dst:
        wholeStr += (tmpPath + '\n')
    
    return wholeStr
        
def main():
    print 'Check Config File...'
    RMHashCheckerResult()
    CheckMD5IsOK()
    
    
if __name__ == '__main__':
    main()