Skip to content

Commit

Permalink
Add path shortener
Browse files Browse the repository at this point in the history
  • Loading branch information
PlethoraChutney committed Mar 10, 2024
1 parent f702929 commit 6e09c86
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/appia/parsers/user_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,16 @@ def database_password(self, password: str):
else:
raise TypeError(f"Password must be a string, not a {type(password)}")

@property
def max_path_length(self):
return self._user_settings.get("max_path_length", 0)

@max_path_length.setter
def max_path_length(self, path_length: int):
try:
self._user_settings["max_path_length"] = int(path_length)
except ValueError:
raise ValueError("Max path length must be an integer.")


appia_settings = AppiaSettings()
9 changes: 9 additions & 0 deletions src/appia/parsers/utilities_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ def main(args):
print("Password:", appia_settings.database_password)
print("Port:", appia_settings.database_port)

if args.set_max_path_length:
appia_settings.max_path_length = args.set_max_path_length
appia_settings.save_settings()


parser = argparse.ArgumentParser("Appia utilities", add_help=False)
parser.set_defaults(func=main)
Expand Down Expand Up @@ -129,3 +133,8 @@ def main(args):
help="Print login info to the terminal",
action="store_true",
)
parser.add_argument(
"--set-max-path-length",
help="Set greatest number of path steps to display. Set to 0 to show full path",
type=int,
)
22 changes: 21 additions & 1 deletion web.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,33 @@
from urllib.parse import parse_qs
from appia.processors.database import Database
from appia.processors.experiment import concat_experiments
from appia.parsers.user_settings import appia_settings

url_basename = "/traces/"
app = dash.Dash(__name__, url_base_pathname=url_basename)
server = app.server
db = Database()


def shorten_path_length(fullpath):
# can't use os.path.sep b/c processing machine may be different OS
# most likely processing machine is Windows, so check \\ second
sep = ""
if "/" in fullpath:
sep = "/"
if "\\" in fullpath:
sep = "\\"
if not sep or appia_settings.max_path_length <= 0:
return fullpath

split_path = fullpath.split(sep)
try:
split_path = split_path[-appia_settings.max_path_length :]
except IndexError:
pass
return sep.join(split_path)


def exp_list_from_pathname(pathname):
path_string = pathname.replace(url_basename, "")
return path_string.split("+")
Expand Down Expand Up @@ -307,7 +327,7 @@ def serve_layout():
dcc.Dropdown(
id="experiment_dropdown",
options=[
{"label": x, "value": x}
{"label": shorten_path_length(x), "value": x}
for x in db.update_experiment_list()
],
multi=True,
Expand Down

0 comments on commit 6e09c86

Please sign in to comment.