diff --git a/doc/KADMOS.html b/doc/KADMOS.html index 7780838bd9500b94e9b55b12a30611cbd36e3135..479cbb1524dfa90cdf4734c30fb00a1e3e4e0d9f 100644 --- a/doc/KADMOS.html +++ b/doc/KADMOS.html @@ -3862,7 +3862,7 @@ provided then the files are stored in a temp directory.</p> <dl class="method"> <dt id="kadmos.cmdows.cmdows.CMDOWS.add_element_to_element_of_uid"> -<code class="descname">add_element_to_element_of_uid</code><span class="sig-paren">(</span><em>uid</em>, <em>element_to_add</em>, <em>expected_tag_uid_el=None</em>, <em>expected_tag_new_el=None</em><span class="sig-paren">)</span><a class="headerlink" href="#kadmos.cmdows.cmdows.CMDOWS.add_element_to_element_of_uid" title="Permalink to this definition">¶</a></dt> +<code class="descname">append_element_to_uid_element</code><span class="sig-paren">(</span><em>uid</em>, <em>element_to_add</em>, <em>expected_tag_uid_el=None</em>, <em>expected_tag_new_el=None</em><span class="sig-paren">)</span><a class="headerlink" href="#kadmos.cmdows.cmdows.CMDOWS.add_element_to_element_of_uid" title="Permalink to this definition">¶</a></dt> <dd><p>Generic method to add a subelement to an element with a certain UID.</p> <table class="docutils field-list" frame="void" rules="none"> <col class="field-name" /> diff --git a/doc/genindex.html b/doc/genindex.html index b65a1ce98ef24a55b3bbd0fe1a60a909891a6bc2..2b914f7d910cd82046020bcaf252fd52386b558d 100644 --- a/doc/genindex.html +++ b/doc/genindex.html @@ -109,7 +109,7 @@ </li> </ul></td> <td style="width: 33%; vertical-align: top;"><ul> - <li><a href="KADMOS.html#kadmos.cmdows.cmdows.CMDOWS.add_element_to_element_of_uid">add_element_to_element_of_uid() (kadmos.cmdows.cmdows.CMDOWS method)</a> + <li><a href="KADMOS.html#kadmos.cmdows.cmdows.CMDOWS.add_element_to_element_of_uid">append_element_to_uid_element() (kadmos.cmdows.cmdows.CMDOWS method)</a> </li> <li><a href="KADMOS.html#kadmos.graph.mixin_equation.EquationMixin.add_equation">add_equation() (kadmos.graph.mixin_equation.EquationMixin method)</a> </li> diff --git a/examples/knowledgebases/ssbj/__cmdows__SSBJ.xml b/examples/knowledgebases/ssbj/__cmdows__SSBJ.xml index 8067f07d48815ea6557b57077d2c65194d09ad96..503ade6a418a581cc17a6e116d64104c597718dc 100644 --- a/examples/knowledgebases/ssbj/__cmdows__SSBJ.xml +++ b/examples/knowledgebases/ssbj/__cmdows__SSBJ.xml @@ -1,41 +1,255 @@ <?xml version='1.0' encoding='UTF-8'?> <cmdows xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://bitbucket.org/imcovangent/cmdows/raw/master/schema/0.8/cmdows.xsd"> <header> - <creator>I. van Gent</creator> - <description>CMDOWS file of the SSBJ database.</description> - <timestamp>2018-03-07T14:51:56.287006</timestamp> - <fileVersion>0.0</fileVersion> - <cmdowsVersion>0.7</cmdowsVersion> + <timestamp>2018-05-23T11:19:56.287006</timestamp> + <cmdowsVersion>0.8</cmdowsVersion> + <description>CMDOWS file for the SSBJ database.</description> + <fileVersion>1.0</fileVersion> + <creator>Imco van Gent</creator> + <organization> + <contacts> + <contact uID="imcovangent"> + <function>PhD Student</function> + <name>Imco van Gent</name> + <country>The Netherlands</country> + <company>TU Delft</company> + <telephone>0031 6 53 89 42 75</telephone> + <address>Kluyverweg 1, 2629 HS, Delft</address> + <department>Flight Performance and Propulsion</department> + <email>i.vangent@tudelft.nl</email> + </contact> + <contact uID="remilafage"> + <name>Remi Lafage</name> + <country>France</country> + <company>ONERA - French Aerospace Lab</company> + <email>Remi.Lafage@onera.fr</email> + </contact> + <contact uID="sylvaindubreuil"> + <name>Sylvain Dubreuil</name> + <country>France</country> + <company>ONERA - French Aerospace Lab</company> + <email>Sylvain.Dubreuil@onera.fr</email> + </contact> + </contacts> + <organigram> + <architects> + <architect> + <contactUID>imcovangent</contactUID> + </architect> + </architects> + <integrators> + <integrator> + <contactUID>imcovangent</contactUID> + </integrator> + </integrators> + <toolSpecialists> + <toolSpecialist> + <contactUID>remilafage</contactUID> + </toolSpecialist> + <toolSpecialist> + <contactUID>sylvaindubreuil</contactUID> + </toolSpecialist> + </toolSpecialists> + </organigram> + </organization> </header> <executableBlocks> <designCompetences> <designCompetence uID="Structures"> - <ID>Structures</ID> - <modeID>main</modeID> <instanceID>1</instanceID> <version>1.0</version> + <modeID>main</modeID> + <ID>Structures</ID> <label>Structures</label> + <metadata> + <generalInfo> + <status>Available</status> + <description>Structures discipline of the SSBJ tool set.</description> + <owner> + <contactUID>remilafage</contactUID> + </owner> + <creator> + <contactUID>sylvaindubreuil</contactUID> + </creator> + <operator> + <contactUID>imcovangent</contactUID> + </operator> + <licensing> + <licenseType>open-source</licenseType> + <licenseInfo>https://www.apache.org/licenses/LICENSE-2.0</licenseInfo> + <licenseSpecification>Apache License 2.0</licenseSpecification> + </licensing> + <sources> + <repositoryLink>https://bitbucket.org/imcovangent/ssbj-kadmos/src/master/</repositoryLink> + <references> + <reference>ONERA SSBJ-OpenMDAO GitHub repository: https://github.com/OneraHub/SSBJ-OpenMDAO</reference> + <reference>NASA report using SSBJ: https://ntrs.nasa.gov/archive/nasa/casi.ntrs.nasa.gov/19980234657.pdf</reference> + </references> + <downloadLink>https://bitbucket.org/imcovangent/ssbj-kadmos/downloads/</downloadLink> + </sources> + </generalInfo> + <executionInfo> + <localComponentInfo> + <executionDetails> + <operatingSystem>Windows</operatingSystem> + <description>Details for the command line execution of the Structures Python tool in Windows using an Optimus integration.</description> + <softwareRequirements> + <softwareRequirement>Python 2.7.11 or higher installed</softwareRequirement> + <softwareRequirement>kadmos Python package version 0.8 or higher installed</softwareRequirement> + </softwareRequirements> + <command>cd %PROJECTDIR%\SSBJ\n"ssbjkadmos\tools\aerodynamics\structures.py" -i "cpacsInputUpdated.xml" -o "cpacsOutput.xml"\necho doing some analysis\ncopy %PROJECTDIR%\SSBJ\cpacsOutput.xml %METHODDIR%\cpacsOutput.xml</command> + <integrationPlatform>Optimus</integrationPlatform> + </executionDetails> + </localComponentInfo> + </executionInfo> + </metadata> </designCompetence> <designCompetence uID="Aerodynamics"> - <ID>Aerodynamics</ID> - <modeID>main</modeID> <instanceID>1</instanceID> <version>1.0</version> + <modeID>main</modeID> + <ID>Aerodynamics</ID> <label>Aerodynamics</label> + <metadata> + <generalInfo> + <status>Available</status> + <description>Aerodynamics discipline of the SSBJ tool set.</description> + <owner> + <contactUID>remilafage</contactUID> + </owner> + <creator> + <contactUID>sylvaindubreuil</contactUID> + </creator> + <operator> + <contactUID>imcovangent</contactUID> + </operator> + <licensing> + <licenseType>open-source</licenseType> + <licenseInfo>https://www.apache.org/licenses/LICENSE-2.0</licenseInfo> + <licenseSpecification>Apache License 2.0</licenseSpecification> + </licensing> + <sources> + <repositoryLink>https://bitbucket.org/imcovangent/ssbj-kadmos/src/master/</repositoryLink> + <references> + <reference>ONERA SSBJ-OpenMDAO GitHub repository: https://github.com/OneraHub/SSBJ-OpenMDAO</reference> + <reference>NASA report using SSBJ: https://ntrs.nasa.gov/archive/nasa/casi.ntrs.nasa.gov/19980234657.pdf</reference> + </references> + <downloadLink>https://bitbucket.org/imcovangent/ssbj-kadmos/downloads/</downloadLink> + </sources> + </generalInfo> + <executionInfo> + <localComponentInfo> + <executionDetails> + <operatingSystem>Windows</operatingSystem> + <description>Details for the command line execution of the Aerodynamics Python tool in Windows using an Optimus integration.</description> + <softwareRequirements> + <softwareRequirement>Python 2.7.11 or higher installed</softwareRequirement> + <softwareRequirement>kadmos Python package version 0.8 or higher installed</softwareRequirement> + </softwareRequirements> + <command>cd %PROJECTDIR%\SSBJ\n"ssbjkadmos\tools\aerodynamics\aerodynamics.py" -i "cpacsInputUpdated.xml" -o "cpacsOutput.xml"\necho doing some analysis\ncopy %PROJECTDIR%\SSBJ\cpacsOutput.xml %METHODDIR%\cpacsOutput.xml</command> + <integrationPlatform>Optimus</integrationPlatform> + </executionDetails> + </localComponentInfo> + </executionInfo> + </metadata> </designCompetence> <designCompetence uID="Propulsion"> - <ID>Propulsion</ID> - <modeID>main</modeID> <instanceID>1</instanceID> <version>1.0</version> + <modeID>main</modeID> + <ID>Propulsion</ID> <label>Propulsion</label> + <metadata> + <generalInfo> + <status>Available</status> + <description>Propulsion discipline of the SSBJ tool set.</description> + <owner> + <contactUID>remilafage</contactUID> + </owner> + <creator> + <contactUID>sylvaindubreuil</contactUID> + </creator> + <operator> + <contactUID>imcovangent</contactUID> + </operator> + <licensing> + <licenseType>open-source</licenseType> + <licenseInfo>https://www.apache.org/licenses/LICENSE-2.0</licenseInfo> + <licenseSpecification>Apache License 2.0</licenseSpecification> + </licensing> + <sources> + <repositoryLink>https://bitbucket.org/imcovangent/ssbj-kadmos/src/master/</repositoryLink> + <references> + <reference>ONERA SSBJ-OpenMDAO GitHub repository: https://github.com/OneraHub/SSBJ-OpenMDAO</reference> + <reference>NASA report using SSBJ: https://ntrs.nasa.gov/archive/nasa/casi.ntrs.nasa.gov/19980234657.pdf</reference> + </references> + <downloadLink>https://bitbucket.org/imcovangent/ssbj-kadmos/downloads/</downloadLink> + </sources> + </generalInfo> + <executionInfo> + <localComponentInfo> + <executionDetails> + <operatingSystem>Windows</operatingSystem> + <description>Details for the command line execution of the Propulsion Python tool in Windows using an Optimus integration.</description> + <softwareRequirements> + <softwareRequirement>Python 2.7.11 or higher installed</softwareRequirement> + <softwareRequirement>kadmos Python package version 0.8 or higher installed</softwareRequirement> + </softwareRequirements> + <command>cd %PROJECTDIR%\SSBJ\n"ssbjkadmos\tools\aerodynamics\propulsion.py" -i "cpacsInputUpdated.xml" -o "cpacsOutput.xml"\necho doing some analysis\ncopy %PROJECTDIR%\SSBJ\cpacsOutput.xml %METHODDIR%\cpacsOutput.xml</command> + <integrationPlatform>Optimus</integrationPlatform> + </executionDetails> + </localComponentInfo> + </executionInfo> + </metadata> </designCompetence> <designCompetence uID="Performance"> - <ID>Performance</ID> - <modeID>main</modeID> <instanceID>1</instanceID> <version>1.0</version> + <modeID>main</modeID> + <ID>Performance</ID> <label>Performance</label> + <metadata> + <generalInfo> + <status>Available</status> + <description>Performance discipline of the SSBJ tool set.</description> + <owner> + <contactUID>remilafage</contactUID> + </owner> + <creator> + <contactUID>sylvaindubreuil</contactUID> + </creator> + <operator> + <contactUID>imcovangent</contactUID> + </operator> + <licensing> + <licenseType>open-source</licenseType> + <licenseInfo>https://www.apache.org/licenses/LICENSE-2.0</licenseInfo> + <licenseSpecification>Apache License 2.0</licenseSpecification> + </licensing> + <sources> + <repositoryLink>https://bitbucket.org/imcovangent/ssbj-kadmos/src/master/</repositoryLink> + <references> + <reference>ONERA SSBJ-OpenMDAO GitHub repository: https://github.com/OneraHub/SSBJ-OpenMDAO</reference> + <reference>NASA report using SSBJ: https://ntrs.nasa.gov/archive/nasa/casi.ntrs.nasa.gov/19980234657.pdf</reference> + </references> + <downloadLink>https://bitbucket.org/imcovangent/ssbj-kadmos/downloads/</downloadLink> + </sources> + </generalInfo> + <executionInfo> + <localComponentInfo> + <executionDetails> + <operatingSystem>Windows</operatingSystem> + <description>Details for the command line execution of the Performance Python tool in Windows using an Optimus integration.</description> + <softwareRequirements> + <softwareRequirement>Python 2.7.11 or higher installed</softwareRequirement> + <softwareRequirement>kadmos Python package version 0.8 or higher installed</softwareRequirement> + </softwareRequirements> + <command>cd %PROJECTDIR%\SSBJ\n"ssbjkadmos\tools\aerodynamics\performance.py" -i "cpacsInputUpdated.xml" -o "cpacsOutput.xml"\necho doing some analysis\ncopy %PROJECTDIR%\SSBJ\cpacsOutput.xml %METHODDIR%\cpacsOutput.xml</command> + <integrationPlatform>Optimus</integrationPlatform> + </executionDetails> + </localComponentInfo> + </executionInfo> + </metadata> </designCompetence> </designCompetences> </executableBlocks> diff --git a/examples/knowledgebases/ssbj/create_cmdows_file.py b/examples/knowledgebases/ssbj/create_cmdows_file.py new file mode 100644 index 0000000000000000000000000000000000000000..a0baf8cde66b248b6d6b9cb809d6afafa0220759 --- /dev/null +++ b/examples/knowledgebases/ssbj/create_cmdows_file.py @@ -0,0 +1,58 @@ +from kadmos.cmdows import CMDOWS + +cmdows = CMDOWS() + +dcs = ['Structures', 'Aerodynamics', 'Propulsion', 'Performance'] + + +cmdows.add_header('Imco van Gent', 'CMDOWS file for the SSBJ database.', '2018-05-23T11:19:56.287006', + fileVersion='1.0') + +cmdows.add_contact('Imco van Gent', 'i.vangent@tudelft.nl', 'imcovangent', + company='TU Delft', + department='Flight Performance and Propulsion', + function='PhD Student', + address='Kluyverweg 1, 2629 HS, Delft', + country='The Netherlands', + telephone='0031 6 53 89 42 75', + roles=['architect', 'integrator']) +cmdows.add_contact('Remi Lafage', 'Remi.Lafage@onera.fr', 'remilafage', + company='ONERA - French Aerospace Lab', + country='France', + roles=['tool_specialist']) +cmdows.add_contact('Sylvain Dubreuil', 'Sylvain.Dubreuil@onera.fr', 'sylvaindubreuil', + company='ONERA - French Aerospace Lab', + country='France', + roles=['tool_specialist']) + +for dc in dcs: + cmdows.add_dc(dc, dc, 'main', instance_id=1, version='1.0', label=dc) + + cmdows.add_dc_general_info(dc, + description='{} discipline of the SSBJ tool set.'.format(dc), + status='Available', + owner_uid='remilafage', + creator_uid='sylvaindubreuil', + operator_uid='imcovangent') + cmdows.add_dc_licensing(dc, + license_type='open-source', + license_specification='Apache License 2.0', + license_info='https://www.apache.org/licenses/LICENSE-2.0') + cmdows.add_dc_sources(dc, + repository_link='https://bitbucket.org/imcovangent/ssbj-kadmos/src/master/', + download_link='https://bitbucket.org/imcovangent/ssbj-kadmos/downloads/', + references=['ONERA SSBJ-OpenMDAO GitHub repository: https://github.com/OneraHub/SSBJ-OpenMDAO', + 'NASA report using SSBJ: https://ntrs.nasa.gov/archive/nasa/casi.ntrs.nasa.gov/19980234657.pdf']) + cmdows.add_dc_execution_details(dc, + operating_system='Windows', + integration_platform='Optimus', + command='cd %PROJECTDIR%\SSBJ\\n' + '"ssbjkadmos\\tools\\aerodynamics\\{}.py" -i "cpacsInputUpdated.xml" -o "cpacsOutput.xml"\\n' + 'echo doing some analysis\\n' + 'copy %PROJECTDIR%\\SSBJ\\cpacsOutput.xml %METHODDIR%\\cpacsOutput.xml'.format(dc.lower(), dc), + description='Details for the command line execution of the {} Python tool in Windows using an Optimus integration.'.format(dc), + software_requirements=['Python 2.7.11 or higher installed', + 'kadmos Python package version 0.8 or higher installed'], + hardware_requirements=None) + +cmdows.save('__cmdows__SSBJ.xml', pretty_print=True) \ No newline at end of file diff --git a/examples/knowledgebases/tu_delft_wing_design/tu_delft_knowledge_base_cmdows.xml b/examples/knowledgebases/tu_delft_wing_design/tu_delft_knowledge_base_cmdows.xml index 9db4127c4973f2f326a2691ebd215416275c6882..3288fc8fffd6387883091e424b79dc4fe501f60b 100644 --- a/examples/knowledgebases/tu_delft_wing_design/tu_delft_knowledge_base_cmdows.xml +++ b/examples/knowledgebases/tu_delft_wing_design/tu_delft_knowledge_base_cmdows.xml @@ -5,7 +5,7 @@ <description>RCG CMDOWS file of the repository of aircraft design tools from Delft University of Technology</description> <timestamp>2017-09-21T09:00:51.663296</timestamp> <fileVersion>0.2</fileVersion> - <cmdowsVersion>0.7</cmdowsVersion> + <cmdowsVersion>0.8</cmdowsVersion> <updates> <update> <modification>KADMOS export of a repository connectivity graph (RCG).</modification> diff --git a/examples/scripts/ssbj_mda.py b/examples/scripts/ssbj_mda.py index 5e4e31bd14c64e7b47999608c390169f4a8b65dd..a418973a65546c2551b5131f0c550cdd0266b4ca 100644 --- a/examples/scripts/ssbj_mda.py +++ b/examples/scripts/ssbj_mda.py @@ -26,9 +26,9 @@ mdao_definitions = ['unconverged-MDA-GS', # 0 all_graphs = [] # Settings for scripting -mdao_definitions_loop_all = True # Option for looping through all MDAO definitions -mdao_definition_id = 6 # Option for selecting a MDAO definition (in case mdao_definitions_loop_all=False) -start_interactive_vistoms = True # Option to start an interactive VISTOMS at the end +mdao_definitions_loop_all = True # Option for looping through all MDAO definitions +mdao_definition_id = 6 # Option for selecting a MDAO definition (in case mdao_definitions_loop_all=False) +start_interactive_vistoms = False # Option to start an interactive VISTOMS at the end # Settings for loading and saving kb_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '../knowledgebases') diff --git a/examples/scripts/ssbj_mdo.py b/examples/scripts/ssbj_mdo.py index 9e0c795129d8888bac3cc0f34dd8ca3bc45ee25a..dd5e0bcc6c5dd3dba8491e7f596ffbcad38ad635 100644 --- a/examples/scripts/ssbj_mdo.py +++ b/examples/scripts/ssbj_mdo.py @@ -20,7 +20,7 @@ all_graphs = [] # Settings for scripting mdao_definitions_loop_all = True # Option for looping through all MDAO definitions mdao_definition_id = 2 # Option for selecting a MDAO definition (in case mdao_definitions_loop_all=False) -start_interactive_vistoms = True # Option to start an interactive VISTOMS at the end +start_interactive_vistoms = False # Option to start an interactive VISTOMS at the end # Settings for loading and saving kb_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), '../knowledgebases') diff --git a/kadmos/cmdows/cmdows.py b/kadmos/cmdows/cmdows.py index 8cd2f2f275379d64e956436d11867b22259a7afe..f23ad7d345f17a319439a1eae0c3443aa80c8022 100644 --- a/kadmos/cmdows/cmdows.py +++ b/kadmos/cmdows/cmdows.py @@ -188,7 +188,8 @@ class CMDOWS(object): contact.getparent().remove(contact) return - def assert_element_tag(self, el, expected_tag): + @staticmethod + def assert_element_tag(el, expected_tag): """Method to assert that the tag of an element is as expected. :param el: element @@ -259,7 +260,7 @@ class CMDOWS(object): :rtype: xpath """ - el = self.get_element_of_uid(uid, expected_tag=None) + el = self.get_element_of_uid(uid, expected_tag=expected_tag) return el.getroottree().getpath(el) def get_executable_blocks_uids(self): @@ -379,7 +380,7 @@ class CMDOWS(object): # ----------------------------------------- # # Add / change file functions # # ----------------------------------------- # - def add_header(self, creator, description, timestamp=None, fileVersion="0.0", cmdowsVersion="0.7"): + def add_header(self, creator, description, timestamp=None, fileVersion="0.0", cmdowsVersion="0.8"): """Method to add a header to a CMDOWS file. :param creator: name of creator @@ -400,11 +401,9 @@ class CMDOWS(object): el = self.ensure_abs_xpath('/cmdows/header') # Add elements - el.add("creator", creator) - el.add("description", description) - el.add("timestamp", str(datetime.now()).replace(' ', 'T') if timestamp is None else timestamp) - el.add("fileVersion", fileVersion) - el.add("cmdowsVersion", cmdowsVersion) + el.add_multiple(creator=creator, description=description, + timestamp=str(datetime.now()).replace(' ', 'T') if timestamp is None else timestamp, + fileVersion=fileVersion, cmdowsVersion=cmdowsVersion) return def add_contact(self, name, email, uid, company=None, department=None, function=None, address=None, telephone=None, @@ -443,9 +442,6 @@ class CMDOWS(object): * 'customer' """ - # Assert that there is a path to the contacts element or add one - parent_element = self.ensure_abs_xpath('/cmdows/header/organization/contacts') - # Assert that there is no existing element with the uid try: self.get_element_of_uid(uid) @@ -454,18 +450,11 @@ class CMDOWS(object): except: pass - # Add the contact details - contact_element = Element('contact', uID=uid) - contact_element.add('name', name) - contact_element.add('email', email) - contact_element.add('company', company, only_add_if_valued=True) - contact_element.add('department', department, only_add_if_valued=True) - contact_element.add('function', function, only_add_if_valued=True) - contact_element.add('address', address, only_add_if_valued=True) - contact_element.add('telephone', telephone, only_add_if_valued=True) - contact_element.add('country', country, only_add_if_valued=True) - - parent_element.append(contact_element) + # Add the contact element and details + contact_element = self.append_element_to_xpath_element('/cmdows/header/organization/contacts', 'contact', + attrib={'uID': uid}) + contact_element.add_multiple(name=name, email=email, company=company, department=department, function=function, + address=address, telephone=telephone, country=country, only_add_if_valued=True) if roles: if isinstance(roles, list): @@ -495,9 +484,6 @@ class CMDOWS(object): :rtype: XMLSchema """ - # Assert that there is a path to the designCompetences element or add one - parent_element = self.ensure_abs_xpath('/cmdows/executableBlocks/designCompetences') - # Assert that there is no existing element with the uid try: self.get_element_of_uid(uid) @@ -507,48 +493,12 @@ class CMDOWS(object): pass # Add the design competence details - dc_element = Element('designCompetence', uID=uid) + dc_element = self.append_element_to_xpath_element('/cmdows/executableBlocks/designCompetences', 'designCompetence', + attrib={'uID': uid}) if instance_id > 1: - dc_element.add('instanceID', instance_id) - dc_element.add('relatedInstanceUID', "x") #CHANGE: when instance+1? deploy() in __init__.py? how to relate + dc_element.add_multiple(instanceID=instance_id, relatedInstanceUID="x", label=label) # TODO: how to fix this? else: - dc_element.add('ID', id) - dc_element.add('modeID', mode_id) - dc_element.add('instanceID', instance_id) - dc_element.add('version', version) - dc_element.add('label', label) - - parent_element.append(dc_element) - - return - - def add_element_to_element_of_uid(self, uid, element_to_add, expected_tag_uid_el=None, expected_tag_new_el=None): - """Generic method to add a subelement to an element with a certain UID. - - :param uid: uID of element to be added to - :type uid: basestring - :param element_to_add: subelement to be added - :type element_to_add: str - :param expected_tag_uid_el: expected tag of element - :type expected_tag_uid_el: str - :param expected_tag_new_el: expected tag of subelement - :type expected_tag_new_el: str - :return: XML with subelement - :rtype: XMLSchema - """ - - # Assert that there is a UID element - xpath = self.get_xpath_of_uid(uid, expected_tag=expected_tag_uid_el) - - # Assert that an inputs element is given - if expected_tag_new_el: - self.assert_element_tag(element_to_add, expected_tag_new_el) - - # Get element of uid - parent_element = self.get_element_of_uid(uid) - - # Add new element - parent_element.append(element_to_add) + dc_element.add_multiple(ID=id, modeID=mode_id, instanceID=instance_id, version=version, label=label) return def add_dc_inputs_element(self, dc_uid, inputs_element): @@ -561,7 +511,7 @@ class CMDOWS(object): :return: XML with input element :rtype: XMLSchema """ - self.add_element_to_element_of_uid(dc_uid, inputs_element, 'designCompetence', 'inputs') + self.append_element_to_uid_element(dc_uid, inputs_element, 'designCompetence', 'inputs') return def add_dc_outputs_element(self, dc_uid, outputs_element): @@ -574,7 +524,7 @@ class CMDOWS(object): :return: XML with output element :rtype: XMLSchema """ - self.add_element_to_element_of_uid(dc_uid, outputs_element, 'designCompetence', 'outputs') + self.append_element_to_uid_element(dc_uid, outputs_element, 'designCompetence', 'outputs') return def add_dc_general_info(self, dc_uid, description, status=None, creation_date=None, owner_uid=None, @@ -631,17 +581,12 @@ class CMDOWS(object): assert_dict_keys(model_definition, self.MODEL_DEFINITION_ELEMENTS, all_keys_required=False) model_definition = dict_to_ord_dict(model_definition, self.MODEL_DEFINITION_ELEMENTS) - # Assert that there is no existing general info element or else remove it - self.remove_element_based_on_xpath(xpath + '/metadata/generalInfo') - - # Ensure element to metadata parent - parent_element = self.ensure_abs_xpath(xpath + '/metadata') + # Refresh generalInfo element + general_info_element = self.refresh_element_xpath(xpath + '/metadata/generalInfo') # Add the contact details - general_info_element = Element('generalInfo') - general_info_element.add('description', description) - general_info_element.add('status', status, only_add_if_valued=True) - general_info_element.add('creation_date', creation_date, only_add_if_valued=True, camel_case_conversion=True) + general_info_element.add_multiple(description=description, status=status, creation_date=creation_date, + only_add_if_valued=True, camel_case_conversion=True) if owner_uid: if isinstance(owner_uid, basestring): general_info_element.add('owner', {'contactUID': owner_uid}) @@ -662,7 +607,77 @@ class CMDOWS(object): general_info_element.add('operator', {'contactUID': uid}, only_add_if_valued=True) general_info_element.add('model_definition', model_definition, camel_case_conversion=True, only_add_if_valued=True) - parent_element.append(general_info_element) + return general_info_element + + def add_dc_licensing(self, dc_uid, license_type=None, license_specification=None, license_info=None): + """Method to add a licensing element to the generalInfo element of a DC branch. + + :param dc_uid: designCompetence uID + :type dc_uid: basestring + :param license_type: type of license (open-source, commercial, etc) + :type license_type: basestring + :param license_specification: precise license specification (e.g. Apache License 2.0) + :type license_specification: basestring + :param license_info: additional info or full license description + :type license_info: basestring + :return: XML with license info + :rtype: ExtendedElement + """ + # TODO: If instance is higher than 1 the metadata should not be added. + + # Assert that there is a DC element + xpath = self.get_xpath_of_uid(dc_uid, expected_tag='designCompetence') + + # Assert that at least one license element has a value + assert (license_type or license_specification or license_specification) is not None, \ + 'Please specify at least one licensing element.' + + # Refresh licensing element + parent_element = self.refresh_element_xpath(xpath + '/metadata/generalInfo/licensing') + + # Add the licensing details + parent_element.add_multiple(license_type=license_type, + license_specification=license_specification, + license_info=license_info, + only_add_if_valued=True, camel_case_conversion=True) + return + + def add_dc_sources(self, dc_uid, repository_link=None, download_link=None, references=None): + """Method to add a sources element to the generalInfo element of a DC branch. + + :param dc_uid: designCompetence uID + :type dc_uid: basestring + :param repository_link: weblink to repository containing the design competence + :type repository_link: basestring + :param download_link: weblink for downloading the design competence + :type download_link: basestring + :param references: list of references about the design competence (papers, websites, etc.) + :type references: list + :return: XML with license info + :rtype: ExtendedElement + """ + # TODO: If instance is higher than 1 the metadata should not be added. + + # Assert that there is a DC element + xpath = self.get_xpath_of_uid(dc_uid, expected_tag='designCompetence') + + # Assert that at least one license element has a value + assert (repository_link or download_link or references) is not None, \ + 'Please specify at least one sources element.' + # Check the references input + if references: + assert isinstance(references, list), 'references should be a list.' + for ref in references: + assert isinstance(ref, basestring), 'Each reference in the references list should be a string ({}).'.format(ref) + + # Refresh sources element + parent_element = self.refresh_element_xpath(xpath + '/metadata/generalInfo/sources') + + # Add the licensing details + parent_element.add_multiple(repository_link=repository_link, + download_link=download_link, + references=references, + camel_case_conversion=True, only_add_if_valued=True) return def add_dc_performance_info(self, dc_uid, precision=None, fidelity_level=None, run_time=None, verification=None): @@ -704,19 +719,10 @@ class CMDOWS(object): # Assert the verifier is a contact self.get_element_of_uid(verification['verifier']) - # Assert that there is no existing general info element or else remove it - self.remove_element_based_on_xpath(xpath + '/metadata/performanceInfo') - - # Ensure elements to metadata parent - parent_element = self.ensure_abs_xpath(xpath + '/metadata') - # Add the contact details - performance_info_element = Element('performanceInfo') - performance_info_element.add('precision', precision, only_add_if_valued=True) - performance_info_element.add('fidelityLevel', fidelity_level, only_add_if_valued=True) - performance_info_element.add('run_time', run_time, only_add_if_valued=True, camel_case_conversion=True) - parent_element.append(performance_info_element) - + performance_info_element = self.refresh_element_xpath(xpath + '/metadata/performanceInfo') + performance_info_element.add_multiple(precision=precision, fidelity_level=fidelity_level, run_time=run_time, + only_add_if_valued=True, camel_case_conversion=True) if verification: self.add_dc_verification(dc_uid, verification['method'], verification['verifier'], verification['result'], verification['date'], verification['version']) @@ -747,17 +753,15 @@ class CMDOWS(object): self.get_element_of_uid(verifier, expected_tag='contact') if verifier else None # Ensure elements to verifications parent - parent_element = self.ensure_abs_xpath(xpath + '/metadata/performanceInfo/verifications') + verification_element = self.append_element_to_xpath_element(xpath + '/metadata/performanceInfo/verifications', + 'verification') # Find verifications element - verification_element = Element('verification') verification_element.add('method', method) verification_element.add('verifier', {'contactUID': verifier}, camel_case_conversion=False) verification_element.add('result', result) verification_element.add('date', date) verification_element.add('version', version) - - parent_element.append(verification_element) return def add_dc_remote_component_info(self, dc_uid, single_or_multi_execution, job_name, remote_engineer, @@ -781,11 +785,8 @@ class CMDOWS(object): data_exchange_dict = dict_to_ord_dict(data_exchange_dict, self.DATA_EXCHANGE_SETTINGS_ELEMENTS) # Assert that there is an execution info element and remove a potential existing remoteComponent element - parent_element = self.ensure_abs_xpath(xpath + '/metadata/executionInfo') - self.remove_element_based_on_xpath(xpath + '/metadata/executionInfo/remoteComponentInfo') + remote_component_element = self.refresh_element_xpath(xpath + '/metadata/executionInfo/remoteComponentInfo') - # Add the remote component element - remote_component_element = Element('remoteComponentInfo') remote_component_element.add('job_settings', value=OrderedDict((('single_or_multi_execution',single_or_multi_execution), ('job_name', job_name), @@ -794,9 +795,32 @@ class CMDOWS(object): camel_case_conversion=True) remote_component_element.add('data_exchange_settings', value=data_exchange_dict, only_add_if_valued=True, camel_case_conversion=True) - parent_element.append(remote_component_element) return + def add_dc_execution_details(self, dc_uid, operating_system=None, integration_platform=None, command=None, + description=None, software_requirements=None, hardware_requirements=None): + """Method to add a local execution info element to a dc branch.""" + + # TODO: If instance is higher than 1 the metadata should not be added. + + # Assert that there is a DC element + xpath = self.get_xpath_of_uid(dc_uid, expected_tag='designCompetence') + + # Assert at least one element is provided with a value + assert (operating_system or integration_platform or command or description or + software_requirements or hardware_requirements) is not None, 'At least one element should be valued.' + + # First ensure a localComponentInfo XPath + exec_details_el = self.append_element_to_xpath_element(xpath + '/metadata/executionInfo/localComponentInfo', + 'executionDetails') + exec_details_el.add_multiple(operating_system=operating_system, + integration_platform=integration_platform, + command=command, description=description, + software_requirements=software_requirements, + hardware_requirements=hardware_requirements, + camel_case_conversion=True, only_add_if_valued=True) + return exec_details_el + def add_new_parameters_from_element(self, parameters_element): """Method to add the new parameters based on a parameters element. @@ -845,7 +869,7 @@ class CMDOWS(object): # Input assertions self.get_element_of_uid(contact_uid) assert isinstance(role, basestring), 'Role should be of type string.' - assert role in self.ROLES_OPTIONS, 'Role {} does not exist.'.format(role) + assert role in self.ROLES_OPTIONS, 'Role {} does not exist. Choose from: {}'.format(role, self.ROLES_OPTIONS) # Assert that there is a path to the roles element or add one target_element = make_camel_case(role, make_plural_option=True) @@ -898,6 +922,66 @@ class CMDOWS(object): self.add_subelement(el_pr[0], eltag) return self.root.xpath(local_xpath)[0] + def append_element_to_xpath_element(self, xpath, element_tag, attrib=None): + """Method to append a new element at an XPath location. + + :param xpath: unique XPath location where the element should be appended + :type xpath: basestring + :param element_tag: name of the new element to be appended + :type element_tag: basestring + :return: appended element + :rtype: ExtendedElement + """ + el = self.ensure_abs_xpath(xpath) + new_el = el.add(element_tag, attrib=attrib) + return new_el + + def append_element_to_uid_element(self, uid, element_to_add, expected_tag_uid_el=None, expected_tag_new_el=None): + """Generic method to add a subelement to an element with a certain UID. + + :param uid: uID of element to be added to + :type uid: basestring + :param element_to_add: subelement to be added + :type element_to_add: str + :param expected_tag_uid_el: expected tag of element + :type expected_tag_uid_el: str + :param expected_tag_new_el: expected tag of subelement + :type expected_tag_new_el: str + :return: XML with subelement + :rtype: XMLSchema + """ + + # Assert that there is a UID element + xpath = self.get_xpath_of_uid(uid, expected_tag=expected_tag_uid_el) + + # Assert that an inputs element is given + if expected_tag_new_el: + self.assert_element_tag(element_to_add, expected_tag_new_el) + + # Get element of uid + parent_element = self.get_element_of_uid(uid) + + # Add new element + parent_element.append(element_to_add) + return + + def refresh_element_xpath(self, xpath): + """Method to refresh an element based on an XPath. This means the element is removed if it exist and a new + element is created and returned. + + :param xpath: XPath of the element to be refreshed. + :type xpath: basestring + :return: refreshed element + :rtype: ExtendedElement + """ + # Assert that there is no existing licensing element or else remove it + self.remove_element_based_on_xpath(xpath) + + # Ensure element to metadata parent + parent_element = self.ensure_abs_xpath(xpath) + + return parent_element + def resolve_uids(self): """Method to rename duplicate uIDs in a CMDOWS file. diff --git a/kadmos/cmdows/schemas/0.8/cmdows.xml b/kadmos/cmdows/schemas/0.8/cmdows.xml new file mode 100644 index 0000000000000000000000000000000000000000..2665a4718856acf0c4d1b0ca0e9c104fd5e65e13 --- /dev/null +++ b/kadmos/cmdows/schemas/0.8/cmdows.xml @@ -0,0 +1,964 @@ +<cmdows> + <header> + <creator>string</creator> + <description>string</description> + <timestamp>2008-09-29T03:49:45</timestamp> + <fileVersion>string</fileVersion> + <cmdowsVersion>string</cmdowsVersion> + <!--Optional:--> + <updates> + <!--1 or more repetitions:--> + <update> + <modification>string</modification> + <creator>string</creator> + <timestamp>2014-09-19T01:18:33</timestamp> + <fileVersion>string</fileVersion> + <cmdowsVersion>string</cmdowsVersion> + </update> + </updates> + <!--Optional:--> + <organization> + <contacts> + <!--1 or more repetitions:--> + <contact uID="string"> + <name>string</name> + <!--Optional:--> + <email>string</email> + <!--Optional:--> + <company>anyType</company> + <!--Optional:--> + <department>anyType</department> + <!--Optional:--> + <function>string</function> + <!--Optional:--> + <address>string</address> + <!--Optional:--> + <telephone>string</telephone> + <!--Optional:--> + <country>string</country> + </contact> + </contacts> + <!--Optional:--> + <organigram> + <!--Optional:--> + <architects> + <!--1 or more repetitions:--> + <architect> + <contactUID>anyType</contactUID> + </architect> + </architects> + <!--Optional:--> + <integrators> + <!--1 or more repetitions:--> + <integrator> + <contactUID>anyType</contactUID> + </integrator> + </integrators> + <!--Optional:--> + <collaborativeEngineers> + <!--1 or more repetitions:--> + <collaborativeEngineer> + <contactUID>anyType</contactUID> + </collaborativeEngineer> + </collaborativeEngineers> + <!--Optional:--> + <toolSpecialists> + <!--1 or more repetitions:--> + <toolSpecialist> + <contactUID>anyType</contactUID> + </toolSpecialist> + </toolSpecialists> + <!--Optional:--> + <customers> + <!--1 or more repetitions:--> + <customer> + <contactUID>string</contactUID> + </customer> + </customers> + <!--Optional:--> + <projectSpecific>anyType</projectSpecific> + </organigram> + </organization> + </header> + <executableBlocks> + <!--Optional:--> + <designCompetences> + <!--1 or more repetitions:--> + <designCompetence uID="string"> + <label>string</label> + <instanceID>string</instanceID> + <inputs> + <!--1 or more repetitions:--> + <input> + <parameterUID>string</parameterUID> + <!--Optional:--> + <validRanges> + <!--Zero or more repetitions:--> + <limitRange> + <minimum>1.5E2</minimum> + <maximum>1.5E2</maximum> + </limitRange> + <!--Zero or more repetitions:--> + <listRange> + <!--1 or more repetitions:--> + <listRangeItem>string</listRangeItem> + </listRange> + </validRanges> + </input> + </inputs> + <outputs> + <!--1 or more repetitions:--> + <output> + <parameterUID>string</parameterUID> + </output> + </outputs> + <!--You have a CHOICE of the next 2 items at this level--> + <!--Optional:--> + <relatedInstanceUID>string</relatedInstanceUID> + <ID>string</ID> + <modeID>string</modeID> + <version>string</version> + <!--Optional:--> + <metadata> + <!--Optional:--> + <generalInfo> + <!--Optional:--> + <description>string</description> + <!--Optional:--> + <status>string</status> + <!--Optional:--> + <creationDate>2006-08-19+02:00</creationDate> + <!--Optional:--> + <owner> + <!--You have a CHOICE of the next 2 items at this level--> + <!--1 or more repetitions:--> + <contact uID="string"> + <name>string</name> + <!--Optional:--> + <email>string</email> + <!--Optional:--> + <company>anyType</company> + <!--Optional:--> + <department>anyType</department> + <!--Optional:--> + <function>string</function> + <!--Optional:--> + <address>string</address> + <!--Optional:--> + <telephone>string</telephone> + <!--Optional:--> + <country>string</country> + </contact> + <!--1 or more repetitions:--> + <contactUID>string</contactUID> + </owner> + <!--Optional:--> + <creator> + <!--You have a CHOICE of the next 2 items at this level--> + <!--1 or more repetitions:--> + <contact uID="string"> + <name>string</name> + <!--Optional:--> + <email>string</email> + <!--Optional:--> + <company>anyType</company> + <!--Optional:--> + <department>anyType</department> + <!--Optional:--> + <function>string</function> + <!--Optional:--> + <address>string</address> + <!--Optional:--> + <telephone>string</telephone> + <!--Optional:--> + <country>string</country> + </contact> + <!--1 or more repetitions:--> + <contactUID>string</contactUID> + </creator> + <!--Optional:--> + <operator> + <!--You have a CHOICE of the next 2 items at this level--> + <!--1 or more repetitions:--> + <contact uID="string"> + <name>string</name> + <!--Optional:--> + <email>string</email> + <!--Optional:--> + <company>anyType</company> + <!--Optional:--> + <department>anyType</department> + <!--Optional:--> + <function>string</function> + <!--Optional:--> + <address>string</address> + <!--Optional:--> + <telephone>string</telephone> + <!--Optional:--> + <country>string</country> + </contact> + <!--1 or more repetitions:--> + <contactUID>string</contactUID> + </operator> + <!--Optional:--> + <licensing> + <!--Optional:--> + <licenseType>string</licenseType> + <!--Optional:--> + <licenseSpecification>string</licenseSpecification> + <!--Optional:--> + <licenseInfo>string</licenseInfo> + </licensing> + <!--Optional:--> + <sources> + <!--Optional:--> + <repositoryLink>string</repositoryLink> + <!--Optional:--> + <downloadLink>string</downloadLink> + <!--Optional:--> + <references> + <!--1 or more repetitions:--> + <reference>string</reference> + </references> + </sources> + <!--Optional:--> + <modelDefinition> + <!--Optional:--> + <referenceDataSet>string</referenceDataSet> + <!--Optional:--> + <analysisMethod>string</analysisMethod> + <!--Optional:--> + <fittingMethod>string</fittingMethod> + <!--Optional:--> + <relatedDesignCompetenceID>string</relatedDesignCompetenceID> + <!--Optional:--> + <relatedDesignCompetenceVersion>string</relatedDesignCompetenceVersion> + </modelDefinition> + </generalInfo> + <!--Optional:--> + <performanceInfo> + <!--Optional:--> + <precision>1000.00</precision> + <!--Optional:--> + <fidelityLevel>1000.00</fidelityLevel> + <!--Optional:--> + <runTime>1000.00</runTime> + <!--Optional:--> + <standardDeviation>1000.00</standardDeviation> + <!--Optional:--> + <verifications> + <!--1 or more repetitions:--> + <verification> + <method>string</method> + <verifier> + <!--You have a CHOICE of the next 2 items at this level--> + <!--1 or more repetitions:--> + <contact uID="string"> + <name>string</name> + <!--Optional:--> + <email>string</email> + <!--Optional:--> + <company>anyType</company> + <!--Optional:--> + <department>anyType</department> + <!--Optional:--> + <function>string</function> + <!--Optional:--> + <address>string</address> + <!--Optional:--> + <telephone>string</telephone> + <!--Optional:--> + <country>string</country> + </contact> + <!--1 or more repetitions:--> + <contactUID>string</contactUID> + </verifier> + <result>string</result> + <date>2009-05-16</date> + <version>string</version> + </verification> + </verifications> + </performanceInfo> + <!--Optional:--> + <executionInfo> + <!--Optional:--> + <availabilityConstraints> + <!--Optional:--> + <fromDate>2003-08-09+02:00</fromDate> + <!--Optional:--> + <toDate>2012-09-13+02:00</toDate> + <!--Optional:--> + <fromOfficeHour>09:16:36</fromOfficeHour> + <!--Optional:--> + <toOfficeHour>17:05:32</toOfficeHour> + <!--Optional:--> + <maximumTotalExecutions>3</maximumTotalExecutions> + <!--Optional:--> + <maximumParallelExecutions>3</maximumParallelExecutions> + </availabilityConstraints> + <!--Optional:--> + <authorizationConstraints> + <!--Optional:--> + <authorizedUsers> + <!--1 or more repetitions:--> + <authorizedUser> + <!--You have a CHOICE of the next 2 items at this level--> + <!--1 or more repetitions:--> + <contact uID="string"> + <name>string</name> + <!--Optional:--> + <email>string</email> + <!--Optional:--> + <company>anyType</company> + <!--Optional:--> + <department>anyType</department> + <!--Optional:--> + <function>string</function> + <!--Optional:--> + <address>string</address> + <!--Optional:--> + <telephone>string</telephone> + <!--Optional:--> + <country>string</country> + </contact> + <!--1 or more repetitions:--> + <contactUID>string</contactUID> + </authorizedUser> + </authorizedUsers> + <!--Optional:--> + <unauthorizedUsers> + <!--1 or more repetitions:--> + <unauthorizedUser> + <!--You have a CHOICE of the next 2 items at this level--> + <!--1 or more repetitions:--> + <contact uID="string"> + <name>string</name> + <!--Optional:--> + <email>string</email> + <!--Optional:--> + <company>anyType</company> + <!--Optional:--> + <department>anyType</department> + <!--Optional:--> + <function>string</function> + <!--Optional:--> + <address>string</address> + <!--Optional:--> + <telephone>string</telephone> + <!--Optional:--> + <country>string</country> + </contact> + <!--1 or more repetitions:--> + <contactUID>string</contactUID> + </unauthorizedUser> + </unauthorizedUsers> + </authorizationConstraints> + <!--Optional:--> + <remoteComponentInfo> + <!--Optional:--> + <jobSettings> + <!--Optional:--> + <singleOrMultiExecution>single</singleOrMultiExecution> + <!--Optional:--> + <jobName>string</jobName> + <!--Optional:--> + <remoteEngineer> + <!--You have a CHOICE of the next 2 items at this level--> + <!--1 or more repetitions:--> + <contact uID="string"> + <name>string</name> + <!--Optional:--> + <email>string</email> + <!--Optional:--> + <company>anyType</company> + <!--Optional:--> + <department>anyType</department> + <!--Optional:--> + <function>string</function> + <!--Optional:--> + <address>string</address> + <!--Optional:--> + <telephone>string</telephone> + <!--Optional:--> + <country>string</country> + </contact> + <!--1 or more repetitions:--> + <contactUID>string</contactUID> + </remoteEngineer> + <!--Optional:--> + <notificationMessage>string</notificationMessage> + </jobSettings> + <!--Optional:--> + <dataExchangeSettings> + <!--Optional:--> + <dataserver>string</dataserver> + <!--Optional:--> + <urlsite>string</urlsite> + <!--Optional:--> + <webAuthenticationProtocol>string</webAuthenticationProtocol> + <!--Optional:--> + <context>string</context> + <!--Optional:--> + <folder>string</folder> + <!--Optional:--> + <pollingTime>1.5E2</pollingTime> + <!--Optional:--> + <maxIterations>3</maxIterations> + <!--Optional:--> + <timeOut>1.5E2</timeOut> + <!--Optional:--> + <sharedFilePolicy>string</sharedFilePolicy> + <!--Optional:--> + <servermutex>string</servermutex> + </dataExchangeSettings> + </remoteComponentInfo> + <!--Optional:--> + <localComponentInfo> + <!--1 or more repetitions:--> + <executionDetails> + <!--Optional:--> + <operatingSystem>string</operatingSystem> + <!--Optional:--> + <integrationPlatform>string</integrationPlatform> + <!--Optional:--> + <command>string</command> + <!--Optional:--> + <description>string</description> + <!--Optional:--> + <softwareRequirements> + <!--1 or more repetitions:--> + <softwareRequirement>string</softwareRequirement> + </softwareRequirements> + <!--Optional:--> + <hardwareRequirements> + <!--1 or more repetitions:--> + <hardwareRequirement>string</hardwareRequirement> + </hardwareRequirements> + </executionDetails> + </localComponentInfo> + </executionInfo> + </metadata> + <!--Optional:--> + <projectSpecific>anyType</projectSpecific> + </designCompetence> + </designCompetences> + <!--Optional:--> + <mathematicalFunctions> + <!--1 or more repetitions:--> + <mathematicalFunction uID="string"> + <label>string</label> + <functionType>regular</functionType> + <inputs> + <!--1 or more repetitions:--> + <input> + <parameterUID>string</parameterUID> + <!--Optional:--> + <equationLabel>string string</equationLabel> + <!--Optional:--> + <validRanges> + <!--Zero or more repetitions:--> + <limitRange> + <minimum>1.5E2</minimum> + <maximum>1.5E2</maximum> + </limitRange> + <!--Zero or more repetitions:--> + <listRange> + <!--1 or more repetitions:--> + <listRangeItem>string</listRangeItem> + </listRange> + </validRanges> + </input> + </inputs> + <outputs> + <!--1 or more repetitions:--> + <output> + <parameterUID>string</parameterUID> + <!--You have a CHOICE of the next 2 items at this level--> + <equations uID="string"> + <!--1 or more repetitions:--> + <equation language="string">string</equation> + </equations> + <equationsUID>string</equationsUID> + </output> + </outputs> + </mathematicalFunction> + </mathematicalFunctions> + </executableBlocks> + <parameters> + <!--1 or more repetitions:--> + <parameter uID="string"> + <label>string</label> + <instanceID>3</instanceID> + <!--You have a CHOICE of the next 2 items at this level--> + <relatedInstanceUID>string</relatedInstanceUID> + <!--Optional:--> + <description>string</description> + <!--Optional:--> + <schemaPath>string</schemaPath> + <!--Optional:--> + <note>string</note> + <!--Optional:--> + <defaultValue>string</defaultValue> + <!--Optional:--> + <unit>string</unit> + <!--Optional:--> + <dataType>string</dataType> + </parameter> + </parameters> + <!--Optional:--> + <problemDefinition uID="string"> + <problemFormulation> + <mdaoArchitecture>string</mdaoArchitecture> + <!--Optional:--> + <convergerType>string</convergerType> + <executableBlocksOrder> + <!--1 or more repetitions:--> + <executableBlock position="3">string</executableBlock> + </executableBlocksOrder> + <allowUnconvergedCouplings>false</allowUnconvergedCouplings> + <!--Optional:--> + <doeSettings> + <doeMethod>string</doeMethod> + <!--Optional:--> + <doeSeed>1000.00</doeSeed> + <!--Optional:--> + <doeRuns>3</doeRuns> + </doeSettings> + </problemFormulation> + <problemRoles> + <parameters> + <!--Optional:--> + <designVariables> + <!--1 or more repetitions:--> + <designVariable uID="string"> + <parameterUID>string</parameterUID> + <!--Optional:--> + <nominalValue>1000.00</nominalValue> + <!--Optional:--> + <validRanges> + <!--Zero or more repetitions:--> + <limitRange> + <minimum>1.5E2</minimum> + <maximum>1.5E2</maximum> + </limitRange> + <!--Zero or more repetitions:--> + <listRange> + <!--1 or more repetitions:--> + <listRangeItem>string</listRangeItem> + </listRange> + </validRanges> + <!--Optional:--> + <variableType>int</variableType> + <!--Optional:--> + <samples> + <!--1 or more repetitions:--> + <sample position="string">1000.00</sample> + </samples> + </designVariable> + </designVariables> + <!--Optional:--> + <objectiveVariables> + <!--1 or more repetitions:--> + <objectiveVariable uID="string"> + <parameterUID>string</parameterUID> + </objectiveVariable> + </objectiveVariables> + <!--Optional:--> + <constraintVariables> + <!--1 or more repetitions:--> + <constraintVariable uID="string"> + <parameterUID>string</parameterUID> + <!--Optional:--> + <constraintType>string</constraintType> + <!--Optional:--> + <constraintOperator>anyType</constraintOperator> + <!--Optional:--> + <referenceValue>anyType</referenceValue> + <!--Optional:--> + <requiredEqualityPrecision>1000.00</requiredEqualityPrecision> + </constraintVariable> + </constraintVariables> + <!--Optional:--> + <stateVariables> + <!--1 or more repetitions:--> + <stateVariable uID="string"> + <parameterUID>string</parameterUID> + </stateVariable> + </stateVariables> + </parameters> + <executableBlocks> + <!--Optional:--> + <preCouplingBlocks> + <!--1 or more repetitions:--> + <preCouplingBlock>string</preCouplingBlock> + </preCouplingBlocks> + <!--Optional:--> + <coupledBlocks> + <!--1 or more repetitions:--> + <coupledBlock>string</coupledBlock> + </coupledBlocks> + <!--Optional:--> + <postCouplingBlocks> + <!--1 or more repetitions:--> + <postCouplingBlock>string</postCouplingBlock> + </postCouplingBlocks> + <!--Optional:--> + <preDesvarsBlocks> + <!--1 or more repetitions:--> + <preDesvarsBlock>string</preDesvarsBlock> + </preDesvarsBlocks> + <!--Optional:--> + <postDesvarsBlocks> + <!--1 or more repetitions:--> + <postDesvarBlock>string</postDesvarBlock> + </postDesvarsBlocks> + </executableBlocks> + </problemRoles> + </problemDefinition> + <!--Optional:--> + <workflow> + <!--Optional:--> + <problemDefinitionUID>string</problemDefinitionUID> + <dataGraph> + <name>string</name> + <edges> + <!--1 or more repetitions:--> + <edge> + <!--You have a CHOICE of the next 2 items at this level--> + <fromParameterUID>string</fromParameterUID> + <fromExecutableBlockUID>string</fromExecutableBlockUID> + <!--You have a CHOICE of the next 2 items at this level--> + <toParameterUID>anyType</toParameterUID> + <toExecutableBlockUID>anyType</toExecutableBlockUID> + </edge> + </edges> + <!--Optional:--> + <metadata>anyType</metadata> + </dataGraph> + <!--Optional:--> + <processGraph> + <name>string</name> + <edges> + <!--1 or more repetitions:--> + <edge> + <fromExecutableBlockUID>string</fromExecutableBlockUID> + <toExecutableBlockUID>string</toExecutableBlockUID> + <processStepNumber>3</processStepNumber> + </edge> + </edges> + <nodes> + <!--1 or more repetitions:--> + <node> + <referenceUID>string</referenceUID> + <processStepNumber>3</processStepNumber> + <!--Optional:--> + <convergerStepNumber>3</convergerStepNumber> + <diagonalPosition>3</diagonalPosition> + </node> + </nodes> + <!--Optional:--> + <metadata> + <!--Optional:--> + <loopNesting relatedUID="string"> + <!--Optional:--> + <loopElements> + <!--1 or more repetitions:--> + <loopElement/> + </loopElements> + <!--Optional:--> + <functionElements> + <!--1 or more repetitions:--> + <functionElement>string</functionElement> + </functionElements> + </loopNesting> + </metadata> + </processGraph> + </workflow> + <!--Optional:--> + <architectureElements> + <parameters> + <!--Optional:--> + <initialGuessCouplingVariables> + <!--1 or more repetitions:--> + <initialGuessCouplingVariable uID="string"> + <!--You have a CHOICE of the next 2 items at this level--> + <relatedParameterUID>string</relatedParameterUID> + <relatedInstanceUID>string</relatedInstanceUID> + <label>string</label> + <instanceID>3</instanceID> + </initialGuessCouplingVariable> + </initialGuessCouplingVariables> + <!--Optional:--> + <finalCouplingVariables> + <!--1 or more repetitions:--> + <finalCouplingVariable uID="string"> + <!--You have a CHOICE of the next 2 items at this level--> + <relatedParameterUID>string</relatedParameterUID> + <relatedInstanceUID>string</relatedInstanceUID> + <label>string</label> + <instanceID>3</instanceID> + </finalCouplingVariable> + </finalCouplingVariables> + <!--Optional:--> + <couplingCopyVariables> + <!--1 or more repetitions:--> + <couplingCopyVariable uID="string"> + <!--You have a CHOICE of the next 2 items at this level--> + <relatedParameterUID>string</relatedParameterUID> + <relatedInstanceUID>string</relatedInstanceUID> + <label>string</label> + <instanceID>3</instanceID> + </couplingCopyVariable> + </couplingCopyVariables> + <!--Optional:--> + <initialGuessDesignVariables> + <!--1 or more repetitions:--> + <initialGuessDesignVariable uID="string"> + <!--You have a CHOICE of the next 2 items at this level--> + <relatedParameterUID>string</relatedParameterUID> + <relatedInstanceUID>string</relatedInstanceUID> + <label>string</label> + <instanceID>3</instanceID> + </initialGuessDesignVariable> + </initialGuessDesignVariables> + <!--Optional:--> + <finalDesignVariables> + <!--1 or more repetitions:--> + <finalDesignVariable uID="string"> + <!--You have a CHOICE of the next 2 items at this level--> + <relatedParameterUID>string</relatedParameterUID> + <relatedInstanceUID>string</relatedInstanceUID> + <label>string</label> + <instanceID>3</instanceID> + </finalDesignVariable> + </finalDesignVariables> + <!--Optional:--> + <finalOutputVariables> + <!--1 or more repetitions:--> + <finalOutputVariable uID="string"> + <!--You have a CHOICE of the next 2 items at this level--> + <relatedParameterUID>string</relatedParameterUID> + <relatedInstanceUID>string</relatedInstanceUID> + <label>string</label> + <instanceID>3</instanceID> + </finalOutputVariable> + </finalOutputVariables> + <!--Optional:--> + <copyDesignVariables> + <!--1 or more repetitions:--> + <copyDesignVariable uID="string"> + <!--You have a CHOICE of the next 2 items at this level--> + <relatedParameterUID>string</relatedParameterUID> + <relatedInstanceUID>string</relatedInstanceUID> + <label>string</label> + <instanceID>3</instanceID> + </copyDesignVariable> + </copyDesignVariables> + <!--Optional:--> + <consistencyConstraintVariables> + <!--1 or more repetitions:--> + <consistencyConstraintVariable uID="string"> + <!--You have a CHOICE of the next 2 items at this level--> + <relatedParameterUID>string</relatedParameterUID> + <relatedInstanceUID>string</relatedInstanceUID> + <label>string</label> + <instanceID>3</instanceID> + </consistencyConstraintVariable> + </consistencyConstraintVariables> + <!--Optional:--> + <doeInputSampleLists> + <!--1 or more repetitions:--> + <doeInputSampleList uID="string"> + <!--You have a CHOICE of the next 2 items at this level--> + <relatedParameterUID>string</relatedParameterUID> + <relatedInstanceUID>string</relatedInstanceUID> + <label>string</label> + <instanceID>3</instanceID> + </doeInputSampleList> + </doeInputSampleLists> + <!--Optional:--> + <doeOutputSampleLists> + <!--1 or more repetitions:--> + <doeOutputSampleList uID="string"> + <!--You have a CHOICE of the next 2 items at this level--> + <relatedParameterUID>string</relatedParameterUID> + <relatedInstanceUID>string</relatedInstanceUID> + <label>string</label> + <instanceID>3</instanceID> + </doeOutputSampleList> + </doeOutputSampleLists> + <!--Optional:--> + <surrogateModelApproximates> + <!--1 or more repetitions:--> + <surrogateModelApproximate uID="string"> + <!--You have a CHOICE of the next 2 items at this level--> + <relatedParameterUID>string</relatedParameterUID> + <relatedInstanceUID>string</relatedInstanceUID> + <label>string</label> + <instanceID>3</instanceID> + </surrogateModelApproximate> + </surrogateModelApproximates> + <!--Optional:--> + <couplingWeights> + <!--1 or more repetitions:--> + <couplingWeight uID="string"> + <!--You have a CHOICE of the next 2 items at this level--> + <relatedParameterUID>string</relatedParameterUID> + <relatedInstanceUID>string</relatedInstanceUID> + <label>string</label> + <instanceID>3</instanceID> + </couplingWeight> + </couplingWeights> + </parameters> + <executableBlocks> + <!--Optional:--> + <coordinators> + <!--1 or more repetitions:--> + <coordinator uID="string"> + <label>string</label> + <!--Optional:--> + <settings>string</settings> + </coordinator> + </coordinators> + <!--Optional:--> + <optimizers> + <!--1 or more repetitions:--> + <optimizer uID="string"> + <!--Optional:--> + <label>string</label> + <!--Optional:--> + <settings> + <maximumIterations>1.5E2</maximumIterations> + <algorithm>string</algorithm> + <applyScaling>false</applyScaling> + <maximumFunctionEvaluations>1.5E2</maximumFunctionEvaluations> + <constraintTolerance>1.5E2</constraintTolerance> + <convergenceTolerance>1.5E2</convergenceTolerance> + </settings> + <!--Optional:--> + <designVariables> + <!--1 or more repetitions:--> + <designVariable> + <designVariableUID>string</designVariableUID> + </designVariable> + </designVariables> + <!--Optional:--> + <objectiveVariables> + <!--1 or more repetitions:--> + <objectiveVariable> + <objectiveVariableUID>string</objectiveVariableUID> + </objectiveVariable> + </objectiveVariables> + <!--Optional:--> + <constraintVariables> + <!--1 or more repetitions:--> + <constraintVariable> + <constraintVariableUID>string</constraintVariableUID> + </constraintVariable> + </constraintVariables> + </optimizer> + </optimizers> + <!--Optional:--> + <convergers> + <!--1 or more repetitions:--> + <converger uID="string"> + <!--Optional:--> + <label>string</label> + <!--Optional:--> + <settings> + <lastIterationsToConsider>1.5E2</lastIterationsToConsider> + <maximumIterations>1.5E2</maximumIterations> + <convergenceToleranceRelative>1.5E2</convergenceToleranceRelative> + <convergenceToleranceAbsolute>1.5E2</convergenceToleranceAbsolute> + </settings> + </converger> + </convergers> + <!--Optional:--> + <does> + <!--1 or more repetitions:--> + <doe uID="string"> + <label>string</label> + <settings> + <!--Optional:--> + <doeTable> + <!--1 or more repetitions:--> + <tableRow relatedParameterUID="string"> + <!--1 or more repetitions:--> + <tableElement experimentID="string">1000.00</tableElement> + </tableRow> + </doeTable> + <!--Optional:--> + <doeMethod>string</doeMethod> + <!--Optional:--> + <doeRuns>100</doeRuns> + <!--Optional:--> + <doeSeed>100</doeSeed> + </settings> + <!--Optional:--> + <designVariables> + <!--1 or more repetitions:--> + <designVariable> + <designVariableUID>string</designVariableUID> + </designVariable> + </designVariables> + </doe> + </does> + <!--Optional:--> + <surrogateModels> + <!--1 or more repetitions:--> + <surrogateModel> + <relatedExecutableBlockUID>string</relatedExecutableBlockUID> + </surrogateModel> + </surrogateModels> + <!--Optional:--> + <boundaryDeterminators> + <!--1 or more repetitions:--> + <boundaryDeterminator> + <relatedExecutableBlockUID>string</relatedExecutableBlockUID> + </boundaryDeterminator> + </boundaryDeterminators> + <!--Optional:--> + <surrogateModelBuilders> + <!--1 or more repetitions:--> + <surrogateModelBuilder> + <relatedExecutableBlockUID>string</relatedExecutableBlockUID> + </surrogateModelBuilder> + </surrogateModelBuilders> + <!--Optional:--> + <preCouplingAnalyses> + <!--1 or more repetitions:--> + <preCouplingAnalysis> + <relatedExecutableBlockUID>string</relatedExecutableBlockUID> + </preCouplingAnalysis> + </preCouplingAnalyses> + <!--Optional:--> + <preIteratorAnalyses> + <!--1 or more repetitions:--> + <preIteratorAnalysis> + <relatedExecutableBlockUID>string</relatedExecutableBlockUID> + </preIteratorAnalysis> + </preIteratorAnalyses> + <!--Optional:--> + <postIteratorAnalyses> + <!--1 or more repetitions:--> + <postIteratorAnalysis> + <relatedExecutableBlockUID>string</relatedExecutableBlockUID> + </postIteratorAnalysis> + </postIteratorAnalyses> + <!--Optional:--> + <coupledAnalyses> + <!--1 or more repetitions:--> + <coupledAnalysis> + <relatedExecutableBlockUID>string</relatedExecutableBlockUID> + </coupledAnalysis> + </coupledAnalyses> + <!--Optional:--> + <postCouplingAnalyses> + <!--1 or more repetitions:--> + <postCouplingAnalysis> + <relatedExecutableBlockUID>string</relatedExecutableBlockUID> + </postCouplingAnalysis> + </postCouplingAnalyses> + </executableBlocks> + </architectureElements> +</cmdows> \ No newline at end of file diff --git a/kadmos/cmdows/schemas/0.8/cmdows.xsd b/kadmos/cmdows/schemas/0.8/cmdows.xsd index b15d484ae5cb92c371f9e2c04e22f25a4da22252..8e7684d4310c6aeb65bbe816071435a49d1316a2 100644 --- a/kadmos/cmdows/schemas/0.8/cmdows.xsd +++ b/kadmos/cmdows/schemas/0.8/cmdows.xsd @@ -265,6 +265,63 @@ <xs:documentation>Operator(s) of the design competence to be contacted in case of problems</xs:documentation> </xs:annotation> </xs:element> + <xs:element name="licensing" minOccurs="0"> + <xs:annotation> + <xs:documentation>Optional element to specify licensing information.</xs:documentation> + </xs:annotation> + <xs:complexType> + <xs:all> + <xs:element name="licenseType" type="xs:string" minOccurs="0"> + <xs:annotation> + <xs:documentation>License type examples: commercial, open-source, academic.</xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="licenseSpecification" type="xs:string" minOccurs="0"> + <xs:annotation> + <xs:documentation>License specification using a link or description. E.g.: Apache License 2.0</xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="licenseInfo" type="xs:string" minOccurs="0"> + <xs:annotation> + <xs:documentation>Additional information concerning the license (e.g. how to receive it if commercial, link to open-source license).</xs:documentation> + </xs:annotation> + </xs:element> + </xs:all> + </xs:complexType> + </xs:element> + <xs:element name="sources" minOccurs="0"> + <xs:annotation> + <xs:documentation>Optional element to specify sources for the design competence, such as download link, repository link, papers, websites, etc.</xs:documentation> + </xs:annotation> + <xs:complexType> + <xs:all> + <xs:element name="repositoryLink" type="xs:string" minOccurs="0"> + <xs:annotation> + <xs:documentation>Link to the (open-source) software repository.</xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="downloadLink" type="xs:string" minOccurs="0"> + <xs:annotation> + <xs:documentation>Link to the download link (for installation files, for example).</xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="references" minOccurs="0"> + <xs:annotation> + <xs:documentation>Additional references, such as websites, papers and others.</xs:documentation> + </xs:annotation> + <xs:complexType> + <xs:sequence> + <xs:element name="reference" type="xs:string" maxOccurs="unbounded"> + <xs:annotation> + <xs:documentation>Additional reference, such as website, papers or other.</xs:documentation> + </xs:annotation> + </xs:element> + </xs:sequence> + </xs:complexType> + </xs:element> + </xs:all> + </xs:complexType> + </xs:element> <xs:element name="modelDefinition" minOccurs="0"> <xs:annotation> <xs:documentation>Optional element for 'surrogateModel' competence types</xs:documentation> @@ -383,6 +440,36 @@ </xs:all> </xs:complexType> </xs:element> + <xs:element name="localComponentInfo" minOccurs="0"> + <xs:complexType> + <xs:sequence> + <xs:element name="executionDetails" maxOccurs="unbounded"> + <xs:complexType> + <xs:all> + <xs:element name="operatingSystem" type="xs:string" minOccurs="0"/> + <xs:element name="integrationPlatform" type="xs:string" minOccurs="0"/> + <xs:element name="command" type="xs:string" minOccurs="0"/> + <xs:element name="description" type="xs:string" minOccurs="0"/> + <xs:element name="softwareRequirements" minOccurs="0"> + <xs:complexType> + <xs:sequence> + <xs:element name="softwareRequirement" type="xs:string" maxOccurs="unbounded"/> + </xs:sequence> + </xs:complexType> + </xs:element> + <xs:element name="hardwareRequirements" minOccurs="0"> + <xs:complexType> + <xs:sequence> + <xs:element name="hardwareRequirement" type="xs:string" maxOccurs="unbounded"/> + </xs:sequence> + </xs:complexType> + </xs:element> + </xs:all> + </xs:complexType> + </xs:element> + </xs:sequence> + </xs:complexType> + </xs:element> </xs:all> </xs:complexType> </xs:element> @@ -528,8 +615,21 @@ <xs:documentation>Any additional note for the parameter</xs:documentation> </xs:annotation> </xs:element> - <xs:element name="unit" type="xs:string" minOccurs="0"/> - <xs:element name="dataType" type="xs:string" minOccurs="0"/> + <xs:element name="defaultValue" type="xs:string" minOccurs="0"> + <xs:annotation> + <xs:documentation>Default value of the parameter</xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="unit" type="xs:string" minOccurs="0"> + <xs:annotation> + <xs:documentation>Unit used for the parameter, e.g. m, s, Pa, N, kN, etc.</xs:documentation> + </xs:annotation> + </xs:element> + <xs:element name="dataType" type="xs:string" minOccurs="0"> + <xs:annotation> + <xs:documentation>Datatype used to store the parameter value, e.g. scalar, vector, matrix</xs:documentation> + </xs:annotation> + </xs:element> </xs:sequence> </xs:choice> </xs:sequence> @@ -1178,7 +1278,7 @@ </xs:complexType> <xs:complexType name="contactType"> <xs:choice> - <xs:element name="contact"> + <xs:element name="contact" maxOccurs="unbounded"> <xs:complexType> <xs:all> <xs:element name="name" type="xs:string"> @@ -1205,7 +1305,7 @@ </xs:attribute> </xs:complexType> </xs:element> - <xs:element name="contactUID" type="xs:string"/> + <xs:element name="contactUID" type="xs:string" maxOccurs="unbounded"/> </xs:choice> </xs:complexType> <xs:complexType name="loopElementType"> diff --git a/kadmos/graph/graph_data.py b/kadmos/graph/graph_data.py index 308b5b3c20fd21ed6e91707587fb507ff11f83c5..b4e8b6d344edbda24082050bbb9424791de2e1a4 100644 --- a/kadmos/graph/graph_data.py +++ b/kadmos/graph/graph_data.py @@ -1174,7 +1174,7 @@ class DataGraph(KadmosGraph): el = els[0] default_value = el.text if default_value: - self.nodes[var_node]['note'] = default_value + self.nodes[var_node]['default_value'] = default_value return diff --git a/kadmos/graph/graph_kadmos.py b/kadmos/graph/graph_kadmos.py index 30c92e92534e9028ef9c7bfd909db55f88aaeb93..766f70d05461425d5388395bfa43e22a9a37d2bc 100644 --- a/kadmos/graph/graph_kadmos.py +++ b/kadmos/graph/graph_kadmos.py @@ -43,8 +43,8 @@ logger = logging.getLogger(__name__) # Settings for the KADMOS file types and the corresponding extensions -file_types = ['cmdows', 'kdms', 'graphml'] -file_extensions = ['xml', 'kdms', 'graphml'] +file_types = ['cmdows', 'kdms', 'graphml', 'zipped-cmdows'] +file_extensions = ['xml', 'kdms', 'graphml', 'zip'] class KadmosGraph(nx.DiGraph, EquationMixin, VistomsMixin): @@ -1065,6 +1065,7 @@ class KadmosGraph(nx.DiGraph, EquationMixin, VistomsMixin): cmdows_parameter.add('description', self.nodes[graph_parameter].get('description'), only_add_if_valued=True) cmdows_parameter.add('note', self.nodes[graph_parameter].get('note'), only_add_if_valued=True) + cmdows_parameter.add('defaultValue', self.nodes[graph_parameter].get('defaultValue'), only_add_if_valued=True) cmdows_parameter.add('unit', self.nodes[graph_parameter].get('unit'), only_add_if_valued=True) cmdows_parameter.add('dataType', self.nodes[graph_parameter].get('data_type'), only_add_if_valued=True) @@ -1285,6 +1286,8 @@ class KadmosGraph(nx.DiGraph, EquationMixin, VistomsMixin): self.nodes[uid]['unit'] = related_variable.findtext('unit') if related_variable.findtext('dataType') is not None: self.nodes[uid]['data_type'] = related_variable.findtext('dataType') + if related_variable.findtext('defaultValue') is not None: + self.nodes[uid]['default_value'] = related_variable.findtext('defaultValue') return @@ -1410,7 +1413,7 @@ class KadmosGraph(nx.DiGraph, EquationMixin, VistomsMixin): # Save file logger.info('Saving the ' + file_type.upper() + ' file ' + file_path + '...') - if file_type == 'cmdows': + if file_type == ('cmdows' or 'zipped-cmdows'): self._save_cmdows(file_path, description=description, creator=creator, version=version, timestamp=timestamp, mpg=mpg, keep_empty_elements=keep_empty_elements, pretty_print=pretty_print, convention=convention, check=True) @@ -4068,7 +4071,7 @@ class KadmosGraph(nx.DiGraph, EquationMixin, VistomsMixin): instance=idx, related_to_schema_node=node) for func in function_order: if func in target_funcs: - self.add_edge(new_node, func) + self.add_edge((node, func), (new_node, func)) self.remove_edge(node, func) if func in source_funcs: if idx == 1 and func not in target_funcs: @@ -4079,7 +4082,7 @@ class KadmosGraph(nx.DiGraph, EquationMixin, VistomsMixin): new_node = self.copy_node_with_suffix(node, '__i'+str(idx), '^{vi'+str(idx)+'}', instance=idx, related_to_schema_node=node) idx += 1 - self.add_edge(func, new_node) + self.copy_edge((func, node), (func, new_node)) self.remove_edge(func, node) # Remove the original node diff --git a/kadmos/graph/mixin_vistoms.py b/kadmos/graph/mixin_vistoms.py index 4cc521075746ab8e4c7e832791447f98d84a1584..f3021b0878e2be2589909d6e95602abd1122217a 100644 --- a/kadmos/graph/mixin_vistoms.py +++ b/kadmos/graph/mixin_vistoms.py @@ -367,8 +367,6 @@ class VistomsMixin(object): :rtype: dict """ - print(xml_file) - # Start-up self.get_nodes_subcategory() @@ -1098,7 +1096,8 @@ def vistoms_get_graph_info(vistoms_dir): return graph_dict -def get_vistoms_tree_viewer(xml_file, vistoms_dir, use_png_figs=False, file_refs=None): +def get_vistoms_tree_viewer(xml_file, vistoms_dir, use_png_figs=False, file_refs=None, + compress=False, remove_after_compress=False): # Create temporary directory temp_dir = tempfile.mkdtemp() @@ -1181,6 +1180,9 @@ def get_vistoms_tree_viewer(xml_file, vistoms_dir, use_png_figs=False, file_refs # Remove temporary directory shutil.rmtree(temp_dir) + if compress: + _compress_vistoms_instance(vistoms_dir, remove_after_compress) + def _write_json_file(vistoms_dir, data_json): """ Function to write the data.json file and first remove the previous one. diff --git a/kadmos/utilities/xmls.py b/kadmos/utilities/xmls.py index 85504a1db65035fb967e28374cdcb69eb771f0fc..58bd370569fed76cd3883fc27e4f35ad2856be7e 100644 --- a/kadmos/utilities/xmls.py +++ b/kadmos/utilities/xmls.py @@ -242,6 +242,18 @@ class ExtendedElement(etree.ElementBase): return child + def add_multiple(self, camel_case_conversion=False, only_add_if_valued=False, **kwargs): + """Method to add multiple subelements based on keyword arguments. + + :param camel_case_conversion: Option for camel case convention + :type camel_case_conversion: bool + :param only_add_if_valued: Option whether to add elements only when they have a value. + :type camel_case_conversion: bool + """ + for key, value in kwargs.iteritems(): + self.add(key, value, camel_case_conversion=camel_case_conversion, only_add_if_valued=only_add_if_valued) + return + def _add_dictionary(self, tag, dictionary, attrib=None, camel_case_conversion=False, **extra): """Method to add a new sub element to the element based on a dictionary. @@ -295,6 +307,8 @@ class ExtendedElement(etree.ElementBase): if type(item) == tuple: child.add(item[0], item[1], camel_case_conversion=camel_case_conversion) else: + if camel_case_conversion: + tag = unmake_camel_case(tag) child.add(make_singular(tag), item, camel_case_conversion=camel_case_conversion) return child