def request_string(self, url, headers=None, data=None, method=None, encoding=None, cache=None, retryTimes=None): if not retryTimes: retryTimes = 1 if cache is None: cache = Common.debug() response = None for _ in range(retryTimes): response = self.request_data(url, headers=headers, data=data, method=method, cache=cache) if response is not None: break s = None if response is not None: if encoding: s = Common.decode_data(response, encoding=encoding) else: s = Common.decode_data(response, encoding='utf-8') if not s: s = Common.decode_data(response, encoding='gbk') return s
file = Common.join_paths(dst_dir, x) Common.remove(file) def backup_with_config(config_path): content = Common.read_file(config_path) arr = Common.str2json(content) if arr: for x in arr: backup(x.get('src'), x.get('dst_dir'), x.get('retemtion_days'), hours_last_day=x.get('hours_last_day'), ignore_hours=x.get('ignore_hours')) if __name__ == '__main__': Common.set_debug(True) config_path = Common.join_paths(Common.get_cmd_dir(), '..', 'tests', 'backup_test.json') config_path = Common.abs_path(config_path) if Common.debug(): for day in range(0, 18): for hour in range(0, 24): path = '/tmp/backup/backup_test_201902%02d%02d.json' % ( 25 - day, hour) Common.replace_file(config_path, path) backup_with_config(config_path)