Skip to content

Commit 8121488

Browse files
authored
Configurable environment variables to auto-include (#4)
* Remove OpenJPEG test again, as it was not properly tested. Sigh.... * Implement configurable list of environment variables to auto-include
1 parent 1ef922f commit 8121488

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ and several entries giving the various fields of the os.uname() return value.
4444

4545
There is also an entry called `package_version_dict`, which contains a dictionary of version numbers for as many imported Python packages as it can find. So, for example, this will include the version number of numpy and osgeo (i.e. GDAL) which are imported at the time of execution.
4646

47+
If the environment variable `HISTORY_ENVVARS_TO_AUTOINCLUDE` is set, it will be taken to be a space-separated list of other environment variable names. For each of these names, if it is set, then that name/value pair will also be automatically included in the metadata dictionary.
48+
4749
## Viewer
4850
A simple viewer called ``historyview`` is provided, to display the processing history to the console. Since the whole lineage can be quite large and complex, no attempt is made to display the whole thing at once. Rather, the metadata dictionary or the list of parents can be displayed, for either the main file itself, or for a nominated ancestor file within the lineage.
4951

processinghistory/history.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
CURRENTFILE_KEY = "CURRENTFILE"
4848
METADATA_BY_KEY = "metadataByKey"
4949
PARENTS_BY_KEY = "parentsByKey"
50+
AUTOENVVARSLIST_NAME = "HISTORY_ENVVARS_TO_AUTOINCLUDE"
5051

5152
# These GDAL drivers are known to have limits on the size of metadata which
5253
# can be stored, and so we need to keep below these, or we lose everything.
@@ -142,6 +143,16 @@ def makeAutomaticFields():
142143
dictn['script_dir'] = os.path.dirname(script)
143144
dictn['commandline'] = ' '.join(sys.argv[1:])
144145

146+
# If $<AUTOENVVARSLIST_NAME> is set, it is a space-separated list of
147+
# other environment variables which should be included.
148+
autoEnvVars = os.getenv(AUTOENVVARSLIST_NAME)
149+
if autoEnvVars is not None:
150+
autoEnvVarsList = autoEnvVars.split()
151+
for envVar in autoEnvVarsList:
152+
val = os.getenv(envVar)
153+
if val is not None:
154+
dictn[envVar] = val
155+
145156
dictn['python_version'] = "{}.{}.{}".format(*sys.version_info)
146157

147158
# Find version numbers of any external imported modules (if possible)

processinghistory/tests.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ def makeRaster(filename, drvr='KEA', returnDS=False):
3434

3535

3636
# Test these drivers
37-
driverList = [('KEA', 'kea'), ('HFA', 'img'), ('GTiff', 'tif'),
38-
('JP2OpenJPEG', 'jpg')]
37+
driverList = [('KEA', 'kea'), ('HFA', 'img'), ('GTiff', 'tif')]
3938
# Remove any drivers not installed
4039
driverList = [dd for dd in driverList if gdal.GetDriverByName(dd[0]) is not None]
4140

0 commit comments

Comments
 (0)