From 406643b8c2cabb3328ed5edc421702926bd99b63 Mon Sep 17 00:00:00 2001 From: Jan Kotanski Date: Tue, 16 Jul 2024 10:31:34 +0200 Subject: [PATCH] Issue 696: create the output dir if does not exist (#697) * fix support for ScanNames=False * apply pep8 * update for the fix * update for the fix * update Changelog * update config --- ChangeLog | 7 ++----- nxstools/nxsfileinfo.py | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index adac048b..d2874ad8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,11 +1,8 @@ 2024-07-15 Jan Kotanski + * create output dir is does not exists (#696) * fix ScanFileinScanNameDir name to ScanNames (#694) * fix support for ScanNames=False (#695) - * tagged as v4.11.1 - -2024-07-15 Jan Kotanski - * fix ScanFileinScanNameDir name to ScanNames (#694) - * tagged as v4.11.1 + * tagged as v4.12.0 2024-07-11 Jan Kotanski * add --online-xml-file option for nxscreate stdcomp (#687) diff --git a/nxstools/nxsfileinfo.py b/nxstools/nxsfileinfo.py index adf04523..e8e6a5f1 100644 --- a/nxstools/nxsfileinfo.py +++ b/nxstools/nxsfileinfo.py @@ -1639,6 +1639,9 @@ def show(self, root, options): metadata = self.metadata(root, options) if metadata: if options.output: + fdir, fn = os.path.split(os.path.abspath(options.output)) + if not os.path.isdir(fdir): + os.makedirs(fdir, exist_ok=True) chmod = None try: chmod = int(options.chmod, 8) @@ -3013,6 +3016,8 @@ def groupmetadata(cls, options): elif options.group and options.group[0]: if imfile: metadir, _ = os.path.split(os.path.abspath(imfile)) + if not os.path.isdir(metadir): + os.makedirs(metadir, exist_ok=True) omfile = os.path.join( metadir, "%s.scan.json" % options.group[0]) if options.writefiles: @@ -3173,6 +3178,9 @@ def show(self, options): metadata, datablocks, attachments = self.groupmetadata(options) if metadata: if options.output: + fdir, fn = os.path.split(os.path.abspath(options.output)) + if not os.path.isdir(fdir): + os.makedirs(fdir, exist_ok=True) chmod = None try: chmod = int(options.chmod, 8) @@ -3517,6 +3525,9 @@ def show(self, options): metadata = self.datablock(options) if metadata: if options.output: + fdir, fn = os.path.split(os.path.abspath(options.output)) + if not os.path.isdir(fdir): + os.makedirs(fdir, exist_ok=True) chmod = None try: chmod = int(options.chmod, 8) @@ -3687,6 +3698,9 @@ def show(self, options): metadata = self.sample(options) if metadata: if options.output: + fdir, fn = os.path.split(os.path.abspath(options.output)) + if not os.path.isdir(fdir): + os.makedirs(fdir, exist_ok=True) chmod = None try: chmod = int(options.chmod, 8) @@ -4573,6 +4587,9 @@ def show(self, root, options): metadata = self.attachment(root, options) if metadata: if options.output: + fdir, fn = os.path.split(os.path.abspath(options.output)) + if not os.path.isdir(fdir): + os.makedirs(fdir, exist_ok=True) chmod = None try: chmod = int(options.chmod, 8) @@ -4731,6 +4748,9 @@ def show(self, options): metadata = self.instrument(options) if metadata: if options.output: + fdir, fn = os.path.split(os.path.abspath(options.output)) + if not os.path.isdir(fdir): + os.makedirs(fdir, exist_ok=True) chmod = None try: chmod = int(options.chmod, 8)