<s> """<STR_LIT>""" <EOL> import os <EOL> import codecs <EOL> import argparse <EOL> from xml . sax . saxutils import escape <EOL> from ecohydrolib . context import Context <EOL> from ecohydrolib . metadata import GenericMetadata <EOL> from ecohydrolib . metadata import AssetProvenance <EOL> PATH_SEP_IRODS = '<STR_LIT:/>' <EOL> OUTFILE_NAME = '<STR_LIT>' <EOL> def writeAVUToXMLFile ( outfile , target , attribute , value , unit = None ) : <EOL> """<STR_LIT>""" <EOL> outfile . write ( '<STR_LIT>' ) <EOL> outfile . write ( "<STR_LIT>" % ( escape ( target ) , ) ) <EOL> outfile . write ( "<STR_LIT>" % ( escape ( attribute ) , ) ) <EOL> outfile . write ( "<STR_LIT>" % ( escape ( value ) , ) ) <EOL> if unit : <EOL> outfile . write ( "<STR_LIT>" % ( unit , ) ) <EOL> else : <EOL> outfile . write ( '<STR_LIT>' ) <EOL> outfile . write ( '<STR_LIT>' ) <EOL> def writeDictToXMLFile ( outfile , target , dict ) : <EOL> """<STR_LIT>""" <EOL> targetStr = "<STR_LIT>" % ( escape ( target ) , ) <EOL> for key in dict . keys ( ) : <EOL> outfile . write ( '<STR_LIT>' ) <EOL> outfile . write ( targetStr ) <EOL> outfile . write ( "<STR_LIT>" % ( escape ( key ) , ) ) <EOL> outfile . write ( "<STR_LIT>" % ( escape ( dict [ key ] ) , ) ) <EOL> outfile . write ( '<STR_LIT>' ) <EOL> outfile . write ( '<STR_LIT>' ) <EOL> parser = argparse . ArgumentParser ( description = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , dest = '<STR_LIT>' , required = True , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT:-c>' , '<STR_LIT>' , dest = '<STR_LIT>' , required = True , <EOL> help = '<STR_LIT>' ) <EOL> args = parser . parse_args ( ) <EOL> context = Context ( args . projectDir , None ) <EOL> collection = args . collection . rstrip ( PATH_SEP_IRODS ) <EOL> outfilePath = os . path . join ( context . projectDir , OUTFILE_NAME ) <EOL> outfile = codecs . getwriter ( '<STR_LIT:utf-8>' ) ( open ( outfilePath , '<STR_LIT:w>' ) ) <EOL> outfile . write ( '<STR_LIT>' ) <EOL> outfile . write ( '<STR_LIT>' ) <EOL> writeDictToXMLFile ( outfile , collection , GenericMetadata . readStudyAreaEntries ( context ) ) <EOL> history = GenericMetadata . getProcessingHistoryList ( context ) <EOL> i = <NUM_LIT:1> <EOL> for entry in history : <EOL> attribute = "<STR_LIT>" % ( i , ) ; i += <NUM_LIT:1> <EOL> writeAVUToXMLFile ( outfile , collection , attribute , entry ) <EOL> provenance = GenericMetadata . readAssetProvenanceObjects ( context ) <EOL> for entry in provenance : <EOL> target = collection + PATH_SEP_IRODS + entry . dcIdentifier <EOL> writeAVUToXMLFile ( outfile , target , '<STR_LIT:name>' , entry . name ) <EOL> writeAVUToXMLFile ( outfile , target , '<STR_LIT>' , entry . dcSource ) <EOL> writeAVUToXMLFile ( outfile , target , '<STR_LIT>' , entry . dcTitle ) <EOL> writeAVUToXMLFile ( outfile , target , '<STR_LIT>' , entry . dcDate . strftime ( AssetProvenance . FMT_DATE ) ) <EOL> writeAVUToXMLFile ( outfile , target , '<STR_LIT>' , entry . dcPublisher ) <EOL> writeAVUToXMLFile ( outfile , target , '<STR_LIT>' , entry . dcDescription ) <EOL> stations = GenericMetadata . readClimatePointStations ( context ) <EOL> for station in stations : <EOL> target = collection + PATH_SEP_IRODS + station . data <EOL> writeAVUToXMLFile ( outfile , target , '<STR_LIT:id>' , station . id ) <EOL> writeAVUToXMLFile ( outfile , target , '<STR_LIT:name>' , station . name ) <EOL> writeAVUToXMLFile ( outfile , target , '<STR_LIT>' , str ( station . longitude ) , '<STR_LIT>' ) <EOL> writeAVUToXMLFile ( outfile , target , '<STR_LIT>' , str ( station . latitude ) , '<STR_LIT>' ) <EOL> writeAVUToXMLFile ( outfile , target , '<STR_LIT>' , str ( station . elevation ) , '<STR_LIT>' ) <EOL> outfile . write ( '<STR_LIT>' ) <EOL> outfile . close ( ) </s>
