Changeset 3671
- Timestamp:
- 03/20/18 16:05:56 (7 years ago)
- Location:
- TOOLS/MOSAIX
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
TOOLS/MOSAIX/README.txt
r3666 r3671 12 12 All documentation available at https://forge.ipsl.jussieu.fr/igcmg/wiki/IPSLCM6/MOSAIX 13 13 14 Extraction : 15 > svn co http://forge.ipsl.jussieu.fr/igcmg/svn/TOOLS/MOSAIX MOSAIX 16 > svn co svn+ssh://omamce@forge.ipsl.jussieu.fr/ipsl/forge/projets/igcmg/svn/TOOLS/MOSAIX MOSAIX -
TOOLS/MOSAIX/bld.cfg
r3620 r3671 1 1 # -- 2 ## SVN information 3 # $Author: omamce $ 4 # $Date: 2018-03-12 11:17:59 +0100 (Mon, 12 Mar 2018) $ 5 # $Revision: 3625 $ 6 # $Id: CreateWeightsMask.bash 3625 2018-03-12 10:17:59Z omamce $ 7 # $HeadURL: svn+ssh://omamce@forge.ipsl.jussieu.fr/ipsl/forge/projets/igcmg/svn/TOOLS/MOSAIX/CreateWeightsMask.bash $ 8 # 2 9 3 10 cfg::type bld -
TOOLS/MOSAIX/update_xml.py
r3665 r3671 30 30 def usage () : 31 31 texte = """%(prog)s usage : 32 python %(prog)s [-d] [-i iodef.xml] [-o iodef_new.xml] -n [node in Xpath syntax]-k <key> -v <value>33 python %(prog)s [-d] [-i iodef.xml] [-o iodef_new.xml] -n [node in Xpath syntax]-t <value>32 python %(prog)s [-d] [-i iodef.xml] [-o iodef_new.xml] -n <node in Xpath syntax> -k <key> -v <value> 33 python %(prog)s [-d] [-i iodef.xml] [-o iodef_new.xml] -n <node in Xpath syntax> -t <value> 34 34 -d | --debug : debug 35 -i <file> | --input=<file> : input file (default iodef.xml)35 -i <file> | --input=<file> : input file (default: iodef.xml) 36 36 -o <file> | --output=<file> : output file (default: overwrite input file) 37 -n < file> | --node=<file> : node in Xpath syntax37 -n <node> | --node=<node> : node in Xpath syntax 38 38 -f <field> | --field=<field> : xml field to update 39 -v <value> | --value=<value> : new value for xml field 39 40 -t <text> | --text=<text> : will replace the 'text' part of the Xpath by <text> 40 -v <value> | --value=<value> : new value for xml field41 41 example : 42 python %(prog)s -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="file_src"]/field[@id="mask_source"]' -k name 42 python %(prog)s -i iodef.xml -n 'context[@id="interpol_run"]/file_definition/file[@id="file_src"]/field[@id="mask_source"]' -k name -v maskutil_T 43 43 """ 44 44 #print ( texte % ( sys.argv[0], sys.argv[0], sys.argv[0], sys.argv[0] ) ) … … 46 46 print ( texte % { 'prog':sys.argv[0] } ) 47 47 48 # Check version 49 if sys.version_info<(2,7,0): 48 # Check version of Python 49 Version = sys.version_info 50 if Version < (2,7,0) : 50 51 sys.stderr.write ( "You need python 2.7 or later to run this script\n" ) 52 sys.stderr.write ( "Present version is: " + str(Version[0]) + "." + str(Version[1]) + "." + str(Version[2]) + "\n" ) 51 53 sys.exit (1) 52 54 53 ## Input parameters55 ## Default input parameters 54 56 FileIn = 'iodef.xml' 55 57 FileOut = None … … 64 66 myopts, myargs = getopt.getopt ( sys.argv[1:], 'i:o:n:k:v:t:dh', [ 'input=', 'output=', 'node=', 'key=', 'value=', 'text=', 'debug=', '--help' ] ) 65 67 except getopt.GetoptError as cmdle : 66 print ( "Command line error : ", cmdle, "\n")68 print ( "Command line error : "+cmdle ) 67 69 usage () 68 70 sys.exit(1) … … 79 81 80 82 ## Some coherency checking of command line parameters 81 if FileOut == None : FileOut = FileIn 83 ErrorCount = 0 84 85 if FileIn == None : 86 print ( "Error : please specify input file by -i <file>" ) 87 ErrorCount += 1 82 88 83 89 if Node == None : 84 print ( "Error : please specify -n <node>", "\n" ) 85 usage () 86 sys.exit (1) 90 print ( "Error : please specify -n <node>" ) 91 ErrorCount += 1 87 92 88 93 if Key == None and Text == None : 89 print ( "Error : please specify either -t <text> or -k <key> -v <value> ", "\n" ) 94 print ( "Error : please specify either -t <text> or -k <key> -v <value>" ) 95 ErrorCount += 1 96 97 if Key != None and Text != None : 98 print ( "Error : please specify only one option between -t "+Text+" and -k "+Key ) 99 ErrorCount += 1 100 101 if Key != None and Value == None : 102 print ( "Error : please specify -v <value> when -k "+Key+" is given") 103 ErrorCount += 1 104 105 if ErrorCount > 0 : 90 106 usage () 91 107 sys.exit (1) 92 108 93 if Key != None and Text != None : 94 print ( "Error : please specify only one option between -t", Text, "and -k", Key, "\n" ) 95 usage () 96 sys.exit (1) 97 98 if Key != None and Value == None : 99 print ( "Error : please specify -v <value> when -k", Key, "is given", "\n") 100 usage () 101 sys.exit (1) 109 if FileOut == None : FileOut = FileIn 102 110 103 111 ## Get XML tree from input file … … 107 115 nodeList = iodef.findall ( Node ) 108 116 109 ## Check that on ly one node is found117 ## Check that one and only one node is found 110 118 if len(nodeList) == 0 : 111 119 print ( "Error : node not found" ) 112 print ( "Node : ",Node )113 sys.exit (1)120 print ( "Node : "+Node ) 121 sys.exit (1) 114 122 115 123 if len(nodeList) > 1 : 116 print ( "Error : ", len(nodeList), "occurences of node found" )117 print ( "Node : ",Node )118 sys.exit (1)124 print ( "Error : "+len(nodeList)+" occurences of node found" ) 125 print ( "Node : "+Node ) 126 sys.exit (1) 119 127 120 128 ## Update element … … 122 130 123 131 if Debug : 124 print ( 'Node : ',Node )125 print ( 'Key : ',Key )126 print ( 'Value : ',Value )132 print ( 'Node : '+Node ) 133 print ( 'Key : '+Key ) 134 print ( 'Value : '+Value ) 127 135 128 136 if Text != None : 129 137 if Debug : 130 print ( 'Attributes of node: ', elem.attrib)131 print ( 'Text :', elem.text)138 print ( 'Attributes of node: '+str(elem.attrib) ) 139 print ( 'Text : '+str(elem.text) ) 132 140 elem.text = Text 133 141 … … 135 143 # To do : check that Key exist (it is added if not : do we want that ?) 136 144 if Debug : 137 print ( 'Attributes of node: ', elem.attrib)145 print ( 'Attributes of node: '+str(elem.attrib) ) 138 146 elem.attrib.update ( { Key:Value } ) 139 147 … … 143 151 144 152 ## This is the end 145 sys.exit (0)153 sys.exit (0) 146 154 147 155 ### ===========================================================================
Note: See TracChangeset
for help on using the changeset viewer.