Exemple #1
0
def info_project(cfg, location):
    project = prosconfig.ProjectConfig(path=location)
    details = dict()
    details['kernel'] = project.kernel
    templates = local.get_local_templates(
        pros_cfg=cfg.pros_cfg, template_types=[TemplateTypes.kernel])
    details['kernelUpToDate'] = semver.compare(project.kernel,
                                               sorted(templates, key=lambda t: semver.Version(t.version))[-1].version) \
                                >= 0
    templates = local.get_local_templates(
        pros_cfg=cfg.pros_cfg, template_types=[TemplateTypes.library])
    details['libraries'] = dict()
    if project.libraries.__class__ is dict:
        for (lib, ver) in project.libraries.items():
            details['libraries'][lib] = dict()
            details['libraries'][lib]['version'] = ver
            sorted_versions = sorted(
                [t.version for t in templates if t.name == lib],
                key=lambda v: semver.Version(v))
            if len(sorted_versions) > 0:
                latest = semver.compare(ver, sorted_versions[-1]) >= 0
            else:
                latest = True
            details['libraries'][lib]['latest'] = latest
    click.echo(json.dumps(details))
Exemple #2
0
def upgrade(cfg, kernel, location, depot):
    first_run(cfg)
    templates = local.get_local_templates(pros_cfg=cfg.pros_cfg,
                                          template_types=[TemplateTypes.kernel])  # type: List[Identifier]
    if not templates or len(templates) == 0:
        click.echo('No templates have been downloaded! Use `pros conduct download` to download the latest kernel.')
        click.get_current_context().abort()
        sys.exit()
    kernel_version = kernel
    if kernel == 'latest':
        kernel_version = sorted(templates, key=lambda t: semver.Version(t.version))[-1].version
        proscli.utils.debug('Resolved version {} to {}'.format(kernel, kernel_version))
    templates = [t for t in templates if t.version == kernel_version]
    depot_registrar = depot
    if depot == 'auto':
        templates = [t for t in templates if t.version == kernel_version]
        if not templates or len(templates) == 0:
            click.echo('No templates exist for {}'.format(kernel_version))
            click.get_current_context().abort()
            sys.exit()
        if 'pros-mainline' in [t.depot for t in templates]:
            depot_registrar = 'pros-mainline'
        else:
            depot_registrar = [t.depot for t in templates][0]
        proscli.utils.debug('Resolved depot {} to {}'.format(depot, depot_registrar))
    templates = [t for t in templates if t.depot == depot_registrar]
    if not templates or len(templates) == 0:
        click.echo('No templates were found for kernel version {} on {}'.format(kernel_version, depot_registrar))
    template = templates[0]
    if not os.path.isabs(location):
        location = os.path.abspath(location)
    click.echo('Upgrading existing project to {} on {} at {}'.format(template.version, template.depot, location))
    local.upgrade_project(identifier=template, dest=location, pros_cli=cfg.pros_cfg)
Exemple #3
0
def register(cfg, location, kernel):
    first_run(cfg)
    kernel_version = kernel
    if kernel_version == 'latest':
        templates = local.get_local_templates(pros_cfg=cfg.pros_cfg,
                                              template_types=[
                                                  TemplateTypes.kernel
                                              ])  # type: List[Identifier]
        if not templates or len(templates) == 0:
            click.echo(
                'No templates have been downloaded! Use `pros conduct download` to download the latest kernel or'
                ' specify a kernel manually.')
            click.get_current_context().abort()
            sys.exit()
        kernel_version = sorted(
            templates, key=lambda t: semver.Version(t.version))[-1].version
        proscli.utils.debug('Resolved version {} to {}'.format(
            kernel, kernel_version))

    cfg = prosconfig.ProjectConfig(location, create=True, raise_on_error=True)
    cfg.kernel = kernel_version
    if not location:
        click.echo('Location not specified, registering current directory.')
    click.echo('Registering {} with kernel {}'.format(
        location or os.path.abspath('.'), kernel_version))
    cfg.save()
def upgrade(cfg, kernel, location, depot):
    first_run(cfg)
    templates = local.get_local_templates(pros_cfg=cfg.pros_cfg,
                                          template_types=[TemplateTypes.kernel])  # type: List[Identifier]
    if not templates or len(templates) == 0:
        click.echo('No templates have been downloaded! Use `pros conduct download` to download the latest kernel.')
        click.get_current_context().abort()
        sys.exit()
    kernel_version = kernel
    if kernel == 'latest':
        kernel_version = sorted(templates, key=lambda t: semver.Version(t.version))[-1].version
        proscli.utils.debug('Resolved version {} to {}'.format(kernel, kernel_version))
    templates = [t for t in templates if t.version == kernel_version]
    depot_registrar = depot
    if depot == 'auto':
        templates = [t for t in templates if t.version == kernel_version]
        if not templates or len(templates) == 0:
            click.echo('No templates exist for {}'.format(kernel_version))
            click.get_current_context().abort()
            sys.exit()
        if 'pros-mainline' in [t.depot for t in templates]:
            depot_registrar = 'pros-mainline'
        else:
            depot_registrar = [t.depot for t in templates][0]
        proscli.utils.debug('Resolved depot {} to {}'.format(depot, depot_registrar))
    templates = [t for t in templates if t.depot == depot_registrar]
    if not templates or len(templates) == 0:
        click.echo('No templates were found for kernel version {} on {}'.format(kernel_version, depot_registrar))
    template = templates[0]
    if not os.path.isabs(location):
        location = os.path.abspath(location)
    click.echo('Upgrading existing project from {} on {} at {}'.format(template.version, template.depot, location))
    local.upgrade_project(identifier=template, dest=location, pros_cli=cfg.pros_cfg)
Exemple #5
0
def newlib(cfg, location, library, version, depot):
    if not (version == 'latest') and len(version.split('.')) < 3:
        depot = version
        version = 'latest'
    first_run(cfg)
    templates = local.get_local_templates(pros_cfg=cfg.pros_cfg,
                                          template_types=[TemplateTypes.library])  # type: List[Identifier]
    selected = None
    to_remove = []
    if not templates or len(templates) == 0:
        click.echo('No templates have been downloaded! Use `pros conduct download` to download the latest kernel.')
        click.get_current_context().abort()
        sys.exit()
    templates = [t for t in templates if t.name == library]
    to_remove = []
    if version == 'latest':
        lib_version = sorted(templates, key=lambda t: semver.Version(t.version))[-1].version
        highest = lib_version.split('.')
        for template in templates:
            curr = template.version.split('.')
            if len(highest) > len(curr):
                to_remove.append(template)
            for i in range(len(highest)):
                if curr[i] < highest[i]:
                    to_remove.append(template)
                    break

    else:
        for template in templates:
            if template.version != version:
                to_remove.append(template)
    for template in to_remove:
        templates.remove(template)
    to_remove = []
    if depot == 'auto':
        for template in templates:
            if template.depot == 'pros-mainline':
                selected = template
                break
        if selected is None:
            selected = templates[0]
    else:
        for template in templates:
            if template.depot != depot:
                to_remove.append(template)
        for template in to_remove:
            templates.remove(template)
        to_remove = []
        if len(templates) > 0:
            selected = templates[0]
        else:
            click.echo(
                'No local libraries match the specified name, version, and depot. Check your arguments and make sure the appropriate libraries are downloaded')
            click.get_current_context().abort()
            sys.exit()
    local.install_lib(selected, location, cfg.pros_cfg)
    print('Installed library {} v. {} in {} from {}'.format(selected.name, selected.version, location, selected.depot))
def register(cfg, location, kernel):
    first_run(cfg)
    kernel_version = kernel
    if kernel_version == 'latest':
        templates = local.get_local_templates(pros_cfg=cfg.pros_cfg,
                                              template_types=[TemplateTypes.kernel])  # type: List[Identifier]
        if not templates or len(templates) == 0:
            click.echo('No templates have been downloaded! Use `pros conduct download` to download the latest kernel or'
                       ' specify a kernel manually.')
            click.get_current_context().abort()
            sys.exit()
        kernel_version = sorted(templates, key=lambda t: semver.Version(t.version))[-1].version
        proscli.utils.debug('Resolved version {} to {}'.format(kernel, kernel_version))

    cfg = prosconfig.ProjectConfig(location, create=True, raise_on_error=True)
    cfg.kernel = kernel_version
    click.echo('Registering {} with kernel {}'.format(location, kernel_version))
    cfg.save()