From 7c95c370632f62a7fb277f5a16acb929fd7f2561 Mon Sep 17 00:00:00 2001 From: Taylor Salo Date: Fri, 26 Jan 2024 09:26:17 -0500 Subject: [PATCH] Update cubids.py --- cubids/cubids.py | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/cubids/cubids.py b/cubids/cubids.py index a824b82f..a7c03e5c 100644 --- a/cubids/cubids.py +++ b/cubids/cubids.py @@ -414,16 +414,13 @@ def apply_tsv_changes(self, summary_tsv, files_tsv, new_prefix, raise_on_error=T full_cmd = "\n".join(merge_commands + move_ops) if full_cmd: - # write full_cmd to a .sh file - # Open file for writing - fileObject = open(new_prefix + "_full_cmd.sh", "w") - fileObject.write("#!/bin/bash\n") - fileObject.write(full_cmd) - # Close the file - fileObject.close() - renames = new_prefix + "_full_cmd.sh" + # write full_cmd to a .sh file + with open(renames, "w") as fo: + fo.write("#!/bin/bash\n") + fo.write(full_cmd) + if self.use_datalad: # first check if IntendedFor renames need to be saved if not self.is_datalad_clean(): @@ -831,11 +828,10 @@ def _purge_associations(self, scans): path_prefix = str(Path(self.path).parent) - fileObject = open(path_prefix + "/" + "_full_cmd.sh", "w") - fileObject.write("#!/bin/bash\n") - fileObject.write(full_cmd) - # Close the file - fileObject.close() + with open(path_prefix + "/" + "_full_cmd.sh", "w") as fo: + fo.write("#!/bin/bash\n") + fo.write(full_cmd) + if self.scans_txt: cmt = f"Purged scans listed in {self.scans_txt} from dataset" else: