#!/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()
|