예제 #1
0
def main(args):
    image_file = os.path.abspath(args.image)
    appdir.chdir_to_app_dir(args.appdir)
    app_name = appdir.get_current_app_name()

    api.invoke('POST', '/apps/{}/deployments'.format(app_name),
               params={ 'comment': args.comment },
               files={ 'image': open(image_file, 'rb') })
예제 #2
0
파일: new.py 프로젝트: sh19910711/ms-cli
def main(args):
    path = args.path
    app_name = os.path.basename(path)

    generate_dir(path)
    generate_file(os.path.join(path, 'application.yaml'), APPLICATION_YAML,
                  locals())
    generate_file(os.path.join(path, 'main.cpp'), MAIN_CPP)
    generate_file(os.path.join(path, '.gitignore'), GITIGNORE)

    if args.register:
        api.invoke('POST', '/apps', params={'app_name': app_name})
        success("registered")
예제 #3
0
def main(args):
    appdir.get_current_app_name()
    app_name = appdir.get_current_app_name()

    # TODO: use WebSocket
    since = None
    try:
        while True:
            r = api.invoke('GET', '/apps/{}/log'.format(app_name),
                           {'since': since})
            for line in r.json()['log']:
                timestamp, _, device, message = line.split(':', 3)
                date = datetime.datetime.fromtimestamp(float(timestamp))
                print("{date}  {device} | {message}".format(
                    **{
                        'date': colored(date.strftime('%H:%M:%S'), 'blue'),
                        'device': colored(device, 'magenta'),
                        'message': message
                    }))

                since = timestamp

            time.sleep(4)
    except KeyboardInterrupt:
        sys.exit()
예제 #4
0
def main(args):
    try:
        board = import_module('makestack.boards.{}'.format(args.board))
    except ImportError:
        error('unknown board type: {}'.format(args.board))

    if args.reinstall:
        r = api.invoke('GET', 'devices/{}'.format(args.device_name))
        device_secret = r.json()['device_secret']
    else:
        if args.device_secret is None:
            device_secret = register_new_device(args.device_name, args.board)
        else:
            device_secret = args.device_secret

    url = api.get_credentials()['url']
    parsed_url = urllib.parse.urlparse(url)
    hostname = parsed_url.hostname
    if parsed_url.port is None:
        port = '443' if parsed_url.scheme == 'https' else '80'
    else:
        port = str(parsed_url.port)

    tls = 'yes' if parsed_url.scheme == 'https' else 'no'

    if args.firmware is None:
        original = get_stable_firmware(board.get_firmware_url())
    else:
        original = args.firmware

    with tempfile.NamedTemporaryFile() as f:
        image = open(original, 'rb').read()

        image = replace_and_fill(image, "__VERY_VERY_LONG_SERVER_HOST_NAME__REPLACE_ME__", hostname)
        image = replace_and_fill(image, "__PORT__REPLACE_ME__", port)
        image = replace_and_fill(image, "__TLS__REPLACE_ME__", tls)
        image = replace_and_fill(image, "__VERY_VERY_LONG_DEVICE_SECRET__REPLACE_ME__", device_secret)
        image = replace_and_fill(image, "__WIFI_SSID__REPLACE_ME__", args.wifi_ssid)
        image = replace_and_fill(image, "__WIFI_PASSWORD__REPLACE_ME__", args.wifi_password)

        f.write(image)
        f.flush()

        if args.device_path is None:
            dev_file = detect_device_path()
        else:
            dev_file = args.device_path

        board.install(dev_file, f.name)

    success("done")
예제 #5
0
def change_password(args):
    current_password = get_env_or_ask("MAKESTACK_CURRENT_PASSWORD",
                                      "Current Password",
                                      password=True)
    new_password = get_env_or_ask("MAKESTACK_NEW_PASSWORD",
                                  "New Password",
                                  password=True)
    password_confirmation = get_env_or_ask("MAKESTACK_PASSWORD_CONFIRMATION",
                                           "New Password (confirmation)",
                                           password=True)

    if new_password != password_confirmation:
        error("New passwords din't match.")

    r = api.invoke('PUT',
                   '/auth/password',
                   params={
                       'current_password': current_password,
                       'password': new_password,
                       'password_confirmation': password_confirmation
                   },
                   prepend_user_path=False)
예제 #6
0
def main(args):
    r = api.invoke('GET', '/devices')
    for device in r.json()['devices']:
        print("{name} ({board}): {status}".format(**device))
예제 #7
0
파일: env.py 프로젝트: sh19910711/ms-cli
def set_(args):
    api.invoke('PUT',
               '/devices/{}/envvars/{}'.format(args.device_name, args.key),
               params={"value": args.value})
예제 #8
0
파일: env.py 프로젝트: sh19910711/ms-cli
def list_(args):
    r = api.invoke('GET', '/devices/{}/envvars'.format(args.device_name))
    for env in r.json()['envvars']:
        print("{name}={value}".format(**env))
예제 #9
0
def main(args):
    appdir.chdir_to_app_dir(args.appdir)
    app_name = appdir.get_current_app_name()
    api.invoke('POST', '/apps', params={ 'app_name': app_name })
예제 #10
0
def register_new_device(device_name, board):
    r = api.invoke('POST', 'devices', params={ 'name': device_name, 'board': board })
    return r.json()['device_secret']