Skip to content
Snippets Groups Projects
Commit de7774d2 authored by Tom Fischer's avatar Tom Fischer
Browse files

wip some ideas and snippets

parent e925b904
No related branches found
No related tags found
No related merge requests found
#!/bin/python
import sys
import subprocess
def addMedia(input, out):
xml_path = "//OpenGeoSysProject/time_loop"
ex = "xmlstarlet ed --insert " + xml_path + " --type elem -n media " + input
process = subprocess.Popen(ex.split(), stdout=subprocess.PIPE)
output_stream, errors = process.communicate()
output = output_stream.decode()
outfile = open(out, 'w')
outfile.write(output)
def addMedium(input, out, medium_id):
xml_path = "//OpenGeoSysProject/media"
xml_medium_node = "medium_" + str(medium_id)
ex = "xmlstarlet ed --subnode " + xml_path + " --type elem -n " + xml_medium_node + " " + input
process = subprocess.Popen(ex.split(), stdout=subprocess.PIPE)
output_stream, errors = process.communicate()
output = output_stream.decode()
outfile = open('/tmp/' + xml_medium_node + '_t1.prj', 'w')
outfile.write(output)
xml_medium = xml_path + "/" + xml_medium_node
ex = "xmlstarlet ed --subnode " + xml_medium + " --type attr -n id -v " + str(medium_id) + " /tmp/" + xml_medium_node + "_t1.prj"
process = subprocess.Popen(ex.split(), stdout=subprocess.PIPE)
output_stream, errors = process.communicate()
output = output_stream.decode()
outfile = open('/tmp/' + xml_medium_node + '_t2.prj', 'w')
outfile.write(output)
addPhases('/tmp/' + xml_medium_node + '_t2.prj', '/tmp/' + xml_medium_node + '_t2_phases.prj', xml_medium)
rename_cmd = "xmlstarlet ed --rename " + xml_medium + " -v medium /tmp/" + xml_medium_node + "_t2_phases.prj"
process = subprocess.Popen(rename_cmd.split(), stdout=subprocess.PIPE)
output_stream, errors = process.communicate()
output = output_stream.decode()
outfile = open(out, 'w')
outfile.write(output)
def addPhases(input, out, xml_path):
ex = "xmlstarlet ed --subnode " + xml_path + " --type elem -n phases " + input
process = subprocess.Popen(ex.split(), stdout=subprocess.PIPE)
output_stream, errors = process.communicate()
output = output_stream.decode()
file_name = '/tmp/media_medium_phases.prj'
outfile = open(file_name, 'w')
outfile.write(output)
addPhase(file_name, out, 'AqueousLiquid', "//OpenGeoSysProject/media/medium/phases")
def addPhase(input, out, phase, xml_path):
ex = "xmlstarlet ed --subnode " + xml_path + " --type elem -n phase " + input
process = subprocess.Popen(ex.split(), stdout=subprocess.PIPE)
output_stream, errors = process.communicate()
output = output_stream.decode()
outfile = open(out, 'w')
outfile.write(output)
# phase
xml_path = "//OpenGeoSysProject/media/medium/phases/phase"
ex = "xmlstarlet ed --subnode " + xml_path + " --type elem -n type -v " + phase + " " + out
process = subprocess.Popen(ex.split(), stdout=subprocess.PIPE)
output_stream, errors = process.communicate()
output = output_stream.decode()
outfile = open(out, 'w')
outfile.write(output)
def addProperties(input, out, phase):
xml_path = "//OpenGeoSysProject/media/medium/phases/phase"
ex = "xmlstarlet ed --subnode " + xml_path + " --type elem -n properties " + input
process = subprocess.Popen(ex.split(), stdout=subprocess.PIPE)
output_stream, errors = process.communicate()
output = output_stream.decode()
outfile = open(out, 'w')
outfile.write(output)
def addMediumProperties(input, out):
xml_path = "//OpenGeoSysProject/media/medium"
ex = "xmlstarlet ed --subnode " + xml_path + " --type elem -n properties " + input
process = subprocess.Popen(ex.split(), stdout=subprocess.PIPE)
output_stream, errors = process.communicate()
output = output_stream.decode()
outfile = open(out, 'w')
outfile.write(output)
### create media xml tree
addMedia(sys.argv[1], '/tmp/media.prj')
addMedium('/tmp/media.prj', '/tmp/medium_0.prj', 0)
addMedium('/tmp/medium_0.prj', '/tmp/medium_1.prj', 1)
exit()
addPhase('/tmp/phases.prj', '/tmp/phase.prj', 'AqueousLiquid')
addProperties('/tmp/phase.prj', '/tmp/aqueous_properties.prj', 'AqueousLiquid')
addMediumProperties('/tmp/aqueous_properties.prj', '/tmp/medium_properties.prj')
xmlstarlet sel -t -m "//*[parameter]" th_decovalex.prj
xmlstarlet sel -t -c "//*[parameter]" th_decovalex.prj
xmlstarlet sel -t -v "//*[parameter]" th_decovalex.prj
xmlstarlet sel -t -c "//*[parameter]" th_decovalex.prj
xmlstarlet sel -t -c "//*/parameter" th_decovalex.prj
xmlstarlet sel -t -c "//*/parameter/name" th_decovalex.prj
xmlstarlet sel -t -c "//*/parameter/name[]" th_decovalex.prj
xmlstarlet sel -t -c "//*/parameter/name[1]" th_decovalex.prj
xmlstarlet sel -t -c "//*/parameter/name[2]" th_decovalex.prj
xmlstarlet sel -t -c "//*/parameter/name[text()==mu1]" th_decovalex.prj
xmlstarlet sel -t -c "//*/parameter/name[text()=mu1]" th_decovalex.prj
xmlstarlet sel -t -c "//*/parameter/name[text()='mu1']" th_decovalex.prj
xmlstarlet sel -t -c "//*/parameter/name[text()='mu1'].." th_decovalex.prj
xmlstarlet sel -t -c "//*/parameter/name[text()='mu1']/.." th_decovalex.prj
xmlstarlet sel -t -c "//*/parameter/name[text()='mu1']/.." -m "*" th_decovalex.prj
xmlstarlet sel -t -c "//*/parameter/name[text()='mu1']/.." -c "/.." th_decovalex.prj
xmlstarlet sel -t -m "//*/parameter/name[text()='mu1']/.." -c "/.." th_decovalex.prj
xmlstarlet sel -t -m "//*/parameter/name[text()='mu1']/.." -c "./.." th_decovalex.prj
xmlstarlet sel -t -m "//*/parameter/name[text()='mu1']/.." -c "./.." th_decovalex.prj | less
xmlstarlet sel -t -m "//*/parameter/name[text()='mu1']" -c "./.." th_decovalex.prj | less
xmlstarlet sel -t -m "//*/parameter/name[text()='mu1']/.." -c "./name" th_decovalex.prj | less
xmlstarlet sel -t -m "//*/parameter/name[text()='mu1']/.." -v "./name" th_decovalex.prj | less
xmlstarlet sel -t -m "//*/parameter/name[text()='mu1']/.." -v "./type" th_decovalex.prj | less
xmlstarlet sel -t -m "//*/parameter/name[text()='mu1']/.." -c "./value" th_decovalex.prj | less
xmlstarlet sel -t -m "//*/parameter/name[text()='mu1']/.." -c "./value|values" th_decovalex.prj | less
xmlstarlet sel -t -m "//*/parameter/name[text()='mu1']/.." -m "./type[text()='Constant']" -c "." th_decovalex.prj | less
xmlstarlet sel -t -m "//*/parameter/name[text()='mu1']/.." -m "./type[text()='Constant']" -c "./.." th_decovalex.prj | less
xmlstarlet sel -t -m "//*/parameter/name/.." -m "./type[text()='Constant']" -c "./.." th_decovalex.prj | less
xmlstarlet sel -t -m "//*/parameter/name/.." -m "./type[text()!='Constant']" -c "./.." th_decovalex.prj | less
xmlstarlet sel -t -m "//*/parameter/name/.." -m "./[type!='Constant']" -c "./.." th_decovalex.prj | less
xmlstarlet sel -t -m "//*/parameter/name/.." -m "./[value>0]" -c "./.." th_decovalex.prj | less
xmlstarlet sel -t -m "//*/parameter/name/.." -m ".[value>0]" -c "./.." th_decovalex.prj | less
xmlstarlet sel -t -m "//*/parameter[value>0]" -c "./.." th_decovalex.prj | less
xmlstarlet sel -t -m "//*/parameter[value>0]" -c "./" th_decovalex.prj | less
xmlstarlet sel -t -m "//*/parameter[value>0]" -c "." th_decovalex.prj | less
xmlstarlet sel -t -m "//*/parameter[name=='mu1']" -c "." th_decovalex.prj | less
xmlstarlet sel -t -m "//*/parameter[name='mu1']" -c "." th_decovalex.prj | less
xmlstarlet sel -t -m "//*/parameter[name='mu1' and type='Constant']" -c "." th_decovalex.prj | less
xmlstarlet sel -t -m "//*/parameter[name='mu1' and type='Constant']" -v "./value" th_decovalex.prj | less
xmlstarlet sel -t -m "//*/parameter[name='mu1' and type='Constant']" -v "./value|values" th_decovalex.prj | less
man xmlstarlen
man xmlstarlet
xmlstarlet sel -t -m "//*/parameter[name='mu1' and type='Constant']" -v "./value|values" th_decovalex.prj -C| less
xmlstarlet -C sel -t -m "//*/parameter[name='mu1' and type='Constant']" -v "./value|values" th_decovalex.prj| less
xmlstarlet sel -C -t -m "//*/parameter[name='mu1' and type='Constant']" -v "./value|values" th_decovalex.prj| less
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment