Skip to content

Commit

Permalink
Merge pull request #118 from odtp-org/bug-fixes-0.2.7
Browse files Browse the repository at this point in the history
Bug fixes 0.2.7
  • Loading branch information
sabinem authored May 8, 2024
2 parents bb7dc30 + a6caa4a commit 20145bb
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 39 deletions.
2 changes: 1 addition & 1 deletion odtp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
#filemode='w',
format='%(levelname)s (%(asctime)s): %(message)s (LineL %(lineno)d [%(filename)s])',
datefmt='%d/%m/%Y %I:%M:%S %p',
level=logging.DEBUG)
level=logging.INFO)
# logging.info('The answer is: %s', x) #Variable.
18 changes: 10 additions & 8 deletions odtp/dashboard/pages/page_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ def ui_version_add():
if not current_component:
ui.label("First select the component by choosing the Component Details Tab.")
return
ui.label(current_component.get("name")).classes("text-lg font-medium")
ui_form_version_add(current_component)
ui_component_show()

Expand All @@ -137,7 +138,7 @@ def ui_form_version_add(current_component):
if not version_selector:
ui.markdown(
"""
All available versions on guthub have been already submitted to ODTP.
All available versions on github have been already submitted to ODTP.
"""
).classes("text-lg")
return
Expand Down Expand Up @@ -177,9 +178,11 @@ def ui_form_component_add_step1():
label="Enter Repository URL",
placeholder="repo url",
validation={
"Please provide a component repo url": lambda value: validators.validate_required_input(value),
"""This is not a github repo url
or has not tagged versions
or the component already exists""": lambda value: validators.validate_is_github_repo(value),
},
).classes("w-2/3")
).without_auto_validation().classes("w-2/3")
ui.button(
"Proceed to next step",
on_click=lambda: store_new_component(
Expand Down Expand Up @@ -356,6 +359,8 @@ def ui_workarea():


def store_selected_component(value):
if not ui_theme.new_value_selected_in_ui_select(value):
return
try:
storage.storage_update_component(component_id=value)
except Exception as e:
Expand All @@ -374,12 +379,9 @@ def cancel_component_entry():


def store_new_component(repo_link_input):
if not repo_link_input.validate():
return
repo_link = repo_link_input.value
try:
validators.validate_github_url(repo_link)
except Exception as e:
logging.error(f"new component {repo_link_input.value} could not be stored: an error {e} occurred")
return
try:
latest_commit = odtp_git.check_commit_for_repo(repo_link)
repo_info = odtp_git.get_github_repo_info(repo_link)
Expand Down
9 changes: 5 additions & 4 deletions odtp/dashboard/pages/page_digital_twins.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def ui_digital_twin_select(current_user) -> None:
digital_twin_options,
value=value,
label="digital twins",
on_change=lambda e: store_selected_digital_twin_id(digital_twin_id=str(e.value)),
on_change=lambda e: store_selected_digital_twin_id(str(e.value)),
with_input=True,
).props("size=80")
except Exception as e:
Expand Down Expand Up @@ -183,9 +183,10 @@ def ui_workarea(current_user, user_workdir):
)


def store_selected_digital_twin_id(digital_twin_id):
if not digital_twin_id or digital_twin_id == "":
return
def store_selected_digital_twin_id(value):
if not ui_theme.new_value_selected_in_ui_select(value):
return
digital_twin_id = value
try:
digital_twin = db.get_document_by_id(
document_id=digital_twin_id, collection=db.collection_digital_twins
Expand Down
44 changes: 28 additions & 16 deletions odtp/dashboard/pages/page_executions.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,11 +487,11 @@ def store_new_execution_workflow(current_execution_to_add, workflow):

def cancel_execution_entry():
storage.reset_storage_delete([storage.NEW_EXECUTION])
ui.notify("The execution entry was canceled")
ui_add_execution.refresh()


def execution_form_step_back(current_execution_to_add):
next_stepper = None
current_stepper = current_execution_to_add["stepper"]
current_stepper_index = STEPPERS.index(current_stepper)
next_stepper_index = current_stepper_index - 1
Expand Down Expand Up @@ -538,20 +538,29 @@ def add_parameters_configuration_to_workflow(


async def pick_parameter_file(step_index, user_workdir, current_execution_to_add, step_count) -> None:
root = user_workdir
result = await local_file_picker(root, multiple=False)
if result:
file_path = result[0]
parameters = dict(odtp_parse.parse_parameters_for_one_file(file_path))
if len(parameters) > current_execution_to_add["parameter_count"]:
current_execution_to_add["parameter_count"] = len(parameters)
if current_execution_to_add.get("parameters"):
current_execution_to_add["parameters"][step_index] = parameters
else:
current_execution_to_add["parameters"] = [{} for i in range(step_count)]
current_execution_to_add["parameters"][step_index] = parameters
app.storage.user[storage.NEW_EXECUTION] = json.dumps(current_execution_to_add)
ui_add_execution.refresh()
try:
root = user_workdir
result = await local_file_picker(root, multiple=False)
if not result:
ui.notify("No new parameter file was selected.", type="negative")
return
if result:
file_path = result[0]
parameters = dict(odtp_parse.parse_parameters_for_one_file(file_path))
if len(parameters) > current_execution_to_add["parameter_count"]:
current_execution_to_add["parameter_count"] = len(parameters)
if current_execution_to_add.get("parameters"):
current_execution_to_add["parameters"][step_index] = parameters
else:
current_execution_to_add["parameters"] = [{} for i in range(step_count)]
current_execution_to_add["parameters"][step_index] = parameters
app.storage.user[storage.NEW_EXECUTION] = json.dumps(current_execution_to_add)
except odtp_parse.OdtpParameterParsingException:
ui.notify(f"Selected file {file_path} could not be parsed. Is it a parameter file?", type="negative")
except Exception as e:
logging.error("An exception {e} occurred when picking a parameter file.")
else:
ui_add_execution.refresh()


def save_new_execution(current_execution_to_add):
Expand Down Expand Up @@ -717,14 +726,16 @@ def ui_workarea(current_digital_twin, current_user, user_workdir):


def store_selected_execution(value):
if not ui_theme.new_value_selected_in_ui_select(value):
return
try:
storage.store_execution_selection(
storage.CURRENT_EXECUTION,
execution_id = value
)
except Exception as e:
logging.error(
f"Selected execution could not be stored. An Exception occured: {e}"
f"Selected execution could not be stored. An Exception occurred: {e}"
)
else:
ui_execution_details.refresh()
Expand All @@ -742,5 +753,6 @@ def view_component_details(version_id):

def cancel_execution_selection():
storage.reset_storage_delete([storage.CURRENT_EXECUTION])
ui.notify("The execution selection was canceled")
ui_execution_details.refresh()
ui_execution_select.refresh()
12 changes: 6 additions & 6 deletions odtp/dashboard/pages/page_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ def content() -> None:
"bordered width=500"
) as right_drawer:
ui_workarea()

with ui.tabs().classes("w-full") as tabs:
select = ui.tab("Select User")
add = ui.tab("Add User")
Expand Down Expand Up @@ -57,7 +56,7 @@ def ui_users_select() -> None:
).props("size=80")
except Exception as e:
logging.error(
f"User selection could not be loaded. An Exception occured: {e}"
f"User selection could not be loaded. An Exception occurred: {e}"
)


Expand Down Expand Up @@ -149,13 +148,14 @@ def ui_workarea():
).props('flat')
except Exception as e:
logging.error(
f"Workarea could not be retrieved. An Exception occured: {e}"
f"Workarea could not be retrieved. An Exception occurred: {e}"
)


def store_selected_user(user_id):
if user_id == "":
return
def store_selected_user(value):
if not ui_theme.new_value_selected_in_ui_select(value):
return
user_id = value
try:
user = db.get_document_by_id(
document_id=user_id, collection=db.collection_users
Expand Down
8 changes: 8 additions & 0 deletions odtp/dashboard/utils/ui_theme.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,11 @@ def ui_execution_display(
for key, value in parameters[k].items():
rows.append({'key': key, 'value': value},)
ui.table(columns=table_columns, rows=rows, row_key='key', title=version_tag)


def new_value_selected_in_ui_select(value):
if not value:
return False
if value in ["", "None"]:
return False
return True
11 changes: 7 additions & 4 deletions odtp/dashboard/utils/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,20 @@ def validate_integer_input_below_threshold(value, lower_bound, upper_bound):
return True


def validate_github_url(value):
def validate_is_github_repo(value):
try:
repo_info = otdp_git.get_github_repo_info(value)
if not repo_info:
return False
if not repo_info.get("tagged_versions"):
raise otdp_git.OdtpGithubException(f"Repo {value} has no version tags")
return False
repo_url = repo_info.get("html_url")
component = db.get_document_id_by_field_value("repoLink", repo_url, db.collection_components)
if component:
raise otdp_git.OdtpGithubException(f"Component with {value} already exists")
return False
except Exception as e:
raise otdp_git.OdtpGithubException(e)
return False
return True


def validate_ports_mapping_input(value):
Expand Down
2 changes: 2 additions & 0 deletions odtp/helpers/git.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import logging
from urllib.parse import urlparse

import requests
Expand All @@ -25,6 +26,7 @@ def get_github_repo_url(repo_url):


def make_github_api_call(url):
logging.info(f"make github api call: {url}")
headers = {"Authorization": "token " + GITHUB_TOKEN}
response = requests.get(url, headers=headers)
return response
Expand Down

0 comments on commit 20145bb

Please sign in to comment.