forked from toolshed/alakazam
fix(fetch recipes): use abra recipe lint instead of fetch
This commit is contained in:
+10
-3
@@ -414,7 +414,7 @@ def is_connection_error(output: str) -> bool:
|
||||
return any(error in output.lower() for error in CONNECTION_ERRORS)
|
||||
|
||||
|
||||
def abra(*args: str, machine_output: bool = False, ignore_error: bool = False) -> Union[str,Dict]:
|
||||
def abra(*args: str, machine_output: bool = False, ignore_error: bool = False, offline: bool = True) -> Union[str,Dict]:
|
||||
"""
|
||||
Execute the 'abra' command with the specified arguments. This function acts as a wrapper around the 'abra' CLI tool. It allows for capturing the output and optionally returning it as machine-readable JSON.
|
||||
|
||||
@@ -422,6 +422,7 @@ def abra(*args: str, machine_output: bool = False, ignore_error: bool = False) -
|
||||
*args: Variable length argument list representing the 'abra' command and its parameters.
|
||||
machine_output (bool): If True, expects the output in JSON format and parses it before returning.
|
||||
ignore_error (bool): If True, suppresses the raising of errors on non-zero return codes, otherwise an exception is raised.
|
||||
offline (bool): If True, abra runs with -o and never touches the recipe git repos, this is the default for every call but the recipe refresh.
|
||||
|
||||
Returns:
|
||||
str or dict: Returns the output from the 'abra' command. If machine_output is True, returns a dictionary, otherwise returns raw output as a string.
|
||||
@@ -429,7 +430,7 @@ def abra(*args: str, machine_output: bool = False, ignore_error: bool = False) -
|
||||
Raises:
|
||||
RuntimeError: If the 'abra' command exits with a non-zero return code and ignore_error is False, including the command output in the error.
|
||||
"""
|
||||
command = ["abra", "-o", *args]
|
||||
command = ["abra", "-o" if offline else "", *args]
|
||||
#remove empty elements
|
||||
command = [arg for arg in command if arg]
|
||||
if machine_output:
|
||||
@@ -466,6 +467,9 @@ def fetch_recipes(instance_configs: Dict[str, Dict[str, Any]]) -> None:
|
||||
Since every abra call runs with -o, the recipe git repos are never pulled
|
||||
implicitly. The mtime of `<recipe>/.git/FETCH_HEAD` is used as the marker.
|
||||
|
||||
`abra recipe fetch` only clones a missing recipe, so an online `abra recipe
|
||||
lint` is used instead: it pulls both the recipe repo and the recipe catalogue.
|
||||
|
||||
Args:
|
||||
instance_configs (dict): Merged instance configurations
|
||||
"""
|
||||
@@ -476,7 +480,10 @@ def fetch_recipes(instance_configs: Dict[str, Dict[str, Any]]) -> None:
|
||||
logging.debug(f"recipe {recipe} was fetched less than {FETCH_MAX_AGE}s ago, skip")
|
||||
continue
|
||||
logging.info(f"fetch recipe {recipe}")
|
||||
abra("recipe", "fetch", "-f", recipe, ignore_error=True)
|
||||
try:
|
||||
abra("recipe", "lint", recipe, offline=False)
|
||||
except RuntimeError as e:
|
||||
logging.debug(f"could not fetch recipe {recipe}: {e}")
|
||||
if fetch_head.parent.is_dir():
|
||||
fetch_head.touch()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user