Index: sodar/trunk/plotSodar.py =================================================================== --- sodar/trunk/plotSodar.py (revision 151) +++ sodar/trunk/plotSodar.py (revision 152) @@ -11,4 +11,5 @@ import os import shutil +import csv _uComponentsPlotName = 'uComponents.png' @@ -18,4 +19,5 @@ _quiverPlotName = 'quiver.png' _latestPlotNamePrefix = 'ims_sodar_latest_' +_catalogName = 'sodar-plot-catalog.csv' def plotSingle(filein, pathout): @@ -166,13 +168,34 @@ return 0 -def plotAll(source, destination, latest, force): +def createCatalog(destination, catalog): + """ + Create catalog of plots. + + createCatalog(destination, catalog) -> rc + + destination - path to plot images directory in NCCOOS format. + catalog - path to plot catalog. + rc - 0 if successful + """ + destinationWalk = findMissing.computeDestinationWalk(destination) + catalogData = [destpath.split(os.sep) + for destpath in destinationWalk] + catalogHandle = open(os.join(catalog, _catalogName), 'wb') + writer = csv.writer(catalogHandle) + writer.writerows(catalogData) + catalogHandle.close() + + return 0 + +def plotAll(source, destination, latest, catalog, force): """ Plot all sodar raw data files. - plotAll(source, destination) -> rc + plotAll(source, destination, latest, catalog, force) -> rc source - path to raw data directory in NCCOOS format. - detination - path to plot images directory in NCCOOS format. + destination - path to plot images directory in NCCOOS format. latest - path to latest plots images directory in NCCOOS format. + catalog - path to plot catalog. force - update all destination plots for which raw data sources exist. rc - 0 if successful @@ -200,8 +223,14 @@ # copyLatest(pathout, latest, _quiverPlotName) + createCatalog(destination, catalog) + return 0 def _main(): - """bin/python %prog [options] /path/to/raw/files/ /path/to/plots/ /path/to/latest/plot/""" + """bin/python %prog [options] \ + /path/to/raw/files/ \ + /path/to/plots/ \ + /path/to/latest/plot/ \ + /path/to/catalog/""" __description__ = 'Plot all sodar raw data files.' @@ -216,6 +245,6 @@ help='update all plots for which raw data exists') (values, args) = parser.parse_args() - (source, destination, latest) = tuple(args) - plotAll(source, destination, latest, values.force) + (source, destination, latest, catalog) = tuple(args) + plotAll(source, destination, latest, catalog, values.force) return 0 Index: sodar/trunk/sodar/utils/findMissing.py =================================================================== --- sodar/trunk/sodar/utils/findMissing.py (revision 143) +++ sodar/trunk/sodar/utils/findMissing.py (revision 152) @@ -7,13 +7,12 @@ import os -def findMissing(source, destination, force): +def computeSourceWalk(source): """ - Find raw sodar data files in need of processing. - - Get source filetree. - Get destination file tree. - Construct ideal destination file tree from source - Compare ideal destination file tree to destination file tree - Construct difference file tree as list of tuples (source, destination) + Compute source file tree. + + computeSourceWalk(source) -> sourceWalk + + source - path to raw data directory in NCCOOS format. + sourceWalk - list of all raw data files with full paths. """ @@ -22,5 +21,16 @@ for fullPath, subDirs, files in sourceWalk] - sourceWalk = sourceWalk[1:] + return sourceWalk[1:] + +def computeDestinationWalk(destination,force): + """ + Compute destination file tree. + + computeDestinationWalk(destination, force) -> destinationWalk + + destination - path to plot images directory in NCCOOS format. + force - update all destination plots for which raw data sources exist. + destinationWalk - sorted list of all pre-existing destination paths. + """ if force: @@ -36,7 +46,30 @@ in destinationWalk if not subDirs] - # always mark most recent destination as missing - # to keep it updated as source is updated during the day - destinationWalk = sorted(destinationWalk) + return sorted(destinationWalk) + +def findMissing(source, destination, force): + """ + Find raw sodar data files in need of processing. + + findMissing(source, destination, force) -> differenceWalk + + source - path to raw data directory in NCCOOS format. + destination - path to plot images directory in NCCOOS format. + force - update all destination plots for which raw data sources exist. + differenceWalk - sorted list of source,destination full path tuples. + + Compute source filetree. + Compute destination file tree. + Compute ideal destination file tree from source + Compare ideal destination file tree to destination file tree + Compute difference file tree as list of tuples (source, destination) + """ + + sourceWalk = computeSourceWalk(source) + + destinationWalk = computeDestinationWalk(destination, force) + # always mark most recent destination as missing + # to keep it updated as source is updated during the day + if destinationWalk: destinationWalk = destinationWalk[:-1]