Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NL-BIOMERO
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete link/file

2 changes: 2 additions & 0 deletions omero-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ CONTAINER_NAME="nl-biomero-omeroweb-1"
# Command to execute inside the container
# COMMAND1="/usr/local/bin/entrypoint.sh"
COMMAND0="chmod a+w /opt/omero/web/OMERO.web/var/static"
COMMAND0B="git config --global --add safe.directory /opt/omero/web/OMERO.biomero"

COMMAND1="/opt/omero/web/venv3/bin/python -m pip install -e /opt/omero/web/OMERO.biomero"
COMMAND2="/opt/omero/web/venv3/bin/omero-biomero-setup"
Expand All @@ -15,6 +16,7 @@ COMMAND3="/opt/omero/web/venv3/bin/omero web stop || true; rm -f /opt/omero/web/
COMMAND4="/opt/omero/web/OMERO.biomero/startup.sh"

docker exec --user root "$CONTAINER_NAME" sh -c "$COMMAND0"
docker exec --user root "$CONTAINER_NAME" sh -c "$COMMAND0B"
docker exec --user root "$CONTAINER_NAME" sh -c "$COMMAND1"
docker exec --user root "$CONTAINER_NAME" sh -c "$COMMAND2"
docker exec --user omero-web "$CONTAINER_NAME" sh -c "$COMMAND3"
Expand Down
3 changes: 2 additions & 1 deletion omero-update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ CONTAINER_NAME="nl-biomero-omeroweb-1"
COMMAND0="chmod a+w /opt/omero/web/OMERO.web/var/static"
COMMAND1="/opt/omero/web/venv3/bin/pip install -e /opt/omero/web/OMERO.biomero"
COMMAND2="/opt/omero/web/venv3/bin/omero-biomero-setup"
COMMAND3="/opt/omero/web/venv3/bin/omero web stop"
COMMAND3="/opt/omero/web/venv3/bin/omero web stop || true; rm -f /opt/omero/web/OMERO.web/var/django.pid"

COMMAND4="/opt/omero/web/OMERO.biomero/startup.sh"

docker exec --user root "$CONTAINER_NAME" sh -c "$COMMAND2"
Expand Down
91 changes: 87 additions & 4 deletions omero_biomero/admin_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
import json
import logging
import os
import logging
import os

from biomero import SlurmClient
from collections import defaultdict
from configupdater import ConfigUpdater, Comment
from django.http import JsonResponse, HttpResponseBadRequest
from django.views.decorators.http import require_http_methods
from omeroweb.webclient.decorators import login_required
from .settings import CONFIG_FILE_PATH

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -44,6 +47,21 @@ def admin_config(request, conn=None, **kwargs):
section: dict(configs.items(section)) for section in configs.sections()
}

# Load the JSON configuration file (biomero-config.json)
json_config = {}
if os.path.exists(CONFIG_FILE_PATH):
try:
with open(CONFIG_FILE_PATH, "r") as f:
json_config = json.load(f)
except Exception as e:
logger.error(f"Error reading JSON config: {str(e)}")

# Merge JSON config into config_dict
# Note: JSON config allows nested dicts, while INI is flat (section -> key/value)
# We assume top-level keys in JSON correspond to sections or specific config groups
for key, value in json_config.items():
config_dict[key] = value

return JsonResponse({"config": config_dict})
except Exception as e:
logger.error(f"Error retrieving BIOMERO config: {str(e)}")
Expand Down Expand Up @@ -86,8 +104,58 @@ def generate_model_comment(key):
c = "# Adding or overriding job value for this workflow"
return c

# Update the config with new values
# Separate settings for JSON config and INI config
json_config_updates = {}
ini_config_updates = {}

# Define sections that belong in the JSON configuration
JSON_SECTIONS = [
"UPLOADER",
"PREPROCESSING_CONFIG",
"PREPROCESSING_EXTENSION_MAP",
"FILE_OR_EXTENSION_PATTERNS_EXCLUSIVE",
"UPLOADER_NESTED_FILE_EXTENSIONS",
"group_mappings",
]

for section, settingsd in config_data.items():
if section in JSON_SECTIONS:
json_config_updates[section] = settingsd
else:
ini_config_updates[section] = settingsd

# --- Save JSON Config ---
if json_config_updates:
try:
current_json_config = {}
if os.path.exists(CONFIG_FILE_PATH):
with open(CONFIG_FILE_PATH, "r") as f:
current_json_config = json.load(f) or {}

# Update with new values
for key, value in json_config_updates.items():
current_json_config[key] = value

# Ensure directory exists
config_dir = os.path.dirname(CONFIG_FILE_PATH)
if config_dir and not os.path.exists(config_dir):
os.makedirs(config_dir, exist_ok=True)

with open(CONFIG_FILE_PATH, "w") as f:
json.dump(current_json_config, f, indent=2)
logger.info(f"JSON configuration saved to {CONFIG_FILE_PATH}")
except Exception as e:
logger.error(f"Failed to save JSON config: {str(e)}")
# We might want to return an error here, but let's see if INI save works first?
# Or fail immediately? Let's fail if we can't save the requested changes.
return JsonResponse(
{"error": f"Failed to save JSON configuration: {str(e)}"},
status=500,
)

# --- Save INI Config ---
# Update the config with new values
for section, settingsd in ini_config_updates.items():
if not isinstance(settingsd, dict):
raise ValueError(
f"Section '{section}' must contain key-value pairs."
Expand Down Expand Up @@ -196,10 +264,25 @@ def generate_model_comment(key):
changelog_section.add_after.comment(change_comment)

# Save the updated configuration while preserving comments
with open(config_path, "w") as config_file:
config.write(config_file)
try:
with open(config_path, "w") as config_file:
config.write(config_file)
logger.info(f"Configuration saved successfully to {config_path}")
except PermissionError:
logger.error(
f"Permission denied writing to {config_path}. Skipping INI save."
)
if not json_config_updates:
# If we only tried to save INI and failed, that's an error.
# If we saved JSON but failed INI, we might want to warn or just succeed partially.
# For now, if we have mix, and INI fails, we report error?
# But the user might be toggling UPLOADER (JSON) and not caring about Slurm (INI).
# So if json_config_updates succeeded, we can treat it as partial success.
pass
except Exception as e:
logger.error(f"Error saving INI config: {e}")
raise e

logger.info(f"Configuration saved successfully to {config_path}")
return JsonResponse(
{"message": "Configuration saved successfully", "path": config_path},
status=200,
Expand Down
2 changes: 2 additions & 0 deletions omero_biomero/biomero_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
)
from .settings import (
BASE_DIR,
UPLOADER_ALLOWED_FILE_EXTENSIONS,
)

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -87,5 +88,6 @@ def biomero(request, conn=None, **kwargs):
"app_name": "biomero",
"importer_enabled": importer_enabled,
"analyzer_enabled": analyzer_enabled,
"uploader_allowed_file_extensions": UPLOADER_ALLOWED_FILE_EXTENSIONS,
}
return context
Loading
Loading