Skip to content

Commit

Permalink
Issue 722: improve datasetName values generation in the ScanNames mode (
Browse files Browse the repository at this point in the history
#723)

* improve datasetName values generation in the ScanNames mode

* fix typo
  • Loading branch information
jkotan authored Oct 22, 2024
1 parent 8653637 commit e4e76ea
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
2024-10-22 Jan Kotanski <jankotan@gmail.com>
* improve datasetName values generation in the ScanNames mode (#723)
* tagged as v4.16.2

2024-09-27 Jan Kotanski <jankotan@gmail.com>
* fix for metadata parser of groups without NX_class (#718)
* fix minimal_value and maximal_value to minimum_value and maximum_value NXlog attributes (#718)
Expand Down
12 changes: 11 additions & 1 deletion nxstools/nxsfileinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,7 @@ def update_pid(self, metadata, filename=None, puuid=False, pfname=False,
:rtype: :obj:`dict` <:obj:`str`, `any`>
"""
metadata = metadata or {}
genuid = False
if "pid" not in metadata:
beamtimeid = beamtimeid or ""
if not beamtimeid and "scientificMetadata" in metadata \
Expand Down Expand Up @@ -886,14 +887,23 @@ def update_pid(self, metadata, filename=None, puuid=False, pfname=False,
if puuid:
metadata["pid"] = "%s/%s/%s" % \
(beamtimeid, scanid, str(uuid.uuid4()))
genuid = True
else:
metadata["pid"] = "%s/%s" % \
(beamtimeid, scanid)

if "datasetName" not in metadata and "pid" in metadata:
spid = metadata["pid"].split("/")
if len(spid) > 1:
if genuid:
spid = spid[:-1]
if len(spid) == 2:
metadata["datasetName"] = spid[1]
elif len(spid) > 1:
try:
int(spid[-1])
metadata["datasetName"] = spid[-2]
except Exception:
metadata["datasetName"] = spid[-1]
else:
metadata["datasetName"] = metadata["pid"]
return metadata
Expand Down
2 changes: 1 addition & 1 deletion nxstools/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@
""" NXS tools release version"""

#: (:obj:`str`) package version
__version__ = "4.16.1"
__version__ = "4.16.2"
10 changes: 6 additions & 4 deletions test/NXSFileInfo_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3441,11 +3441,13 @@ def test_metadata_entrynames(self):
formula = arg[8]

commands = [
("nxsfileinfo metadata -k4 %s %s --pid 12341234 "
("nxsfileinfo metadata -k4 %s %s "
"--pid 99001234/mywpscan/mywpscan_01363 "
"-e logs --entry-classes \'\'"
% (filename, self.flags)).split(),
('nxsfileinfo metadata -k4 %s %s '
" -p 12341234 --entry-names logs -t \'\'"
" -p 99001234/mywpscan/mywpscan_01363 "
"--entry-names logs -t \'\'"
% (filename, self.flags)).split(),
]

Expand Down Expand Up @@ -3499,8 +3501,8 @@ def test_metadata_entrynames(self):
self.assertEqual('', er)
dct = json.loads(vl)
res = {
'pid': '12341234',
'datasetName': '12341234',
'pid': '99001234/mywpscan/mywpscan_01363',
'datasetName': 'mywpscan_01363',
"type": "raw",
"creationTime": "",
"ownerGroup": "ingestor",
Expand Down

0 comments on commit e4e76ea

Please sign in to comment.