How to use get_file_md5 method in autotest

Best Python code snippet using autotest_python

pefile_crawling.py

Source:pefile_crawling.py Github

copy

Full Screen

...35 print("Error :", full_path)36 except :37 pass38 return path_32bit_exe, path_64bit_exe, path_32bit_dll, path_64bit_dll39def get_file_md5( file_path, block_size = 8192 ) :40 hasher = hashlib.md5()41 with open(file_path, 'rb') as f :42 buf = f.read(block_size)43 while buf :44 hasher.update(buf)45 buf = f.read(block_size)46 return hasher.hexdigest()47def crawling_32bit_exe( path_32bit ) :48 md5 = get_file_md5(path_32bit)49 target_path = os.path.join(DESTINATION_32_EXE_PATH, md5 + '.vir')50 if not os.path.exists(target_path) :51 try :52 shutil.copy(path_32bit, target_path)53 except :54 pass55def crawling_64bit_exe( path_64bit ) :56 md5 = get_file_md5(path_64bit)57 target_path = os.path.join(DESTINATION_64_EXE_PATH, md5 + '.vir')58 if not os.path.exists(target_path) :59 try :60 shutil.copy(path_64bit, target_path)61 except :62 pass63def crawling_32bit_dll( path_32bit ) :64 md5 = get_file_md5(path_32bit)65 target_path = os.path.join(DESTINATION_32_DLL_PATH, md5 + '.vir')66 if not os.path.exists(target_path) :67 try :68 shutil.copy(path_32bit, target_path)69 except :70 pass71def crawling_64bit_dll( path_64bit ) :72 md5 = get_file_md5(path_64bit)73 target_path = os.path.join(DESTINATION_64_DLL_PATH, md5 + '.vir')74 if not os.path.exists(target_path) :75 try :76 shutil.copy(path_64bit, target_path)77 except :78 pass79def init() :80 if not os.path.exists(DESTINATION_32_EXE_PATH) :81 try :82 os.makedirs(DESTINATION_32_EXE_PATH)83 except :84 exit(1)85 if not os.path.exists(DESTINATION_64_EXE_PATH) :86 try :...

Full Screen

Full Screen

jarutil.py

Source:jarutil.py Github

copy

Full Screen

...6import os7import hashlib8import shutil9import zipfile, time10def get_file_md5(file):11 md5_l = hashlib.md5()12 with open(file, mode="rb") as f:13 by = f.read()14 md5_l.update(by)15 ret = md5_l.hexdigest()16 # print(ret)17 return ret18def unpack_jar(path):19 zfile = zipfile.ZipFile(path, 'r')20 jarlog_ = os.getcwd() + '/jarlog'21 if not os.path.exists(jarlog_):22 # shutil.rmtree(jarlog_)23 os.makedirs(os.getcwd() + '/jarlog/')24 outPath = jarlog_ + "/" + str(time.time())25 zfile.extractall(outPath)26 return outPath27def ite_file_md5(path):28 for root, dirs, files in os.walk(path):29 for file in files:30 # 获取文件所属目录31 # print(root)32 # 获取文件路径33 path_join = os.path.join(root, file)34 print(path_join)35 print(get_file_md5(path_join))36def compare_jar_class_file(jar1, jar2):37 path1 = unpack_jar(jar1)38 path2 = unpack_jar(jar2)39 for root, dirs, files in os.walk(path1):40 for file in files:41 # 获取文件所属目录42 # print(root)43 # 获取文件路径44 path_join1 = os.path.join(root, file)45 path_join2 = os.path.join(path2, file)46 print(path_join1)47 print(get_file_md5(path_join1))48 if get_file_md5(path_join1) == get_file_md5(path_join2):49 print("equals")50if __name__ == '__main__':...

Full Screen

Full Screen

recorder.py

Source:recorder.py Github

copy

Full Screen

...10 return json.loads(content)11def write_json_file(path, t):12 with open(path, 'w') as outfile:13 json.dump(t, outfile, sort_keys=True, indent=4, separators=(',', ': '))14def get_file_md5(file):15 hash_md5 = hashlib.md5()16 with open(file, 'rb') as f:17 for chunk in iter(lambda: f.read(4096), b''):18 hash_md5.update(chunk)19 return hash_md5.hexdigest()20def get_file_modify_time(path):21 return os.stat(path).st_mtime22def read_file(file):23 return open(file, 'r').read()24def write_file(file, content):25 with open(file, 'w') as outfile:26 outfile.write(content)27class Recorder:28 def __init__(self, record_file):29 self.record_file = record_file30 self.records = read_json_file(record_file)31 def record(self, file):32 md5 = get_file_md5(file)33 modify_time = get_file_modify_time(file)34 self.records[file] = (modify_time, md5, time.ctime(modify_time))35 write_json_file(self.record_file, self.records)36 def need_update(self, file):37 if not file in self.records:38 return True39 if not os.path.isfile(file):40 return True41 if type(self.records[file]) == type(''):42 return True43 modify_time_prev = self.records[file][0]44 modify_time = get_file_modify_time(file)45 if modify_time == modify_time_prev:46 return False47 md5 = get_file_md5(file)48 md5_prev = self.records[file][1]...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful