def create_or_erase(f): f = FunCom.get_abspath(FunCom.path_join(Res.project_path, f)) FunCom.log('to parse file: ' + f) if not FunCom.exists(f): FunCom.log('not exist, creating') FunCom.create_file(f) else: FunCom.log('exist, erasing') FunCom.erase_file_content(f)
def log_trick(device_id, monkey_log, sender, pwd, receivers, anr_receivers, subject, logfile, browser, device, version, keyword): FunCom.log('start log analyze') # todo # exception_handle(device_id) if FunCom.exists(monkey_log): f = open(monkey_log) lines = f.read() exception = "Exception" crash = "CRASH" anr = "ANR" native_crash = 'Short Msg: Native crash' not_running = 'is your activity running' focus_on = "Bitmap" logcat_to_file = focus_on in lines if exception in lines or crash in lines: crash_result = lines[lines.index(crash) - 200:] crash_result = crash_result.replace('\n', '<br>') exception_handle(device_id, logcat_to_file) if check_key_word(crash_result, keyword): Sender.sendException(crash_result, sender, pwd, receivers, subject, logfile, browser, device, version) FunCom.log("monkey finished with exception") else: FunCom.log('monkey finished with system exception\n') FunCom.log('<<<<<<<<<<<<<<<<<<<<<\n' + crash_result) elif anr in lines: FunCom.log("monkey finished with anr") FunCom.log(lines[lines.index(anr):lines.index(anr) + 10000]) crash_result = lines[lines.index(anr):lines.index(anr) + 200] crash_result = crash_result.replace('\n', '<br>') exception_handle(device_id, logcat_to_file) Sender.sendException(crash_result, sender, pwd, anr_receivers, subject.replace('Crash', 'ANR'), logfile, browser, device, version) elif native_crash in lines: exception_handle(device_id, logcat_to_file) FunCom.log('monkey finished with native crash') elif not_running in lines: FunCom.log('monkey finished with activity not running') f.close() FunCom.log('>>> monkey finished...\n\n')