def load_logcats(log_dir): json_files = list() for file in FileUtils.list_files_in_dir(log_dir): if file.endswith(".json"): json_dict = FileUtils.load_json(log_dir + file) json_files.append(json_dict) return json_files
def prepare_output_directories(self): if FileUtils.dir_exists(GlobalConfig.OUTPUT_DIR): Printer.system_message( self.TAG, "Directory " + Color.GREEN + GlobalConfig.OUTPUT_DIR + Color.BLUE + " found!. Only session related directories and files will be cleaned." ) else: Printer.system_message( self.TAG, "Directory " + Color.GREEN + GlobalConfig.OUTPUT_DIR + Color.BLUE + " not found. Creating...") for directory in [ GlobalConfig.OUTPUT_SUMMARY_LOG_DIR, GlobalConfig.OUTPUT_AVD_LOG_DIR, GlobalConfig.OUTPUT_TEST_LOG_DIR, GlobalConfig.OUTPUT_TEST_LOGCAT_DIR, GlobalConfig.OUTPUT_STYLES_FOLDER_DIR, GlobalConfig.OUTPUT_LOGCAT_HTML_DIR, GlobalConfig.OUTPUT_TEST_RECORDINGS_DIR ]: if FileUtils.dir_exists(directory): files_num = 0 if FileUtils.list_files_in_dir( directory) is None else len( FileUtils.list_files_in_dir(directory)) Printer.system_message( self.TAG, "Directory " + Color.GREEN + directory + Color.BLUE + " was found. Removing (" + Color.GREEN + str(files_num) + " files" + Color.BLUE + ").") FileUtils.clear_dir(directory) else: Printer.system_message( self.TAG, "Directory " + Color.GREEN + directory + Color.BLUE + " not found. Creating...") FileUtils.create_dir(directory) if FileUtils.file_exists(GlobalConfig.OUTPUT_INDEX_HTML_DIR): Printer.system_message( self.TAG, "Removing " + Color.GREEN + GlobalConfig.OUTPUT_INDEX_HTML_DIR + Color.BLUE + " file from previous session.")
def load_summary(log_dir): files_in_summary_dir = FileUtils.list_files_in_dir(log_dir) if len(files_in_summary_dir) != 1: message = ( "Something went wrong! There should be one file with name 'session_summary.json' in '" + log_dir + "' directory but " + str(len(files_in_summary_dir)) + " were found.") raise Exception(message) json_dict = FileUtils.load_json(log_dir + files_in_summary_dir[0]) return json_dict
def add_rerun_number_to_filename_in_dir(path, filename): rerun_count = 0 for filename_in_dir in FileUtils.list_files_in_dir(path): if filename in filename_in_dir: rerun_count += 1 if rerun_count > 0: if "." in filename: filename_parts = filename.split(".") filename = filename_parts[0] + "_rerun_no_{}".format(rerun_count) + filename_parts[1] else: filename += "_rerun_no_{}".format(rerun_count) return filename
def dump_saved_files_history(): nothing_to_display = True if FileUtils.dir_exists(GlobalConfig.OUTPUT_AVD_LOG_DIR): nothing_to_display = False saved_avd_logs = FileUtils.list_files_in_dir( GlobalConfig.OUTPUT_AVD_LOG_DIR) Printer.system_message( TAG, "Directory " + Color.GREEN + str(GlobalConfig.OUTPUT_AVD_LOG_DIR) + Color.BLUE + " (" + Color.GREEN + str(len(saved_avd_logs)) + " files" + Color.BLUE + ")") for saved_file in FileUtils.list_files_in_dir( GlobalConfig.OUTPUT_AVD_LOG_DIR): Printer.system_message(TAG, " * " + saved_file + ".") if FileUtils.dir_exists(GlobalConfig.OUTPUT_TEST_LOG_DIR): nothing_to_display = False saved_test_summaries = FileUtils.list_files_in_dir( GlobalConfig.OUTPUT_TEST_LOG_DIR) Printer.system_message( TAG, "Directory " + Color.GREEN + str(GlobalConfig.OUTPUT_TEST_LOG_DIR) + Color.BLUE + " (" + Color.GREEN + str(len(saved_test_summaries)) + " files" + Color.BLUE + ")") for saved_file in FileUtils.list_files_in_dir( GlobalConfig.OUTPUT_TEST_LOG_DIR): Printer.system_message(TAG, " * " + saved_file + ".") if FileUtils.dir_exists(GlobalConfig.OUTPUT_TEST_LOGCAT_DIR): nothing_to_display = False saved_logcats_summaries = FileUtils.list_files_in_dir( GlobalConfig.OUTPUT_TEST_LOGCAT_DIR) Printer.system_message( TAG, "Directory " + Color.GREEN + str(GlobalConfig.OUTPUT_TEST_LOGCAT_DIR) + Color.BLUE + " (" + Color.GREEN + str(len(saved_logcats_summaries)) + " files" + Color.BLUE + ")") for saved_file in saved_logcats_summaries: Printer.system_message(TAG, " * " + saved_file + ".") if GlobalConfig.SHOULD_RECORD_TESTS: if FileUtils.dir_exists(GlobalConfig.OUTPUT_TEST_RECORDINGS_DIR): nothing_to_display = False saved_recordings_summaries = FileUtils.list_files_in_dir( GlobalConfig.OUTPUT_TEST_RECORDINGS_DIR) Printer.system_message( TAG, "Directory " + Color.GREEN + str(GlobalConfig.OUTPUT_TEST_RECORDINGS_DIR) + Color.BLUE + " (" + Color.GREEN + str(len(saved_recordings_summaries)) + " files" + Color.BLUE + ")") for saved_file in saved_recordings_summaries: Printer.system_message(TAG, " * " + saved_file + ".") if nothing_to_display: Printer.system_message(TAG, "No files were saved during session.")