def segway_config(args=None): keys = [ 'env', 'open_app', 'retry_limit', 'retry_interval', 'log_dir', 'username', 'password', 'token', 'log_start_time', 'token2' ] hit = False if len(sys.argv) > 1: args = sys.argv[1:] config = Config('config.json').config for arg in args: k, v = arg.split('=') if k in keys: hit = True config[k] = v if hit: Config.dump(config)
def segway_fetch(args=None): if len(sys.argv) == 1: print("Usage: %s %s" % ('segway_fetch', '<url>')) return url = sys.argv[1] config = Config('config.json').config fetch_and_open(url, config['open_app'], config['log_dir'])
def setUp(self): print('setUp...') self.url = 'http://robot-base.${host_part_2}.com/aws/web/file/download/?bucketName=ota-robot-base&objectKey=log/GXBOX' \ '-${PREFIX}0036_2020-12-05_23-06-05-137_M.zip ' self.name_expect = 'GXBOX-${PREFIX}0036_2020-12-05_23-06-05-137_M.zip' self.config = Config('config.json').config self.timestamp = 1607180765.0
def login_and_save_token(): config = Config('config.json').config if 'token' not in config or not config['token']: if not config['username'] or not config['password']: print('请先配置账号密码') return else: response = raw_login(config['username'], config['password']) token = get_token(response) if token: config['token'] = token Config.dump(config) return token else: print('登录失败') else: print('已有token: %s' % config['token']) return config['token']
def pull_log_from_dir(log_dir): print('----------------') config = Config('config.json').config parent = config['log_dir'] device_id = get_device_id() dir = get_dir(parent) # 最终输出路径:日志父目录-设备id-格式化时间-设备日志目录 final_dir = dir + log_dir.replace('/', '_') pull_log_to(from_dir=log_dir, to_dir=final_dir) open_with_app(config['open_app'], final_dir)
def segway_login(args=None): """ 登录并获取token,token会自动写入config """ config = Config('config.json').config if not args: args = sys.argv[1:] if len(args) == 2: username = args[0] password = args[1] else: username = config['username'] password = config['password'] token = login_and_save_token() if token: if not config: config = Config('config.json').config config['username'] = username config['password'] = password config['token'] = token Config.dump(config) print(token)
def segway_upload(args=None): if len(sys.argv) > 2: robot_id = sys.argv[1] path = sys.argv[2] else: return config = Config('config.json').config log_start_time_f = config['log_start_time'] if not log_start_time_f: # 默认拉取24小时日志 print('拉取24小时日志') log_start_time = tick - 24 * 60 * 60 else: print('拉取日志起始点:%s' % log_start_time_f) log_start_time = int( time.mktime(time.strptime(log_start_time_f, '%Y-%m-%d_%H:%M:%S')) * 1000) result = upload_with_retry(robot_id, path, log_start_time, None, None) if result: print(result)
def setUp(self): print('setUp...') self.url = 'http://robot-base.${host_part_2}.com/aws/web/file/download/?bucketName=ota-robot-base&objectKey=log/S1RLM2047C0009_2020-12-04_16-37-27-950_M.zip' self.name_expect = 'S1RLM2047C0009_2020-12-04_16-37-27-950_M.zip' self.config = Config('config.json').config self.timestamp = 1607071047.0
def clear_token(): config = Config('config.json').config config['token'] = None Config.dump(config)
def segway_showconfig(): config = Config('config.json').config print(json.dumps(config, sort_keys=True, indent=4, ensure_ascii=False))
def test_login_and_save_token(self): result = login_and_save_token(self.config['username'], self.config['password']) new_config = Config('config.json').config self.assertTrue(result) self.assertTrue(new_config['token'] == result)
def setUp(self): print('setUp...') self.config = Config('config.json').config