Esempio n. 1
0
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)
Esempio n. 2
0
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'])
Esempio n. 3
0
 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
Esempio n. 4
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']
Esempio n. 5
0
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)
Esempio n. 6
0
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)
Esempio n. 7
0
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)
Esempio n. 8
0
 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
Esempio n. 9
0
def clear_token():
    config = Config('config.json').config
    config['token'] = None
    Config.dump(config)
Esempio n. 10
0
def segway_showconfig():
    config = Config('config.json').config
    print(json.dumps(config, sort_keys=True, indent=4, ensure_ascii=False))
Esempio n. 11
0
 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)
Esempio n. 12
0
 def setUp(self):
     print('setUp...')
     self.config = Config('config.json').config