From e5130d6c1bb637b1d77cb1748c63ed4c1d2c8762 Mon Sep 17 00:00:00 2001 From: Jan Kotanski Date: Sun, 14 Jul 2024 11:53:23 +0200 Subject: [PATCH 1/6] fix support for ScanNames=False --- ChangeLog | 5 +++++ nxstools/pyeval/scdataset.py | 16 ++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4a1e4a36..adac048b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2024-07-15 Jan Kotanski + * 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 diff --git a/nxstools/pyeval/scdataset.py b/nxstools/pyeval/scdataset.py index e956680a..a2e5cbac 100644 --- a/nxstools/pyeval/scdataset.py +++ b/nxstools/pyeval/scdataset.py @@ -127,13 +127,21 @@ def append_scicat_dataset(macro, status_info=True, reingest=False): if "INIT" in skip_acq: sname = "%s:%s" % (sname, time.time()) + fdir = macro.getEnv('ScanDir') + snmode = get_env_var(macro, 'ScanNames', False) + pdir = None + if snmode is not None: + if bool(snmode): + fdir = os.path.dirname(os.path.abspath(fdir)) + elif appendentry is False: + fdir, pdir = os.path.split(os.path.abspath(fdir)) + if pdir: + sname = "%s/%s" % (pdir, sname) + # auto grouping grouping = bool(get_env_var(macro, 'SciCatAutoGrouping', False)) - if grouping: + if grouping or pdir: commands = [] - fdir = macro.getEnv('ScanDir') - if bool(get_env_var(macro, 'ScanNames', False)): - fdir = os.path.dirname(os.path.abspath(fdir)) try: sm = dict(get_env_var(macro, 'SciCatMeasurements', {})) except Exception: From c81d874e58dba40cf29d630f88c3bd35d5a7a5d6 Mon Sep 17 00:00:00 2001 From: Jan Kotanski Date: Sun, 14 Jul 2024 11:54:29 +0200 Subject: [PATCH 2/6] apply pep8 --- nxstools/pyeval/scdataset.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nxstools/pyeval/scdataset.py b/nxstools/pyeval/scdataset.py index a2e5cbac..a8ef9953 100644 --- a/nxstools/pyeval/scdataset.py +++ b/nxstools/pyeval/scdataset.py @@ -137,7 +137,7 @@ def append_scicat_dataset(macro, status_info=True, reingest=False): fdir, pdir = os.path.split(os.path.abspath(fdir)) if pdir: sname = "%s/%s" % (pdir, sname) - + # auto grouping grouping = bool(get_env_var(macro, 'SciCatAutoGrouping', False)) if grouping or pdir: From e78f64884116afea71ae4e7b320aa51f47682cd5 Mon Sep 17 00:00:00 2001 From: Jan Kotanski Date: Sun, 14 Jul 2024 11:59:45 +0200 Subject: [PATCH 3/6] update for the fix --- nxstools/pyeval/scdataset.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/nxstools/pyeval/scdataset.py b/nxstools/pyeval/scdataset.py index a8ef9953..3149b5e9 100644 --- a/nxstools/pyeval/scdataset.py +++ b/nxstools/pyeval/scdataset.py @@ -128,7 +128,7 @@ def append_scicat_dataset(macro, status_info=True, reingest=False): sname = "%s:%s" % (sname, time.time()) fdir = macro.getEnv('ScanDir') - snmode = get_env_var(macro, 'ScanNames', False) + snmode = get_env_var(macro, 'ScanNames', None) pdir = None if snmode is not None: if bool(snmode): @@ -182,7 +182,8 @@ def append_scicat_record(macro, sname, status_info=True): """ # get beamtime id fdir = macro.getEnv('ScanDir') - if bool(get_env_var(macro, 'ScanNames', False)): + snmode = + if get_env_var(macro, 'ScanNames', None): fdir = os.path.dirname(os.path.abspath(fdir)) bmtfpath = get_env_var(macro, "BeamtimeFilePath", "/gpfs/current") bmtfprefix = get_env_var( From ac95c2cd04e700deecdbf81fd2bc55bd00c4db14 Mon Sep 17 00:00:00 2001 From: Jan Kotanski Date: Sun, 14 Jul 2024 12:00:28 +0200 Subject: [PATCH 4/6] update for the fix --- nxstools/pyeval/scdataset.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/nxstools/pyeval/scdataset.py b/nxstools/pyeval/scdataset.py index 3149b5e9..1ad88fee 100644 --- a/nxstools/pyeval/scdataset.py +++ b/nxstools/pyeval/scdataset.py @@ -182,8 +182,7 @@ def append_scicat_record(macro, sname, status_info=True): """ # get beamtime id fdir = macro.getEnv('ScanDir') - snmode = - if get_env_var(macro, 'ScanNames', None): + if get_env_var(macro, 'ScanNames', None) is not None: fdir = os.path.dirname(os.path.abspath(fdir)) bmtfpath = get_env_var(macro, "BeamtimeFilePath", "/gpfs/current") bmtfprefix = get_env_var( From 182f3781df2c481fbb1f6cd12cb222fd40823551 Mon Sep 17 00:00:00 2001 From: Jan Kotanski Date: Tue, 16 Jul 2024 09:27:40 +0200 Subject: [PATCH 5/6] update Changelog --- ChangeLog | 4 ---- 1 file changed, 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index adac048b..b83dca4c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,10 +3,6 @@ * 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 - 2024-07-11 Jan Kotanski * add --online-xml-file option for nxscreate stdcomp (#687) * add support for ScanFileinScanNameDir mode for detector template (#689) From 5bc123f13fb4f3a1324717be01e7c1bd98f7a009 Mon Sep 17 00:00:00 2001 From: Jan Kotanski Date: Tue, 16 Jul 2024 09:50:26 +0200 Subject: [PATCH 6/6] update config --- ChangeLog | 3 ++- nxstools/nxsfileinfo.py | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index b83dca4c..d2874ad8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,7 +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 + * 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)