Skip to content
Snippets Groups Projects
Commit c722a964 authored by imcovangent's avatar imcovangent
Browse files

Add DC1_MDA_PDFs

Former-commit-id: 568ea8fcd4332acfc6cae98f37cccf4e920e8232
parent c69286f0
No related branches found
No related tags found
No related merge requests found
Showing
with 0 additions and 524 deletions
Workflow name: TUDwingDesign_unconverged-DOE-GS2017-03-24_13:26:34_64
\ No newline at end of file
import os
import sys
from xml.etree import ElementTree as et
class hashabledict(dict):
def __hash__(self):
return hash(tuple(sorted(self.items())))
class XMLCombiner(object):
def __init__(self, filenames):
assert len(filenames) > 0, 'No filenames!'
# save all the roots, in order, to be processed later
self.roots = [et.parse(f).getroot() for f in filenames]
def combine(self):
for r in self.roots[1:]:
# combine each element with the first one, and update that
self.combine_element(self.roots[0], r)
# return the string representation
return et.ElementTree(self.roots[0])
def combine_element(self, one, other):
"""
This function recursively updates either the text or the children
of an element if another element is found in `one`, or adds it
from `other` if not found.
"""
# Create a mapping from tag name to element, as that's what we are fltering with
mapping = {(el.tag, hashabledict(el.attrib)): el for el in one}
for el in other:
if len(el) == 0:
# Not nested
try:
# Update the text
mapping[(el.tag, hashabledict(el.attrib))].text = el.text
except KeyError:
# An element with this name is not in the mapping
mapping[(el.tag, hashabledict(el.attrib))] = el
# Add it
one.append(el)
else:
try:
# Recursively process the element, and update it in the same way
self.combine_element(mapping[(el.tag, hashabledict(el.attrib))], el)
except KeyError:
# Not in the mapping
mapping[(el.tag, hashabledict(el.attrib))] = el
# Just add it
one.append(el)
if __name__ == '__main__':
sys.stdout.write('XML MERGER\n')
for file in sys.argv[1:]:
if file.endswith('.xml'):
sys.stdout.write('file: ' + file + '\n')
r = XMLCombiner(sys.argv[1:]).combine()
print '-'*20
print et.tostring(r.getroot())
r.write('Merger-output-loc.xml', encoding="iso-8859-1", xml_declaration=True)
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<map:mappings xmlns:map="http://www.rcenvironment.de/2015/mapping"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<map:mapping>
<map:source>/cpacs</map:source>
<map:target>/cpacs</map:target>
</map:mapping>
</map:mappings>
\ No newline at end of file
Workflow name: TUDwingDesign_unconverged-DOE-GS2017-03-24_13:26:34_64
\ No newline at end of file
import os
import sys
from xml.etree import ElementTree as et
class hashabledict(dict):
def __hash__(self):
return hash(tuple(sorted(self.items())))
class XMLCombiner(object):
def __init__(self, filenames):
assert len(filenames) > 0, 'No filenames!'
# save all the roots, in order, to be processed later
self.roots = [et.parse(f).getroot() for f in filenames]
def combine(self):
for r in self.roots[1:]:
# combine each element with the first one, and update that
self.combine_element(self.roots[0], r)
# return the string representation
return et.ElementTree(self.roots[0])
def combine_element(self, one, other):
"""
This function recursively updates either the text or the children
of an element if another element is found in `one`, or adds it
from `other` if not found.
"""
# Create a mapping from tag name to element, as that's what we are fltering with
mapping = {(el.tag, hashabledict(el.attrib)): el for el in one}
for el in other:
if len(el) == 0:
# Not nested
try:
# Update the text
mapping[(el.tag, hashabledict(el.attrib))].text = el.text
except KeyError:
# An element with this name is not in the mapping
mapping[(el.tag, hashabledict(el.attrib))] = el
# Add it
one.append(el)
else:
try:
# Recursively process the element, and update it in the same way
self.combine_element(mapping[(el.tag, hashabledict(el.attrib))], el)
except KeyError:
# Not in the mapping
mapping[(el.tag, hashabledict(el.attrib))] = el
# Just add it
one.append(el)
if __name__ == '__main__':
sys.stdout.write('XML MERGER\n')
for file in sys.argv[1:]:
if file.endswith('.xml'):
sys.stdout.write('file: ' + file + '\n')
r = XMLCombiner(sys.argv[1:]).combine()
print '-'*20
print et.tostring(r.getroot())
r.write('Merger-output-loc.xml', encoding="iso-8859-1", xml_declaration=True)
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<map:mappings xmlns:map="http://www.rcenvironment.de/2015/mapping"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<map:mapping>
<map:source>/cpacs</map:source>
<map:target>/cpacs</map:target>
</map:mapping>
</map:mappings>
\ No newline at end of file
Workflow name: TUDwingDesign_unconverged-DOE-GS2017-03-24_13:26:34_64
\ No newline at end of file
import os
import re
import sys
import warnings
import json
from pyKADMOS.packages.TIXI_2_2_4.additional_tixi_functions import ensureElementXPath, get_element_details, \
get_xpath_from_uxpath, ensureElementUXPath
from pyKADMOS.packages.TIXI_2_2_4.tixiwrapper import Tixi
def filter_file(input_file, uxpaths_file, output_file):
# Assert that the files exist
assert os.path.exists(input_file), 'Input file could not be found.'
assert os.path.exists(uxpaths_file), 'UXPaths file could not be found.'
# Open input XML with Tixi
tixi = Tixi()
tixi.openDocument(input_file)
# Check validity of the CPACS file
try:
tixi.uIDCheckDuplicates()
except:
warnings.warn('WARNING: Input file ' + input_file + ' contains UID duplicates.')
# Open json file with UXPaths
with open(uxpaths_file) as data_file:
uxpath_list = json.load(data_file)
assert isinstance(uxpath_list, list), 'UXPaths file should be a json containing a list.'
assert len(uxpath_list) == len(set(uxpath_list)), 'UXPaths list should contain unique values only.'
# Sort the uxpath_list
uxpath_list.sort()
# Create new XML with Tixi
root_name = re.sub("[\(\[].*?[\)\]]", "", uxpath_list[0].split('/')[1])
tixi2 = Tixi()
tixi2.create(root_name)
for uxpath in uxpath_list:
if 'sparPositionUIDs' in uxpath:
print 'CHECK IT OUT!'
print uxpath
# Collect value of node from input XML
var_value, var_dim = get_element_details(tixi, uxpath)
assert var_dim is not None, 'The value for UXPath %s could not be found.' % uxpath
if 'sparPositionUIDs' in uxpath:
print var_value
print var_dim
# Add the uxpath to the new element
xpath = ensureElementUXPath(tixi2, str(uxpath), reference_tixi=tixi)
if 'sparPositionUIDs' in uxpath:
print xpath
print ''
# Add value of the element from the input file to the output file
tixi2.updateTextElement(xpath, var_value)
# Save and close file
tixi2.saveDocument(output_file)
tixi.close()
tixi2.close()
if __name__ == '__main__':
if len(sys.argv)>1:
input_file_path = str(sys.argv[1])
else:
input_file_path = 'Q3D-output.xml'
sys.stdout.write('input file path: ' + input_file_path + '\n')
if len(sys.argv)>1:
uxpaths_file_path = str(sys.argv[2])
else:
uxpaths_file_path = 'uxpaths.json'
sys.stdout.write('UXPaths json file: ' + uxpaths_file_path + '\n')
output_file_path = 'filter_output.xml'
sys.stdout.write('Output file: ' + output_file_path + '\n')
filter_file(input_file_path, uxpaths_file_path, output_file_path)
<?xml version="1.0" encoding="UTF-8"?>
<map:mappings xmlns:map="http://www.rcenvironment.de/2015/mapping"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<map:mapping>
<map:source>/cpacs</map:source>
<map:target>/cpacs</map:target>
</map:mapping>
</map:mappings>
\ No newline at end of file
Workflow name: TUDwingDesign_unconverged-DOE-GS2017-03-24_13:26:34_64
\ No newline at end of file
import os
import re
import sys
import warnings
import json
from pyKADMOS.packages.TIXI_2_2_4.additional_tixi_functions import ensureElementXPath, get_element_details, \
get_xpath_from_uxpath, ensureElementUXPath
from pyKADMOS.packages.TIXI_2_2_4.tixiwrapper import Tixi
def filter_file(input_file, uxpaths_file, output_file):
# Assert that the files exist
assert os.path.exists(input_file), 'Input file could not be found.'
assert os.path.exists(uxpaths_file), 'UXPaths file could not be found.'
# Open input XML with Tixi
tixi = Tixi()
tixi.openDocument(input_file)
# Check validity of the CPACS file
try:
tixi.uIDCheckDuplicates()
except:
warnings.warn('WARNING: Input file ' + input_file + ' contains UID duplicates.')
# Open json file with UXPaths
with open(uxpaths_file) as data_file:
uxpath_list = json.load(data_file)
assert isinstance(uxpath_list, list), 'UXPaths file should be a json containing a list.'
assert len(uxpath_list) == len(set(uxpath_list)), 'UXPaths list should contain unique values only.'
# Sort the uxpath_list
uxpath_list.sort()
# Create new XML with Tixi
root_name = re.sub("[\(\[].*?[\)\]]", "", uxpath_list[0].split('/')[1])
tixi2 = Tixi()
tixi2.create(root_name)
for uxpath in uxpath_list:
if 'sparPositionUIDs' in uxpath:
print 'CHECK IT OUT!'
print uxpath
# Collect value of node from input XML
var_value, var_dim = get_element_details(tixi, uxpath)
assert var_dim is not None, 'The value for UXPath %s could not be found.' % uxpath
if 'sparPositionUIDs' in uxpath:
print var_value
print var_dim
# Add the uxpath to the new element
xpath = ensureElementUXPath(tixi2, str(uxpath), reference_tixi=tixi)
if 'sparPositionUIDs' in uxpath:
print xpath
print ''
# Add value of the element from the input file to the output file
tixi2.updateTextElement(xpath, var_value)
# Save and close file
tixi2.saveDocument(output_file)
tixi.close()
tixi2.close()
if __name__ == '__main__':
if len(sys.argv)>1:
input_file_path = str(sys.argv[1])
else:
input_file_path = 'Q3D-output.xml'
sys.stdout.write('input file path: ' + input_file_path + '\n')
if len(sys.argv)>1:
uxpaths_file_path = str(sys.argv[2])
else:
uxpaths_file_path = 'uxpaths.json'
sys.stdout.write('UXPaths json file: ' + uxpaths_file_path + '\n')
output_file_path = 'filter_output.xml'
sys.stdout.write('Output file: ' + output_file_path + '\n')
filter_file(input_file_path, uxpaths_file_path, output_file_path)
<?xml version="1.0" encoding="UTF-8"?>
<map:mappings xmlns:map="http://www.rcenvironment.de/2015/mapping"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<map:mapping>
<map:source>/cpacs</map:source>
<map:target>/cpacs</map:target>
</map:mapping>
</map:mappings>
\ No newline at end of file
Workflow name: TUDwingDesign_unconverged-DOE-GS2017-03-24_13:26:34_64
\ No newline at end of file
import os
import re
import sys
import warnings
import json
from pyKADMOS.packages.TIXI_2_2_4.additional_tixi_functions import ensureElementXPath, get_element_details, \
get_xpath_from_uxpath, ensureElementUXPath
from pyKADMOS.packages.TIXI_2_2_4.tixiwrapper import Tixi
def filter_file(input_file, uxpaths_file, output_file):
# Assert that the files exist
assert os.path.exists(input_file), 'Input file could not be found.'
assert os.path.exists(uxpaths_file), 'UXPaths file could not be found.'
# Open input XML with Tixi
tixi = Tixi()
tixi.openDocument(input_file)
# Check validity of the CPACS file
try:
tixi.uIDCheckDuplicates()
except:
warnings.warn('WARNING: Input file ' + input_file + ' contains UID duplicates.')
# Open json file with UXPaths
with open(uxpaths_file) as data_file:
uxpath_list = json.load(data_file)
assert isinstance(uxpath_list, list), 'UXPaths file should be a json containing a list.'
assert len(uxpath_list) == len(set(uxpath_list)), 'UXPaths list should contain unique values only.'
# Sort the uxpath_list
uxpath_list.sort()
# Create new XML with Tixi
root_name = re.sub("[\(\[].*?[\)\]]", "", uxpath_list[0].split('/')[1])
tixi2 = Tixi()
tixi2.create(root_name)
for uxpath in uxpath_list:
if 'sparPositionUIDs' in uxpath:
print 'CHECK IT OUT!'
print uxpath
# Collect value of node from input XML
var_value, var_dim = get_element_details(tixi, uxpath)
assert var_dim is not None, 'The value for UXPath %s could not be found.' % uxpath
if 'sparPositionUIDs' in uxpath:
print var_value
print var_dim
# Add the uxpath to the new element
xpath = ensureElementUXPath(tixi2, str(uxpath), reference_tixi=tixi)
if 'sparPositionUIDs' in uxpath:
print xpath
print ''
# Add value of the element from the input file to the output file
tixi2.updateTextElement(xpath, var_value)
# Save and close file
tixi2.saveDocument(output_file)
tixi.close()
tixi2.close()
if __name__ == '__main__':
if len(sys.argv)>1:
input_file_path = str(sys.argv[1])
else:
input_file_path = 'Q3D-output.xml'
sys.stdout.write('input file path: ' + input_file_path + '\n')
if len(sys.argv)>1:
uxpaths_file_path = str(sys.argv[2])
else:
uxpaths_file_path = 'uxpaths.json'
sys.stdout.write('UXPaths json file: ' + uxpaths_file_path + '\n')
output_file_path = 'filter_output.xml'
sys.stdout.write('Output file: ' + output_file_path + '\n')
filter_file(input_file_path, uxpaths_file_path, output_file_path)
<?xml version="1.0" encoding="UTF-8"?>
<map:mappings xmlns:map="http://www.rcenvironment.de/2015/mapping"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<map:mapping>
<map:source>/cpacs</map:source>
<map:target>/cpacs</map:target>
</map:mapping>
</map:mappings>
\ No newline at end of file
Workflow name: TUDwingDesign_unconverged-DOE-GS2017-03-24_13:26:34_64
\ No newline at end of file
import os
import re
import sys
import warnings
import json
from pyKADMOS.packages.TIXI_2_2_4.additional_tixi_functions import ensureElementXPath, get_element_details, \
get_xpath_from_uxpath, ensureElementUXPath
from pyKADMOS.packages.TIXI_2_2_4.tixiwrapper import Tixi
def filter_file(input_file, uxpaths_file, output_file):
# Assert that the files exist
assert os.path.exists(input_file), 'Input file could not be found.'
assert os.path.exists(uxpaths_file), 'UXPaths file could not be found.'
# Open input XML with Tixi
tixi = Tixi()
tixi.openDocument(input_file)
# Check validity of the CPACS file
try:
tixi.uIDCheckDuplicates()
except:
warnings.warn('WARNING: Input file ' + input_file + ' contains UID duplicates.')
# Open json file with UXPaths
with open(uxpaths_file) as data_file:
uxpath_list = json.load(data_file)
assert isinstance(uxpath_list, list), 'UXPaths file should be a json containing a list.'
assert len(uxpath_list) == len(set(uxpath_list)), 'UXPaths list should contain unique values only.'
# Sort the uxpath_list
uxpath_list.sort()
# Create new XML with Tixi
root_name = re.sub("[\(\[].*?[\)\]]", "", uxpath_list[0].split('/')[1])
tixi2 = Tixi()
tixi2.create(root_name)
for uxpath in uxpath_list:
if 'sparPositionUIDs' in uxpath:
print 'CHECK IT OUT!'
print uxpath
# Collect value of node from input XML
var_value, var_dim = get_element_details(tixi, uxpath)
assert var_dim is not None, 'The value for UXPath %s could not be found.' % uxpath
if 'sparPositionUIDs' in uxpath:
print var_value
print var_dim
# Add the uxpath to the new element
xpath = ensureElementUXPath(tixi2, str(uxpath), reference_tixi=tixi)
if 'sparPositionUIDs' in uxpath:
print xpath
print ''
# Add value of the element from the input file to the output file
tixi2.updateTextElement(xpath, var_value)
# Save and close file
tixi2.saveDocument(output_file)
tixi.close()
tixi2.close()
if __name__ == '__main__':
if len(sys.argv)>1:
input_file_path = str(sys.argv[1])
else:
input_file_path = 'Q3D-output.xml'
sys.stdout.write('input file path: ' + input_file_path + '\n')
if len(sys.argv)>1:
uxpaths_file_path = str(sys.argv[2])
else:
uxpaths_file_path = 'uxpaths.json'
sys.stdout.write('UXPaths json file: ' + uxpaths_file_path + '\n')
output_file_path = 'filter_output.xml'
sys.stdout.write('Output file: ' + output_file_path + '\n')
filter_file(input_file_path, uxpaths_file_path, output_file_path)
<?xml version="1.0" encoding="UTF-8"?>
<map:mappings xmlns:map="http://www.rcenvironment.de/2015/mapping"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<map:mapping>
<map:source>/cpacs</map:source>
<map:target>/cpacs</map:target>
</map:mapping>
</map:mappings>
\ No newline at end of file
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