Changeset 3671


Ignore:
Timestamp:
03/20/18 16:05:56 (3 years ago)
Author:
omamce
Message:

O.M. : beautify, and more help

Location:
TOOLS/MOSAIX
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • TOOLS/MOSAIX/README.txt

    r3666 r3671  
    1212All documentation available at https://forge.ipsl.jussieu.fr/igcmg/wiki/IPSLCM6/MOSAIX 
    1313 
     14Extraction : 
     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  
    11# -- 
     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# 
    29 
    310cfg::type     bld                            
  • TOOLS/MOSAIX/update_xml.py

    r3665 r3671  
    3030def usage () : 
    3131    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> 
     32python %(prog)s [-d] [-i iodef.xml] [-o iodef_new.xml] -n <node in Xpath syntax> -k <key>  -v <value> 
     33python %(prog)s [-d] [-i iodef.xml] [-o iodef_new.xml] -n <node in Xpath syntax> -t <value> 
    3434 -d         | --debug         : debug 
    35  -i <file>  | --input=<file>  : input file  (default iodef.xml) 
     35 -i <file>  | --input=<file>  : input file  (default: iodef.xml) 
    3636 -o <file>  | --output=<file> : output file (default: overwrite input file) 
    37  -n <file>  | --node=<file>   : node in Xpath syntax 
     37 -n <node>  | --node=<node>   : node in Xpath syntax 
    3838 -f <field> | --field=<field> : xml field to update 
     39 -v <value> | --value=<value> : new value for xml field 
    3940 -t <text>  | --text=<text>   : will replace the 'text' part of the Xpath by <text> 
    40  -v <value> | --value=<value> : new value for xml field 
    4141example :   
    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 
     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 
    4343    """ 
    4444    #print ( texte % ( sys.argv[0], sys.argv[0], sys.argv[0], sys.argv[0] ) ) 
     
    4646    print ( texte % { 'prog':sys.argv[0] } ) 
    4747     
    48 # Check version 
    49 if sys.version_info<(2,7,0): 
     48# Check version of Python 
     49Version = sys.version_info 
     50if Version < (2,7,0) : 
    5051  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" ) 
    5153  sys.exit (1) 
    5254   
    53 ## Input parameters 
     55## Default input parameters 
    5456FileIn   = 'iodef.xml' 
    5557FileOut  = None 
     
    6466    myopts, myargs = getopt.getopt ( sys.argv[1:], 'i:o:n:k:v:t:dh', [ 'input=', 'output=', 'node=', 'key=', 'value=', 'text=', 'debug=', '--help' ] ) 
    6567except getopt.GetoptError as cmdle : 
    66     print ( "Command line error :", cmdle, "\n" ) 
     68    print ( "Command line error : "+cmdle ) 
    6769    usage () 
    6870    sys.exit(1) 
     
    7981 
    8082## Some coherency checking of command line parameters 
    81 if FileOut == None : FileOut = FileIn 
     83ErrorCount = 0 
     84 
     85if FileIn == None : 
     86    print ( "Error : please specify input file by -i <file>" ) 
     87    ErrorCount += 1 
    8288 
    8389if 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 
    8792     
    8893if 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 
     97if Key != None and Text != None : 
     98    print ( "Error : please specify only one option between -t "+Text+" and -k "+Key ) 
     99    ErrorCount += 1 
     100 
     101if Key != None and Value == None : 
     102    print ( "Error : please specify -v <value> when -k "+Key+" is given") 
     103    ErrorCount += 1 
     104  
     105if ErrorCount > 0 : 
    90106    usage () 
    91107    sys.exit (1) 
    92108 
    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) 
     109if FileOut == None : FileOut = FileIn 
    102110     
    103111## Get XML tree from input file 
     
    107115nodeList = iodef.findall ( Node ) 
    108116 
    109 ## Check that only one node is found 
     117## Check that one and only one node is found 
    110118if len(nodeList) == 0 : 
    111119    print ( "Error : node not found" ) 
    112     print ( "Node  :", Node ) 
    113     sys.exit(1) 
     120    print ( "Node  : "+Node ) 
     121    sys.exit (1) 
    114122     
    115123if 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) 
    119127 
    120128## Update element 
     
    122130 
    123131if 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 ) 
    127135 
    128136if Text != None : 
    129137    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)   ) 
    132140    elem.text = Text 
    133141 
     
    135143    # To do : check that Key exist (it is added if not : do we want that ?) 
    136144    if Debug : 
    137         print ( 'Attributes of node:', elem.attrib ) 
     145        print ( 'Attributes of node: '+str(elem.attrib) ) 
    138146    elem.attrib.update ( { Key:Value } ) 
    139147     
     
    143151 
    144152## This is the end 
    145 sys.exit(0) 
     153sys.exit (0) 
    146154     
    147155### =========================================================================== 
Note: See TracChangeset for help on using the changeset viewer.