def shutil_copy_folder(source_folder, target_folder): """ 复制文件夹 :param source_folder:需要复制的文件夹 :param target_folder: 复制到的目录路径 :return: """ source_folder = ConfigUtils.get_full_path('%s' % source_folder) target_folder = ConfigUtils.get_full_path('%s' % target_folder) shutil.copytree(source_folder, target_folder)
def copy_file(source_file, target_file): """ 复制文件到指定文件夹下 :param source_file 需要复制的文件名路径 :param target_file 复制到的文件名路径 :return: """ source_file = ConfigUtils.get_full_path('%s' % source_file) target_file = ConfigUtils.get_full_path('%s' % target_file) if os.path.exists(source_file) and os.path.isfile(source_file): shutil.copyfile(source_file, target_file)
def get_package_pid(item): try: cmd = '%s -s %s shell "ps | grep %s"' % (adb_file_path, device['Name'], item['PackageName']) dealing_log_message(cmd) output_file_path = ConfigUtils.get_full_path('%s/%s-%s-%s.log' % (PathManager.devices_folder_path(), device['Name'], item['PackageName'], time.strftime('%Y%m%d'))) process = subprocess.Popen(cmd, shell=True, stdin=None, stdout=subprocess.PIPE, stderr=subprocess.PIPE ) result_log, error_log = process.communicate() result_log = dealing_log_message(result_log) error_log = dealing_log_message(error_log) pid = 0 if result_log is not None and len(result_log) > 0: with open(output_file_path, 'w', encoding='UTF-8') as f: f.write(result_log) f.close() pid = result_log.split()[1] return { 'PackageName': item['PackageName'], 'Pid': pid, } except Exception as e: LoggerUtils.error(e)
def list_files_in_folder(path, target_list, ignore_path_list): if os.path.exists(path): if os.path.isfile(path) and path not in ignore_path_list: target_list.append(path) elif os.path.isdir(path): for f in os.listdir(path): if path not in ignore_path_list: list_files_in_folder(ConfigUtils.get_full_path("%s/%s" % (path, f)), target_list, ignore_path_list) return target_list
def create_file(path): result = True try: path = ConfigUtils.get_full_path('%s' % path) if os.path.exists(path): result = False else: with open(path, 'w', encoding='UTF-8') as f: f.close() except Exception as e: result = False LoggerUtils.error(e) return result
def delete_folder(path): """ 删除文件夹 :param path: 要删除的文件夹路径 :return: 返回是否删除成功 """ result = True try: path = ConfigUtils.get_full_path('%s' % path) if os.path.exists(path): shutil.rmtree(path) else: result = False except Exception as e: result = False LoggerUtils.error(e) return result
def create_folder(path): """ 创建文件夹 :param path: 将要创建的文件夹目录 :return: 返回创建成功与否结果 """ result = True try: path = ConfigUtils.get_full_path('%s' % path) if os.path.exists(path): result = False else: os.makedirs(path) except Exception as e: result = False LoggerUtils.error(e) return result
def delete_file(path): """ 删除文件 :param path:将要删除的文件路径 :return: """ result = True try: path = ConfigUtils.get_full_path('%s' % path) if os.path.exists(path): if os.path.isfile(path): os.remove(path) else: result = False else: result = False except Exception as e: result = False LoggerUtils.error(e) return result
def init(): logger_folder_path = PathManager.logger_folder_path() logger_file_path = ConfigUtils.get_full_path( '%s/log_%s.log' % (logger_folder_path, time.strftime("%Y%m%d"))) if os.path.exists(logger_file_path) is False: FileUtils.create_file(logger_file_path) formatter = logging.Formatter('%(asctime)s: %(message)s') if not logger.handlers: # 配置写入文件的拦截器 file_handler = logging.FileHandler(logger_file_path, "w", "UTF-8") file_handler.setLevel(logging.DEBUG) # file_handler.setFormatter(formatter) logger.addHandler(file_handler) # 配置输出到终端命令行的拦截器 stream_handler = logging.StreamHandler() stream_handler.setLevel(logging.INFO) # stream_handler.setFormatter(formatter) logger.addHandler(stream_handler)
def report_folder_path(): path = ConfigUtils.get_full_path('%s/Report' % get_root_path()) if os.path.exists(path) is False: FileUtils.create_folder(path) return path
def devices_folder_path(): path = ConfigUtils.get_full_path('%s/Devices' % get_root_path()) if os.path.exists(path) is False: FileUtils.create_folder(path) return path
def tools_folder_path(): path = ConfigUtils.get_full_path('%s/Tools' % get_root_path()) return path
def scripts_folder_path(): path = ConfigUtils.get_full_path('%s/Scripts' % get_root_path()) return path
def logcat_error_folder_path(): path = ConfigUtils.get_full_path('%s/LogCatError' % get_root_path()) if os.path.exists(path) is False: FileUtils.create_folder(path) return path
def get_root_path(): """ :return: 获取根目录路径 """ path = ConfigUtils.get_full_path('%s' % os.path.abspath(os.getcwd())) return path
if message is not None and message != '': LoggerUtils.debug( '==========> Start Message <==========\n' '%s\n' '==========> End Message <==========\n' % message ) return message except Exception as e: LoggerUtils.error(e) LoggerUtils.init() ConfigUtils.change_default_encoding() adb_file_path = ConfigUtils.get_full_path('%s/adb' % PathManager.tools_folder_path()) cmd = '%s devices' % adb_file_path dealing_log_message(cmd) process = subprocess.Popen(cmd, shell=True, stdin=None, stdout=subprocess.PIPE, stderr=subprocess.PIPE ) result_log, error_log = process.communicate() result_log = dealing_log_message(result_log) error_log = dealing_log_message(error_log)