diff --git a/pros/cli/conductor.py b/pros/cli/conductor.py index 00a0ecb5..f3837ca8 100644 --- a/pros/cli/conductor.py +++ b/pros/cli/conductor.py @@ -332,15 +332,16 @@ def info_project(project: c.Project, ls_upgrades): @conductor.command('add-depot') @click.argument('name') @click.argument('url') +@click.option('--early-access/--disable-early-access', '--early/--disable-early', '-ea/-dea', 'early_access', '--beta/--disable-beta', is_flag=True, default=False, help="Add a depot as beta. Templates on this depot will be stored in early_access_local_templates, requiring --early-access to apply them.") @default_options -def add_depot(name: str, url: str): +def add_depot(name: str, url: str, early_access: bool): """ Add a depot Visit https://pros.cs.purdue.edu/v5/cli/conductor.html to learn more """ _conductor = c.Conductor() - _conductor.add_depot(name, url) + _conductor.add_depot(name, url, early_access=early_access) ui.echo(f"Added depot {name} from {url}") diff --git a/pros/conductor/conductor.py b/pros/conductor/conductor.py index fb40d7e1..9e970480 100644 --- a/pros/conductor/conductor.py +++ b/pros/conductor/conductor.py @@ -94,13 +94,13 @@ def __init__(self, file=None): if MAINLINE_NAME not in self.depots or \ not isinstance(self.depots[MAINLINE_NAME], HttpDepot) or \ self.depots[MAINLINE_NAME].location != MAINLINE_URL: - self.depots[MAINLINE_NAME] = HttpDepot(MAINLINE_NAME, MAINLINE_URL) + self.depots[MAINLINE_NAME] = HttpDepot(MAINLINE_NAME, MAINLINE_URL, early_access=False) needs_saving = True # add early access depot as another remote depot if EARLY_ACCESS_NAME not in self.depots or \ not isinstance(self.depots[EARLY_ACCESS_NAME], HttpDepot) or \ self.depots[EARLY_ACCESS_NAME].location != EARLY_ACCESS_URL: - self.depots[EARLY_ACCESS_NAME] = HttpDepot(EARLY_ACCESS_NAME, EARLY_ACCESS_URL) + self.depots[EARLY_ACCESS_NAME] = HttpDepot(EARLY_ACCESS_NAME, EARLY_ACCESS_URL, early_access=True) needs_saving = True if self.default_target is None: self.default_target = 'v5' @@ -154,7 +154,7 @@ def fetch_template(self, depot: Depot, template: BaseTemplate, **kwargs) -> Loca local_template = LocalTemplate(orig=template, location=destination) local_template.metadata['origin'] = depot.name click.echo(f'Adding {local_template.identifier} to registry...', nl=False) - if depot.name == EARLY_ACCESS_NAME: # check for early access + if depot.config.get("early_access",False): # check for early access self.early_access_local_templates.add(local_template) else: self.local_templates.add(local_template) @@ -165,16 +165,13 @@ def fetch_template(self, depot: Depot, template: BaseTemplate, **kwargs) -> Loca return local_template def purge_template(self, template: LocalTemplate): - if template.metadata['origin'] == EARLY_ACCESS_NAME: - if template not in self.early_access_local_templates: - logger(__name__).info(f"{template.identifier} was not in the Conductor's local early access templates cache.") - else: - self.early_access_local_templates.remove(template) + if template in self.local_templates: + self.local_templates.remove(template) + elif template in self.early_access_local_templates: + self.early_access_local_templates.remove(template) else: - if template not in self.local_templates: - logger(__name__).info(f"{template.identifier} was not in the Conductor's local templates cache.") - else: - self.local_templates.remove(template) + logger(__name__).info(f'{template.identifier} was not in the Conductor\'s local templates cache.') + if os.path.abspath(template.location).startswith( os.path.abspath(os.path.join(self.directory, 'templates'))) \ @@ -210,7 +207,7 @@ def resolve_templates(self, identifier: Union[str, BaseTemplate], allow_online: if allow_online: for depot in self.depots.values(): # EarlyAccess depot will only be accessed when the --early-access flag is true - if depot.name != EARLY_ACCESS_NAME or (depot.name == EARLY_ACCESS_NAME and use_early_access): + if not depot.config.get("early_access", False) or (depot.config.get("early_access", False) and use_early_access): remote_templates = depot.get_remote_templates(force_check=force_refresh, **kwargs) online_results = list(filter(lambda t: t.satisfies(query, kernel_version=kernel_version), remote_templates)) @@ -406,8 +403,8 @@ def new_project(self, path: str, no_default_libs: bool = False, **kwargs) -> Pro logger(__name__).exception(e) return proj - def add_depot(self, name: str, url: str): - self.depots[name] = HttpDepot(name, url) + def add_depot(self, name: str, url: str, early_access: bool): + self.depots[name] = HttpDepot(name, url, early_access=early_access) self.save() def remove_depot(self, name: str): @@ -415,4 +412,4 @@ def remove_depot(self, name: str): self.save() def query_depots(self, url: bool): - return [name + ((' -- ' + depot.location) if url else '') for name, depot in self.depots.items()] + return [(' BETA -- ' if depot.config.get("early_access", False) else 'STABLE -- ') + name + ((' -- ' + depot.location) if url else '') for name, depot in self.depots.items()] diff --git a/pros/conductor/depots/http_depot.py b/pros/conductor/depots/http_depot.py index dc7e3a25..6ba2e3c6 100644 --- a/pros/conductor/depots/http_depot.py +++ b/pros/conductor/depots/http_depot.py @@ -12,10 +12,10 @@ class HttpDepot(Depot): - def __init__(self, name: str, location: str): + def __init__(self, name: str, location: str, early_access: bool = False): # Note: If update_frequency = timedelta(minutes=1) isn't included as a parameter, # the beta depot won't be saved in conductor.json correctly - super().__init__(name, location, config_schema={}, update_frequency = timedelta(minutes=1)) + super().__init__(name, location, config={"early_access": beta}, config_schema={}, update_frequency = timedelta(minutes=1)) def fetch_template(self, template: BaseTemplate, destination: str, **kwargs): import requests