Skip to content

Commit c7c0d3e

Browse files
Update method to save Fiji script parameters
The method now ignores password in a clean way, and skips some other non-essential runtime keys.
1 parent 02d84d8 commit c7c0d3e

File tree

1 file changed

+34
-10
lines changed

1 file changed

+34
-10
lines changed

src/imcflibs/imagej/misc.py

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -713,27 +713,51 @@ def save_script_parameters(destination, save_file_name="script_parameters.txt"):
713713
Directory where the script parameters file will be saved.
714714
save_file_name : str, optional
715715
Name of the script parameters file, by default "script_parameters.txt".
716+
717+
Notes
718+
----------
719+
This function records all input parameters defined in the Fiji script header
720+
(e.g. #@ String) to a text file.
721+
722+
The following parameters are excluded:
723+
- Parameters explicitly declared with `style="password"` are ignored.
724+
- Runtime keys (e.g. 'SJLOG', 'COMMAND', 'RM') are also skipped.
716725
"""
717726
# Get the ScriptModule object from globals made by Fiji
718727
module = globals().get("org.scijava.script.ScriptModule")
719728
if module is None:
720-
print("No ScriptModule found- skipping saving script parameters.")
729+
print("No ScriptModule found skipping saving script parameters.")
721730
return
722731

723-
# Retrieve the input parameters from the scijava module
724-
inputs = module.getInputs()
725732
destination = str(destination)
726733
out_path = os.path.join(destination, save_file_name)
727-
728-
# Write the parameters to output file
729-
skip_keys = ["PASSWORD", "USERNAME", "SJLOG", "COMMAND", "RM"]
734+
735+
# Access script metadata and parameter map
736+
script_info = module.getInfo()
737+
inputs = module.getInputs()
738+
739+
# Keys to skip explicitly (case-insensitive match)
740+
skip_keys = ["USERNAME", "SJLOG", "COMMAND", "RM"]
741+
730742
with open(out_path, "w") as f:
731-
for key in inputs.keySet():
732-
if any(s in key.upper() for s in skip_keys):
743+
for item in script_info.inputs():
744+
key = item.getName()
745+
746+
# Skip if any keys are in the skip list
747+
if any(skip in key.upper() for skip in skip_keys):
733748
continue
734-
val = inputs.get(key)
735-
f.write("%s: %s\n" % (key, str(val)))
749+
750+
# Skip if parameter is declared with style="password"
751+
style = item.getWidgetStyle()
752+
if style is not None and style.lower() == "password":
753+
continue
754+
755+
# Write all other parameters
756+
if inputs.containsKey(key):
757+
val = inputs.get(key)
758+
f.write("%s: %s\n" % (key, str(val)))
736759

737760
print("Saved script parameters to: %s" % out_path)
738761

739762

763+

0 commit comments

Comments
 (0)