Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .vs/ProjectSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"CurrentProjectSetting": null
}
Binary file added .vs/slnx.sqlite
Binary file not shown.
43 changes: 29 additions & 14 deletions pros/cli/conductor.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ def uninstall_template(project: c.Project, query: c.BaseTemplate, remove_user: b
@click.argument('path', type=click.Path())
@click.argument('target', default=c.Conductor().default_target, type=click.Choice(['v5', 'cortex']))
@click.argument('version', default='latest')
@click.option('--download/--no-download', 'download_ok', default=True, show_default=True,
help='(Dis)allow download and use of remote templates in new projects')
@click.option('--force-user', 'force_user', default=False, is_flag=True,
help='Replace all user files in a template')
@click.option('--force-system', '-f', 'force_system', default=False, is_flag=True,
Expand Down Expand Up @@ -207,25 +209,38 @@ def new_project(ctx: click.Context, path: str, target: str, version: str,
'! Delete it first. Are you creating a project in an existing one?', extra={'sentry': False})
ctx.exit(-1)
try:
_conductor = c.Conductor()
if target is None:
target = _conductor.default_target
project = _conductor.new_project(path, target=target, version=version,
force_user=force_user, force_system=force_system,
no_default_libs=no_default_libs, **kwargs)
ui.echo('New PROS Project was created:', output_machine=False)
ctx.invoke(info_project, project=project)

if compile_after or build_cache:
with ui.Notification():
ui.echo('Building project...')
ctx.exit(project.compile([], scan_build=build_cache))

project = _create_project(ctx=ctx, path=path,target=target, version=version,
force_user=force_user, force_system=force_system,
compile_after=compile_after, build_cache=build_cache, **kwargs)
ctx.exit(project.compile([], scan_build=build_cache))
except Exception as e:
pros.common.logger(__name__).exception(e)
ctx.exit(-1)


def _create_project(ctx: click.Context, path: str, target: str, version: str,
force_user: bool = False, force_system: bool = False,
no_default_libs: bool = False, compile_after: bool = True, build_cache: bool = None, **kwargs):
"""
Helper function for new_project

Visit https://pros.cs.purdue.edu/v5/cli/conductor.html to learn more
"""
_conductor = c.Conductor()
if target is None:
target = _conductor.default_target
project = _conductor.new_project(path, target=target, version=version,
force_user=force_user, force_system=force_system,
no_default_libs=no_default_libs, **kwargs)
ui.echo('New PROS Project was created:', output_machine=False)
ctx.invoke(info_project, project=project)
if compile_after or build_cache:
with ui.Notification():
ui.echo('Building project...')
return project



@conductor.command('query-templates',
aliases=['search-templates', 'ls-templates', 'lstemplates', 'querytemplates', 'searchtemplates'],
context_settings={'ignore_unknown_options': True})
Expand Down
25 changes: 14 additions & 11 deletions pros/conductor/conductor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
import shutil
from pathlib import Path
from typing import *

import urllib.request
import urllib.error
import click
from semantic_version import Spec, Version

Expand Down Expand Up @@ -97,22 +98,17 @@ def purge_template(self, template: LocalTemplate):
shutil.rmtree(template.location)
self.save()

def resolve_templates(self, identifier: Union[str, BaseTemplate], allow_online: bool = True,
allow_offline: bool = True, force_refresh: bool = False,
def resolve_templates(self, identifier: Union[str, BaseTemplate], force_refresh: bool = False,
unique: bool = True, **kwargs) -> List[BaseTemplate]:
results = list() if not unique else set()
kernel_version = kwargs.get('kernel_version', None)
if isinstance(identifier, str):
query = BaseTemplate.create_query(name=identifier, **kwargs)
else:
query = identifier
if allow_offline:
offline_results = filter(lambda t: t.satisfies(query, kernel_version=kernel_version), self.local_templates)
if unique:
results.update(offline_results)
else:
results.extend(offline_results)
if allow_online:

try:
urllib.request('http://216.58.192.142', timeout=1)
for depot in self.depots.values():
online_results = filter(lambda t: t.satisfies(query, kernel_version=kernel_version),
depot.get_remote_templates(force_check=force_refresh, **kwargs))
Expand All @@ -122,6 +118,13 @@ def resolve_templates(self, identifier: Union[str, BaseTemplate], allow_online:
results.extend(online_results)
logger(__name__).debug('Saving Conductor config after checking for remote updates')
self.save() # Save self since there may have been some updates from the depots
except Exception as err:
logger(__name__).warn("Failed to connect to Github.")
offline_results = filter(lambda t: t.satisfies(query, kernel_version=kernel_version), self.local_templates)
if unique:
results.update(offline_results)
else:
results.extend(offline_results)
return list(results)

def resolve_template(self, identifier: Union[str, BaseTemplate], **kwargs) -> Optional[BaseTemplate]:
Expand Down Expand Up @@ -173,7 +176,7 @@ def apply_template(self, project: Project, identifier: Union[str, BaseTemplate],
if 'kernel' in project.templates:
# support_kernels for backwards compatibility, but kernel_version should be getting most of the exposure
kwargs['kernel_version'] = kwargs['supported_kernels'] = project.templates['kernel'].version
template = self.resolve_template(identifier=identifier, allow_online=download_ok, **kwargs)
template = self.resolve_template(identifier=identifier, **kwargs)
if template is None:
raise dont_send(
InvalidTemplateException(f'Could not find a template satisfying {identifier} for {project.target}'))
Expand Down