コード例 #1
0
ファイル: cli.py プロジェクト: mekayama/patchbox-cli
def reconnect():
    """Reconnect to default WiFi network"""
    networks = get_networks()
    if len(networks) < 1:
        raise click.ClickException('WiFi network config not found!')
    do_reconnect()
    do_go_back_if_ineractive()
コード例 #2
0
ファイル: cli.py プロジェクト: mekayama/patchbox-cli
def interactions(ctx):
    """List all supported Button interactions"""
    if not ctx.obj.is_supported():
        raise click.ClickException('Button software not found!')
    for interaction in ctx.obj.INTERACTIONS:
        click.echo(interaction)
    do_go_back_if_ineractive()
コード例 #3
0
ファイル: cli.py プロジェクト: mekayama/patchbox-cli
def hotspot_status():
    """Display WiFi hotspot status"""
    active = is_hotspot_active()
    click.echo('hotspot_active={}'.format(int(active)))
    for item in get_hs_config():
        line = '{}={}'.format(item.get('key'), item.get('value'))
        click.echo(line)
    do_go_back_if_ineractive()
コード例 #4
0
ファイル: cli.py プロジェクト: mekayama/patchbox-cli
def actions(ctx):
    """List all supported Button actions"""
    if not ctx.obj.is_supported():
        raise click.ClickException('Button software not found!')
    for action in ctx.obj.get_actions():
        path = action.get('value')
        if path:
            click.echo(path)
    do_go_back_if_ineractive()
コード例 #5
0
ファイル: cli.py プロジェクト: mekayama/patchbox-cli
def scan():
    """List available WiFi networks"""
    if not is_wifi_supported():
        raise click.ClickException('WiFi interface not found!')
    if is_disabled():
        do_enable()
    ssids = get_ssids()
    for ssid in ssids:
        click.echo(ssid)
    do_go_back_if_ineractive()
コード例 #6
0
ファイル: cli.py プロジェクト: mekayama/patchbox-cli
def environment(ctx, option):
    """Choose Boot environment (Desktop or Console)"""
    option = do_ensure_param(ctx, 'option')
    if option == 'desktop':
        subprocess.call(['sudo', 'chmod', '+x', os.path.dirname(os.path.realpath(__file__)) + '/scripts/set_boot_to_desktop.sh'])
        subprocess.call(['sudo', 'sh', '-c', os.path.dirname(os.path.realpath(__file__)) + '/scripts/set_boot_to_desktop.sh'])
    if option == 'console':
        subprocess.call(['sudo', 'chmod', '+x', os.path.dirname(os.path.realpath(__file__)) + '/scripts/set_boot_to_console.sh'])
        subprocess.call(['sudo', 'sh', '-c', os.path.dirname(os.path.realpath(__file__)) + '/scripts/set_boot_to_console.sh'])
    do_go_back_if_ineractive(silent=True)
コード例 #7
0
def cli():
    """Display System info"""
    message = 'IP Address: {}'\
        '\nHostname: {}'.format(get_ip(), get_hostname())
    if is_pisound():
        message += '\nPisound Button Version: {}'\
            '\nPisound Server Version: {}\nPisound Firmware Version: {}'\
            '\nPisound Serial Number: {}'.format(get_btn_version(), get_ctl_version(
            ), get_version(), get_serial())
    click.echo(message)
    do_go_back_if_ineractive()
コード例 #8
0
ファイル: cli.py プロジェクト: mekayama/patchbox-cli
def hotspot_config(ctx, name, channel, password):
    """Change WiFi hotspot settings"""
    if not is_wifi_supported():
        raise click.ClickException('WiFi interface not found!')
    name = do_ensure_param(ctx, 'name')
    channel = do_ensure_param(ctx, 'channel')
    password = do_ensure_param(ctx, 'password')
    if name:
        update_hs_config('ssid', name)
    if channel:
        update_hs_config('channel', channel)
    if password:
        update_hs_config('wpa_passphrase', password)
    if is_hotspot_active():
        do_hotspot_disable()
        do_hotspot_enable()
    do_go_back_if_ineractive(ctx, silent=True)
コード例 #9
0
ファイル: cli.py プロジェクト: mekayama/patchbox-cli
def assign(ctx, interaction, action):
    """Assign different Button interaction to different actions"""
    if not ctx.obj.is_supported():
        raise click.ClickException('Button software not found!')

    interaction = do_ensure_param(ctx, 'interaction')
    action = do_ensure_param(ctx, 'action')

    if not interaction:
        raise click.ClickException(
            'Button interaction not provided! Use --interaction INTERACTION option.')

    if not action:
        raise click.ClickException(
            'Button action not provided! Use --action ACTION option.')

    ctx.obj.update_config(interaction, action.get('value'))
    do_go_back_if_ineractive(ctx, silent=True)
コード例 #10
0
def config(ctx, card, rate, buffer, period):
    """Update Jack service settings"""
    if not jack_installed():
        raise click.ClickException('Jack software not found!')
    card = do_ensure_param(ctx, 'card')
    if card:
        update_jack_config('-d', 'hw:{}'.format(card.get('value')))
    rate = do_ensure_param(ctx, 'rate')
    if rate:
        update_jack_config('-r', rate)
    buffer = do_ensure_param(ctx, 'buffer')
    if buffer:
        update_jack_config('-p', buffer)
    period = do_ensure_param(ctx, 'period')
    if period:
        update_jack_config('-n', period)
    if card or rate or buffer or period:
        jack_restart()
        jack_verify()
    do_go_back_if_ineractive(ctx)
コード例 #11
0
ファイル: cli.py プロジェクト: mekayama/patchbox-cli
def connect(ctx, name, country, password):
    """Connect to WiFi network"""
    if not is_wifi_supported():
        raise click.ClickException('WiFi interface not found!')
    if is_disabled():
        do_enable()
    name = do_ensure_param(ctx, 'name')
    password = do_ensure_param(ctx, 'password')
    if country:
        set_wifi_country(country)
    elif get_wifi_country() == 'unset':
        country = do_ensure_param(ctx, 'country')
        if not country:
            raise click.ClickException(
                'WiFi country not set! Use --country COUNTRY_CODE option.')
    if not name:
        raise click.ClickException(
            'WiFi name (SSID) not set! Use --name NETWORK_NAME option.')
    do_forget_all()
    do_connect(name, password)
    do_reconnect()
    do_go_back_if_ineractive(ctx)
コード例 #12
0
ファイル: cli.py プロジェクト: mekayama/patchbox-cli
def hotspot_enable():
    """Enable WiFi hotspot"""
    do_hotspot_enable()
    do_go_back_if_ineractive()
コード例 #13
0
def restart():
    """Restart Jack service"""
    jack_restart()
    do_go_back_if_ineractive()
コード例 #14
0
def status():
    """Display Jack service status"""
    click.echo(get_status())
    do_go_back_if_ineractive()
コード例 #15
0
ファイル: cli.py プロジェクト: mekayama/patchbox-cli
def status():
    """Display WiFi status"""
    if not is_wifi_supported():
        raise click.ClickException('WiFi interface not found!')
    click.echo(get_status())
    do_go_back_if_ineractive()
コード例 #16
0
ファイル: cli.py プロジェクト: mekayama/patchbox-cli
def enable():
    """Enable WiFi interface"""
    if not is_wifi_supported():
        raise click.ClickException('WiFi interface not found!')
    do_enable()
    do_go_back_if_ineractive()
コード例 #17
0
def start():
    """Start Jack service"""
    jack_start()
    do_go_back_if_ineractive()
コード例 #18
0
def stop():
    """Stop Bluetooth device pairing"""
    if not is_supported():
        raise click.ClickException('Bluetooth is not supported!')
    subprocess.call(['/usr/local/pisound/scripts/pisound-btn/system/set_bt_discoverable.sh', 'false'])
    do_go_back_if_ineractive(silent=True)
コード例 #19
0
def status():
    """Display Bluetooth status"""
    click.echo(get_status().strip())
    do_go_back_if_ineractive()
コード例 #20
0
ファイル: cli.py プロジェクト: mekayama/patchbox-cli
def cli():
    """Change Password"""
    subprocess.call(['passwd', os.environ['SUDO_USER']])
    do_go_back_if_ineractive()
コード例 #21
0
ファイル: cli.py プロジェクト: mekayama/patchbox-cli
def hotspot_disable():
    """Disable WiFi hotspot"""
    if not is_wifi_supported():
        raise click.ClickException('WiFi interface not found!')
    do_hotspot_disable()
    do_go_back_if_ineractive()
コード例 #22
0
ファイル: cli.py プロジェクト: mekayama/patchbox-cli
def disable():
    """Disable WiFi interface"""
    do_disable()
    do_go_back_if_ineractive()
コード例 #23
0
def stop():
    """Stop Jack service"""
    jack_stop()
    do_go_back_if_ineractive()
コード例 #24
0
ファイル: cli.py プロジェクト: mekayama/patchbox-cli
def disconnect():
    """Disconnect from default network"""
    do_disconnect()
    do_go_back_if_ineractive()
コード例 #25
0
ファイル: cli.py プロジェクト: mekayama/patchbox-cli
def config(ctx):
    """Configuration wizard (Interactive)"""
    manager = ctx.obj
    if not isinstance(manager, PatchboxModuleManager):
        manager = PatchboxModuleManager()

    options = [{
        'value':
        module.path,
        'title':
        '{}: {} v{}'.format(module.name, module.description, module.version)
    } for module in manager.get_all_modules()]
    options = sorted(options, key=lambda k: k.get('title'))
    options.append({
        'value': 'none',
        'title': 'none: Default Patchbox OS environment'
    })

    close, value = do_menu('Choose a module:', options, cancel='Cancel')

    if close:
        do_go_back_if_ineractive(ctx, steps=2, silent=True)
        return

    if value.get('value') == 'none':
        manager.deactivate()
        do_go_back_if_ineractive(ctx, steps=2)
        return

    module = manager.get_module_by_path(value.get('value'))
    manager.activate(module, autolaunch=False, autoinstall=True)

    for ser in [
            s for s in module.get_module_services() if s.auto_start == False
    ]:

        close, value = do_yesno('Do you want to start {} now?'.format(
            ser.name))
        if close == 0:
            manager._service_manager.enable_start_unit(ser)
        else:
            manager._service_manager.stop_disable_unit(ser)

    if module.autolaunch:
        arg = None

        if module.autolaunch == 'auto':
            pass

        if module.autolaunch == 'list':
            options = manager.list(module)
            close, arg = do_menu('Choose an option for autolaunch on boot',
                                 options,
                                 cancel='Cancel')
            if close:
                manager._set_autolaunch_argument(module, None)
                do_go_back_if_ineractive(ctx, steps=2)
                return

        if module.autolaunch == 'argument':
            close, arg = do_inputbox(
                'Enter an argument for autolaunch on boot')
            if close:
                manager._set_autolaunch_argument(module, None)
                do_go_back_if_ineractive(ctx, steps=2)
                return

        if module.autolaunch == 'path':
            while True:
                close, arg = do_inputbox('Enter a path for autolaunch on boot')
                if close:
                    manager._set_autolaunch_argument(module, None)
                    do_go_back_if_ineractive(ctx, steps=2)
                    return

                if os.path.isfile(arg) or os.path.isdir(arg):
                    break
                do_msgbox('Argument must be a valid file path')

        if arg:
            manager._set_autolaunch_argument(module, arg)

        close, value = do_yesno('Do you want to launch now?')
        if close == 0:
            manager.launch(module, arg=arg)

    do_go_back_if_ineractive(ctx, steps=2)
コード例 #26
0
ファイル: cli.py プロジェクト: mekayama/patchbox-cli
def status(ctx):
    """Display Button status"""
    if not ctx.obj.is_supported():
        raise click.ClickException('Button software not found!')
    click.echo(ctx.obj.get_status())
    do_go_back_if_ineractive()