Exemplo n.º 1
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))
Exemplo n.º 2
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))
Exemplo n.º 3
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))
Exemplo n.º 4
0
def download(cfg, name, version, depot, no_check):
    """
    Download a template with the specified parameters.

    If the arguments are `download latest` or `download latest kernel`, the latest kernel will be downloaded
    """
    first_run(cfg)
    if name.lower() == 'kernel':
        name = 'kernel'
    elif name == 'latest':
        name = 'kernel'
        if version == 'kernel':
            version = 'latest'

    if version == 'latest' or depot == 'auto' or not no_check:
        click.echo('Fetching online listing to verify available templates.')
        listing = utils.get_available_templates(pros_cfg=cfg.pros_cfg,
                                                template_types=[utils.TemplateTypes.kernel if name == 'kernel'
                                                                else utils.TemplateTypes.library])
        listing = listing.get(utils.TemplateTypes.kernel if name == 'kernel' else utils.TemplateTypes.library)
        listing = {i: d for (i, d) in listing.items() if i.name == name}
        if len(listing) == 0:
            click.echo('No templates were found with the name {}'.format(name))
            click.get_current_context().abort()
            sys.exit()

        if not depot == 'auto':
            if depot not in [d.depot.config.name for ds in listing.values() for d in ds]:
                click.echo('No templates for {} were found on {}'.format(name, depot))
                click.get_current_context().abort()
                sys.exit()
            listing = {i: [d for d in ds if d.depot.config.name == depot] for i, ds in listing.items()
                       if depot in [d.depot.config.name for d in ds]}

        # listing now filtered for depots, if applicable

        if version == 'latest':
            identifier, descriptors = OrderedDict(
                sorted(listing.items(), key=lambda kvp: semver.Version(kvp[0].version))).popitem()
            click.echo('Resolved {} {} to {} {}'.format(name, version, identifier.name, identifier.version))
        else:
            if version not in [i.version for (i, d) in listing.items()]:
                click.echo('No templates for {} were found with the version {}'.format(name, version))
                click.get_current_context().abort()
                sys.exit()
            identifier, descriptors = [(i, d) for (i, d) in listing.items() if i.version == version][0]

        # identifier is now selected...
        if len(descriptors) == 0:
            click.echo('No templates for {} were found with the version {}'.format(name, version))
            click.get_current_context().abort()
            sys.exit()

        if len(descriptors) > 1:
            if name == 'kernel' and depot == 'auto' and 'pros-mainline' in [desc.depot.config.name for desc in
                                                                            descriptors]:
                descriptor = [desc for desc in descriptors if desc.depot.config.name == 'pros-mainline']
            else:
                click.echo('Multiple depots for {}-{} were found. Please specify a depot: '.
                           format(identifier.name, identifier.version))
                options_table = sorted([(descriptors.index(desc), desc.depot.config.name) for desc in descriptors],
                                       key=lambda l: l[1])
                click.echo(tabulate.tabulate(options_table, headers=['', 'Depot']))
                result = click.prompt('Which depot?', default=options_table[0][1],
                                      type=click.Choice(
                                          [str(i) for (i, n) in options_table] + [n for (i, n) in options_table]))
                if result in [str(i) for (i, n) in options_table]:
                    descriptor = [d for d in descriptors if d.depot.config.name == options_table[int(result)][1]][0]
                else:
                    descriptor = [d for d in descriptors if d.depot.config.name == result][0]
        elif depot == 'auto' or descriptors[0].depot.config.name == depot:
            descriptor = descriptors[0]
        else:
            click.echo('Could not find a depot to download {} {}'.format(name, version))
            click.get_current_context().abort()
            sys.exit()
    else:
        identifier = providers.Identifier(name=name, version=version)
        descriptor = utils.TemplateDescriptor(depot=utils.get_depot(utils.get_depot_config(name=depot,
                                                                                           pros_cfg=cfg.pros_cfg)),
                                              offline=False,
                                              online=True)

    click.echo('Downloading {} {} from {} using {}'.format(identifier.name,
                                                           identifier.version,
                                                           descriptor.depot.config.name,
                                                           descriptor.depot.registrar))
    descriptor.depot.download(identifier)
    if identifier.name == 'kernel':
        click.echo('''To create a new PROS project with this kernel, run `pros conduct new <folder> {0} {1}`,
or to upgrade an existing project, run `pros conduct upgrade <folder> {0} {1}'''
                   .format(identifier.version, identifier.depot))
Exemplo n.º 5
0
def download(cfg, name, version, depot, no_check):
    """
    Download a template with the specified parameters.

    If the arguments are `download latest` or `download latest kernel`, the latest kernel will be downloaded
    """
    first_run(cfg)
    if name.lower() == 'kernel':
        name = 'kernel'
    elif name == 'latest':
        name = 'kernel'
        if version == 'kernel':
            version = 'latest'

    if version == 'latest' or depot == 'auto' or not no_check:
        click.echo('Fetching online listing to verify available templates.')
        listing = utils.get_available_templates(pros_cfg=cfg.pros_cfg,
                                                template_types=[utils.TemplateTypes.kernel if name == 'kernel'
                                                                else utils.TemplateTypes.library])
        listing = listing.get(utils.TemplateTypes.kernel if name == 'kernel' else utils.TemplateTypes.library)
        listing = {i: d for (i, d) in listing.items() if i.name == name}
        if len(listing) == 0:
            click.echo('No templates were found with the name {}'.format(name))
            click.get_current_context().abort()
            sys.exit()

        if not depot == 'auto':
            if depot not in [d.depot.config.name for ds in listing.values() for d in ds]:
                click.echo('No templates for {} were found on {}'.format(name, depot))
                click.get_current_context().abort()
                sys.exit()
            listing = {i: [d for d in ds if d.depot.config.name == depot] for i, ds in listing.items()
                       if depot in [d.depot.config.name for d in ds]}

        # listing now filtered for depots, if applicable

        if version == 'latest':
            identifier, descriptors = OrderedDict(sorted(listing.items(), key=lambda kvp: semver.Version(kvp[0].version))).popitem()
            click.echo('Resolved {} {} to {} {}'.format(name, version, identifier.name, identifier.version))
        else:
            if version not in [i.version for (i, d) in listing.items()]:
                click.echo('No templates for {} were found with the version {}'.format(name, version))
                click.get_current_context().abort()
                sys.exit()
            identifier, descriptors = [(i, d) for (i, d) in listing.items() if i.version == version][0]

        # identifier is now selected...
        if len(descriptors) == 0:
            click.echo('No templates for {} were found with the version {}'.format(name, version))
            click.get_current_context().abort()
            sys.exit()

        if len(descriptors) > 1:
            if name == 'kernel' and depot == 'auto' and 'pros-mainline' in [desc.depot.config.name for desc in
                                                                                 descriptors]:
                descriptor = [desc for desc in descriptors if desc.depot.config.name == 'pros-mainline']
            else:
                click.echo('Multiple depots for {}-{} were found. Please specify a depot: '.
                           format(identifier.name, identifier.version))
                options_table = sorted([(descriptors.index(desc), desc.depot.config.name) for desc in descriptors],
                                       key=lambda l: l[1])
                click.echo(tabulate.tabulate(options_table, headers=['', 'Depot']))
                result = click.prompt('Which depot?', default=options_table[0][1],
                                      type=click.Choice(
                                          [str(i) for (i, n) in options_table] + [n for (i, n) in options_table]))
                if result in [str(i) for (i, n) in options_table]:
                    descriptor = [d for d in descriptors if d.depot.config.name == options_table[int(result)][1]][0]
                else:
                    descriptor = [d for d in descriptors if d.depot.config.name == result][0]
        elif depot == 'auto' or descriptors[0].depot.config.name == depot:
            descriptor = descriptors[0]
        else:
            click.echo('Could not find a depot to download {} {}'.format(name, version))
            click.get_current_context().abort()
            sys.exit()
    else:
        identifier = providers.Identifier(name=name, version=version)
        descriptor = utils.TemplateDescriptor(depot=utils.get_depot(utils.get_depot_config(name=depot,
                                                                                           pros_cfg=cfg.pros_cfg)),
                                              offline=False,
                                              online=True)

    click.echo('Downloading {} {} from {} using {}'.format(identifier.name,
                                                           identifier.version,
                                                           descriptor.depot.config.name,
                                                           descriptor.depot.registrar))
    descriptor.depot.download(identifier)
    if identifier.name == 'kernel':
        click.echo('''To create a new PROS project with this kernel, run `pros conduct new <folder> {0} {1}`,
or to upgrade an existing project, run `pros conduct upgrade <folder> {0} {1}'''
                   .format(identifier.version, identifier.depot))