Skip to content

Commit 8819fac

Browse files
committed
Re-add misc.save_script_parameters()
Attempt to fix the problem in a new branch, see #136 for details.
1 parent 14024ee commit 8819fac

1 file changed

Lines changed: 53 additions & 0 deletions

File tree

src/imcflibs/imagej/misc.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,3 +737,56 @@ def run_imarisconvert(file_path, pixel_calibration=None, output_folder=""):
737737
else:
738738
timed_log("Error converting [%s]: %d" % (file_path, result))
739739

740+
741+
def save_script_parameters(destination, save_file_name="script_parameters.txt"):
742+
"""Save all Fiji script parameters to a text file.
743+
744+
Parameters
745+
----------
746+
destination : str
747+
Directory where the script parameters file will be saved.
748+
save_file_name : str, optional
749+
Name of the script parameters file, by default "script_parameters.txt".
750+
751+
Notes
752+
-----
753+
This function records all input parameters defined in the Fiji script header
754+
(e.g. `#@ String`) to a text file.
755+
756+
The following parameters are excluded:
757+
- Parameters explicitly declared with `style="password"` are ignored.
758+
- Runtime keys (e.g. 'SJLOG', 'COMMAND', 'RM') are also skipped.
759+
"""
760+
# Get the ScriptModule object from globals made by Fiji
761+
module = globals().get("org.scijava.script.ScriptModule")
762+
if module is None:
763+
timed_log("No ScriptModule found - skipping saving script parameters.")
764+
return
765+
766+
destination = str(destination)
767+
out_path = os.path.join(destination, save_file_name)
768+
769+
# Access script metadata and inputs
770+
script_info = module.getInfo()
771+
inputs = module.getInputs()
772+
773+
# Keys to skip explicitly
774+
skip_keys = ["USERNAME", "SJLOG", "COMMAND", "RM"]
775+
776+
with open(out_path, "w") as f:
777+
for item in script_info.inputs():
778+
key = item.getName()
779+
780+
# Skip if any keys are in the skip list
781+
if any(skip in key.upper() for skip in skip_keys):
782+
continue
783+
784+
# Skip if parameter is declared with password style
785+
if WidgetStyle.isStyle(item, TextWidget.PASSWORD_STYLE):
786+
continue
787+
788+
if inputs.containsKey(key):
789+
val = inputs.get(key)
790+
f.write("%s: %s\n" % (key, str(val)))
791+
792+
timed_log("Saved script parameters to: %s" % out_path)

0 commit comments

Comments
 (0)