Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions processinghistory/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
METADATA_BY_KEY = "metadataByKey"
PARENTS_BY_KEY = "parentsByKey"
AUTOENVVARSLIST_NAME = "HISTORY_ENVVARS_TO_AUTOINCLUDE"
NO_TIMESTAMP = "UnknownTimestamp"

# These GDAL drivers are known to have limits on the size of metadata which
# can be stored, and so we need to keep below these, or we lose everything.
Expand Down Expand Up @@ -248,20 +249,23 @@ def makeProcessingHistory(userDict, parents):
for parentfile in parents:
parentHist = readHistoryFromFile(filename=parentfile)

key = (os.path.basename(parentfile),
parentHist.metadataByKey[CURRENTFILE_KEY]['timestamp'])
if parentHist is not None:
key = (os.path.basename(parentfile),
parentHist.metadataByKey[CURRENTFILE_KEY]['timestamp'])

# Convert parent's "currentfile" metadata and parentage to normal key entries
procHist.metadataByKey[key] = parentHist.metadataByKey[CURRENTFILE_KEY]
procHist.parentsByKey[key] = parentHist.parentsByKey[CURRENTFILE_KEY]
# Convert parent's "currentfile" metadata and parentage to normal key entries
procHist.metadataByKey[key] = parentHist.metadataByKey[CURRENTFILE_KEY]
procHist.parentsByKey[key] = parentHist.parentsByKey[CURRENTFILE_KEY]

# Remove those from parentHist
parentHist.metadataByKey.pop(CURRENTFILE_KEY)
parentHist.parentsByKey.pop(CURRENTFILE_KEY)
# Remove those from parentHist
parentHist.metadataByKey.pop(CURRENTFILE_KEY)
parentHist.parentsByKey.pop(CURRENTFILE_KEY)

# Copy over all the other ancestor metadata and parentage
procHist.metadataByKey.update(parentHist.metadataByKey)
procHist.parentsByKey.update(parentHist.parentsByKey)
# Copy over all the other ancestor metadata and parentage
procHist.metadataByKey.update(parentHist.metadataByKey)
procHist.parentsByKey.update(parentHist.parentsByKey)
else:
key = (os.path.basename(parentfile), NO_TIMESTAMP)

# Add this parent as parent of current file
procHist.parentsByKey[CURRENTFILE_KEY].append(key)
Expand Down
23 changes: 23 additions & 0 deletions processinghistory/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,29 @@ def test_ancestry(self):

self.deleteTempFiles(filelist)

def test_parentNoHistory(self):
"""
The case of a parent which has no history
"""
childFile = 'child.kea'
parentFile = 'parent.kea'
makeRaster(childFile)
makeRaster(parentFile)
userDict = {'DESCRIPTION': "A test file", 'FIELD1': "Field value"}
history.writeHistoryToFile(userDict, filename=childFile,
parents=[parentFile])
# Now read it back
procHist = history.readHistoryFromFile(filename=childFile)

self.assertNotEqual(procHist, None, msg='History is None')
parentsList = procHist.parentsByKey[history.CURRENTFILE_KEY]
self.assertEqual(len(parentsList), 1, msg='Incorrect parent count')
numMetadata = len(procHist.metadataByKey)
self.assertEqual(numMetadata, 1, msg='Incorrect metadata count')
self.assertEqual(parentsList[0][0], parentFile, msg='Incorrect parent name')

self.deleteTempFiles([parentFile, childFile])

def test_useDataset(self):
"""
Test writing and reading history using an open gdal Dataset
Expand Down
Loading