Skip to content

Commit 9ab6f60

Browse files
committed
merge: Easier debugging for filehandlers
2 parents a89fd0a + ba3d174 commit 9ab6f60

File tree

3 files changed

+16
-15
lines changed

3 files changed

+16
-15
lines changed

capellambse/filehandler/__init__.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,14 @@ def split_protocol(uri: str | os.PathLike) -> tuple[str, str | os.PathLike]:
4242
if isinstance(uri, str) and _looks_like_scp(uri):
4343
return "git", uri
4444

45+
uri = os.fspath(uri)
4546
pattern = r"^(\w+)([+:])"
46-
prefix_match = re.search(pattern, str(uri))
47+
prefix_match = re.search(pattern, uri)
4748

4849
if prefix_match:
4950
handler_name = prefix_match.group(1)
5051
if prefix_match.group(2) == "+":
51-
uri = os.fspath(uri)[len(prefix_match.group(0)) :]
52+
uri = uri[len(prefix_match.group(0)) :]
5253
else:
5354
handler_name = "file"
5455
return (handler_name, uri)

capellambse/filehandler/git.py

+5-9
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,6 @@ def __init_worktree(self) -> None:
748748
"--no-checkout",
749749
worktree,
750750
self.__hash,
751-
silent=True,
752751
)
753752
except:
754753
os.rmdir(worktree)
@@ -847,18 +846,15 @@ def _git(
847846
stderr = err.stderr
848847
raise
849848
finally:
850-
if silent:
851-
err_level = ret_level = logging.DEBUG
852-
elif returncode != 0:
853-
err_level = ret_level = logging.ERROR
849+
if returncode != 0 and not silent:
850+
level = logging.ERROR
854851
else:
855-
err_level = logging.INFO
856-
ret_level = logging.DEBUG
852+
level = logging.DEBUG
857853

858854
if stderr:
859855
if isinstance(stderr, bytes):
860856
stderr = stderr.decode("utf-8")
861857

862858
for line in stderr.splitlines():
863-
LOGGER.getChild("git").log(err_level, "%s", line)
864-
LOGGER.log(ret_level, "Exit status: %d", returncode)
859+
LOGGER.getChild("git").log(level, "%s", line)
860+
LOGGER.log(level, "Exit status: %d", returncode)

capellambse/repl.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ def __exit__(self, *_):
9999

100100
def _load_model_info(datapath: str | importlib.abc.Traversable) -> _ModelInfo:
101101
if isinstance(datapath, str):
102+
try:
103+
return json.loads(datapath)
104+
except json.JSONDecodeError:
105+
pass
102106
datapath = imr.files(capellambse) / "known_models" / f"{datapath}.json"
103107
with datapath.open("r", encoding="utf-8") as file:
104108
return json.load(file)
@@ -113,12 +117,12 @@ def _parse_args(args: list[str] | None = None) -> dict[str, t.Any]:
113117
parser = argparse.ArgumentParser("capellambse/repl.py")
114118
parser.add_argument(
115119
"model",
116-
default="5.0",
120+
default="test-5.0",
117121
nargs=1,
118122
help=(
119-
"A model name from repl_models, an AIRD file, or a JSON file"
120-
" describing the model. The following repl_models are known: "
121-
+ ", ".join(f"``{i}``" for i in known_models)
123+
"A model name from known_models, an AIRD file, or the path to or"
124+
" contents of a JSON file describing the model. The following"
125+
" models are known: " + ", ".join(f"``{i}``" for i in known_models)
122126
),
123127
)
124128
parser.add_argument(

0 commit comments

Comments
 (0)