Skip to content

Commit 4aff1d9

Browse files
committed
Fixed a bug and added an alias for units values.
1 parent 5ec7fe2 commit 4aff1d9

File tree

2 files changed

+31
-24
lines changed

2 files changed

+31
-24
lines changed

ncldDump/aliases.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,10 @@
138138
"SDN_ParameterDiscoveryCode" :
139139
{
140140
"BactTaxaAbundSed" : "http://vocab.nerc.ac.uk/collection/P02/current/BAUC/"
141+
},
142+
"units" :
143+
{
144+
"*" : "https://ncics.org/portfolio/other-resources/udunits2/#{}"
141145
}
142146
}
143147
}

ncldDump/ncldDump.py

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -285,32 +285,35 @@ def resolveValue(name, value, aliasDict):
285285
#
286286
result = None
287287

288-
# Attempt to split the value on '__'.
288+
# If the value is a string, attempt to resolve it.
289289
#
290-
valueParts = value.split('__')
291-
292-
# If there is a context part, resolve the value as a name.
293-
#
294-
if 2 == len(valueParts):
295-
result = resolveName(value, aliasDict)
296-
297-
# If the name exists in the alias dictionary, and if the value exists in
298-
# the sub-dictionary for the name, create a URL using the pattern for the
299-
# value. A wildcard (*) for a value key in the dictionary matches any
300-
# value.
301-
#
302-
elif name in aliasDict['values']:
303-
subDict = aliasDict['values'][name]
304-
305-
pattern = None
290+
if True == isinstance(value, str) or True == isinstance(value, unicode):
291+
# Attempt to split the value on '__'.
292+
#
293+
valueParts = value.split('__')
306294

307-
if value in subDict:
308-
pattern = subDict[value]
309-
elif '*' in subDict:
310-
pattern = subDict['*']
295+
# If there is a context part, resolve the value as a name.
296+
#
297+
if 2 == len(valueParts):
298+
result = resolveName(value, aliasDict)
311299

312-
if pattern is not None:
313-
result = makeURL(value, pattern)
300+
# If the name exists in the alias dictionary, and if the value exists
301+
# in the sub-dictionary for the name, create a URL using the pattern
302+
# for the value. A wildcard (*) for a value key in the dictionary
303+
# matches any value.
304+
#
305+
elif name in aliasDict['values']:
306+
subDict = aliasDict['values'][name]
307+
308+
pattern = None
309+
310+
if value in subDict:
311+
pattern = subDict[value]
312+
elif '*' in subDict:
313+
pattern = subDict['*']
314+
315+
if pattern is not None:
316+
result = makeURL(value, pattern)
314317

315318
# Return the resolved name if one was found.
316319
#
@@ -507,7 +510,7 @@ def ncldDump(inputFile, aliasFile, outputFile):
507510

508511
# Add a filePath entry.
509512
#
510-
ncDict['filePath'] = inputFile
513+
ncDict['filePath'] = os.path.split(inputFile)[-1]
511514

512515
# Create a jinja environment and template object.
513516
#

0 commit comments

Comments
 (0)