Exemple #1
0
def first_run(ctx: proscli.utils.State,
              force=False,
              defaults=False,
              doDownload=True,
              reapplyProviders=False):
    if len(utils.get_depot_configs(ctx.pros_cfg)) == 0:
        click.echo('You don\'t currently have any depots configured.')
    if len(utils.get_depot_configs(ctx.pros_cfg)) == 0 or force:
        if defaults or click.confirm(
                'Add the official PROS kernel depot, pros-mainline?',
                default=True):
            click.get_current_context().invoke(add_depot,
                                               name='pros-mainline',
                                               registrar='github-releases',
                                               location='purduesigbots/pros',
                                               configure=False)
            click.echo(
                'Added pros-mainline to available depots. '
                'Add more depots in the future by running `pros conduct add-depot`\n'
            )
            if (defaults or click.confirm('Download the latest kernel?',
                                          default=True)) and doDownload:
                click.get_current_context().invoke(download,
                                                   name='kernel',
                                                   depot='pros-mainline')
    if reapplyProviders:
        click.echo('Applying default providers')
        ctx.pros_cfg.applyDefaultProviders()
Exemple #2
0
def config_depot(cfg, name):
    if name not in [d.name for d in utils.get_depot_configs(cfg.pros_cfg)]:
        click.echo('{} isn\'t a registered depot! Have you added it using `pros conduct add-depot`?')
        click.get_current_context().abort()
        sys.exit()
    depot = [d for d in utils.get_depot_configs(cfg.pros_cfg) if d.name == name][0]
    config = utils.get_all_provider_types(cfg.pros_cfg)[depot.registrar].config
    depot.registrar_options = prompt_config(config, depot.registrar_options)
    depot.save()
def config_depot(cfg, name):
    if name not in [d.name for d in utils.get_depot_configs(cfg.pros_cfg)]:
        click.echo('{} isn\'t a registered depot! Have you added it using `pros conduct add-depot`?')
        click.get_current_context().abort()
        sys.exit()
    depot = [d for d in utils.get_depot_configs(cfg.pros_cfg) if d.name == name][0]
    depot.registrar_options = utils.get_all_provider_types(cfg.pros_cfg)[depot.registrar](None) \
        .configure_registrar_options(default=depot.registrar_options)
    depot.save()
def first_run(ctx: proscli.utils.State, force=False, defaults=False):
    if len(utils.get_depot_configs(ctx.pros_cfg)) == 0:
        click.echo('You don\'t currently have any depots configured.')
    if len(utils.get_depot_configs(ctx.pros_cfg)) == 0 or force:
        if defaults or click.confirm('Add the official PROS kernel depot, pros-mainline?', default=True):
            click.get_current_context().invoke(add_depot, name='pros-mainline',
                                               registrar='github-releases',
                                               location='purduesigbots/pros',
                                               configure=False)
            click.echo('Added pros-mainline to available depots. '
                       'Add more depots in the future by running `pros conduct add-depot`\n')
            if defaults or click.confirm('Download the latest kernel?', default=True):
                click.get_current_context().invoke(download, name='kernel', depot='pros-mainline')
Exemple #5
0
def remove_depot(cfg, name):
    if name == 'pros-mainline':
        raise click.BadParameter('Cannot delete pros-mainline!')

    for depot in [d for d in utils.get_depot_configs(cfg.pros_cfg) if d.name == name]:
        click.echo('Removing {} ({})'.format(depot.name, depot.location))
        depot.delete()
def remove_depot(cfg, name):
    if name == 'pros-mainline':
        raise click.BadParameter('Cannot delete pros-mainline!')

    for depot in [d for d in utils.get_depot_configs(cfg.pros_cfg) if d.name == name]:
        click.echo('Removing {} ({})'.format(depot.name, depot.location))
        depot.delete()
def list_templates(cfg, template_types, filters, offline_only):
    """
    List templates with the applied filters
    """
    first_run(cfg)
    filters = [f for f in filters if f is not None]
    if not filters:
        filters = ['.*']
    if filters != ['.*']:
        click.echo('Providers matching any of {}: {}'
                   .format(filters,
                           [d.name for d in utils.get_depot_configs(cfg.pros_cfg, filters)]))
    result = utils.get_available_templates(cfg.pros_cfg,
                                           template_types=template_types,
                                           filters=filters,
                                           offline_only=offline_only)
    table = sum(
        [[(i.version, d.depot.config.name, 'online' if d.online else '', 'offline' if d.offline else '') for d in ds]
         for i, ds in result[TemplateTypes.kernel].items()], [])
    if TemplateTypes.kernel in template_types:
        if not cfg.machine_output:
            click.echo('Available kernels:')
            click.echo(tabulate.tabulate(table, headers=['Version', 'Depot', 'Online', 'Offline']))
        else:
            table = [{
                         'version': e[0],
                         'depot': e[1],
                         'online': e[2] == 'online',
                         'offline': e[3] == 'offline'
                     }
                     for e in table]
            click.echo(json.dumps(table))
Exemple #8
0
def list_templates(cfg, template_types, filters, offline_only):
    """
    List templates with the applied filters
    """
    first_run(cfg)
    filters = [f for f in filters if f is not None]
    if not filters:
        filters = ['.*']
    if filters != ['.*']:
        click.echo('Providers matching any of {}: {}'.format(
            filters,
            [d.name for d in utils.get_depot_configs(cfg.pros_cfg, filters)]))
    result = utils.get_available_templates(cfg.pros_cfg,
                                           template_types=template_types,
                                           filters=filters,
                                           offline_only=offline_only)
    table = sum(
        [[(i.version, d.depot.config.name, 'online' if d.online else '',
           'offline' if d.offline else '') for d in ds]
         for i, ds in result[TemplateTypes.kernel].items()], [])
    if TemplateTypes.kernel in template_types:
        if not cfg.machine_output:
            click.echo('Available kernels:')
            click.echo(
                tabulate.tabulate(
                    table, headers=['Version', 'Depot', 'Online', 'Offline']))
        else:
            table = [{
                'version': e[0],
                'depot': e[1],
                'online': e[2] == 'online',
                'offline': e[3] == 'offline'
            } for e in table]
            click.echo(json.dumps(table))
Exemple #9
0
def list_templates(cfg, template_types, filters, offline_only):
    """
    List templates with the applied filters. The first item is guaranteed to be the latest overall template
    """
    first_run(cfg)
    filters = [f for f in filters if f is not None]
    if not filters:
        filters = ['.*']
    if filters != ['.*']:
        click.echo('Providers matching any of {}: {}'.format(
            filters,
            [d.name for d in utils.get_depot_configs(cfg.pros_cfg, filters)]))
    result = utils.get_available_templates(cfg.pros_cfg,
                                           template_types=template_types,
                                           filters=filters,
                                           offline_only=offline_only)
    if TemplateTypes.kernel in template_types:
        table = sum(
            [[(i.version, d.depot.config.name, 'online' if d.online else '',
               'offline' if d.offline else '') for d in ds]
             for i, ds in result[TemplateTypes.kernel].items()], [])
        table = sorted(table, key=lambda v: semver.Version(v[0]), reverse=True)
        if not cfg.machine_output:
            click.echo('Available kernels:')
            click.echo(
                tabulate.tabulate(
                    table, headers=['Version', 'Depot', 'Online', 'Offline']))
        else:
            table = [{
                'version': e[0],
                'depot': e[1],
                'online': e[2] == 'online',
                'offline': e[3] == 'offline'
            } for e in table]
            click.echo(json.dumps(table))
    if TemplateTypes.library in template_types:
        table = sum(
            [[(i.name, i.version, d.depot.config.name,
               'online' if d.online else '', 'offline' if d.offline else '')
              for d in ds]
             for i, ds in result[TemplateTypes.library].items()], [])
        if not cfg.machine_output:
            click.echo('Available libraries:')
            click.echo(
                tabulate.tabulate(table,
                                  headers=[
                                      'Library', 'Version', 'Depot', 'Online',
                                      'Offline'
                                  ]))
        else:
            table = [{
                'library': e[0],
                'version': e[1],
                'depot': e[2],
                'online': e[3] == 'online',
                'offline': e[4] == 'offline'
            } for e in table]
            click.echo(json.dumps(table))
def list_depots(cfg):
    first_run(cfg)
    depots = utils.get_depot_configs()
    if not bool(depots):
        click.echo('No depots currently registered! Use `pros conduct add-depot` to add a new depot')
    else:
        click.echo([(d.name, d.registrar, d.location) for d in depots])
        click.echo(tabulate.tabulate([(d.name, d.registrar, d.location) for d in depots],
                                     ['Name', 'Registrar', 'Location'], tablefmt='simple'))
Exemple #11
0
def list_depots(cfg):
    first_run(cfg)
    depots = utils.get_depot_configs()
    if not bool(depots):
        click.echo(
            'No depots currently registered! Use `pros conduct add-depot` to add a new depot'
        )
    else:
        click.echo([(d.name, d.registrar, d.location) for d in depots])
        click.echo(
            tabulate.tabulate([(d.name, d.registrar, d.location)
                               for d in depots],
                              ['Name', 'Registrar', 'Location'],
                              tablefmt='simple'))
Exemple #12
0
def list_depots(cfg):
    if not cfg.machine_output:
        first_run(cfg)
    depots = utils.get_depot_configs()
    if cfg.machine_output:
        table = [{
            'name': d.name,
            'registrar': d.registrar,
            'location': d.location
        } for d in depots]
        click.echo(json.dumps(table))
    else:
        if not bool(depots):
            click.echo('No depots currently registered! Use `pros conduct add-depot` to add a new depot')
        else:
            click.echo([(d.name, d.registrar, d.location) for d in depots])
            click.echo(tabulate.tabulate([(d.name, d.registrar, d.location) for d in depots],
                                         ['Name', 'Registrar', 'Location'], tablefmt='simple'))