Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
KADMOS
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
LR-FPP-MDO
KADMOS
Commits
0f5729d0
Commit
0f5729d0
authored
6 years ago
by
imcovangent
Browse files
Options
Downloads
Patches
Plain Diff
Added method find_cmdows_file( file_list ) to be used by interactive VISTOMS.
Former-commit-id: e8ef2914a244e1ef501e462c758174f7aa5a6836
parent
efc491ea
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Pipeline
#192794
canceled
1 year ago
Stage: build
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
kadmos/cmdows/cmdows.py
+40
-0
40 additions, 0 deletions
kadmos/cmdows/cmdows.py
with
40 additions
and
0 deletions
kadmos/cmdows/cmdows.py
+
40
−
0
View file @
0f5729d0
...
...
@@ -771,6 +771,46 @@ class CMDOWS(object):
ElementTree
(
self
.
root
).
write
(
file_path
,
pretty_print
=
pretty_print
,
method
=
method
,
xml_declaration
=
xml_declaration
,
encoding
=
encoding
)
# ----------------------------------------- #
# Static functions #
# ----------------------------------------- #
def
find_cmdows_file
(
file_list
):
"""
Function to find the CMDOWS file among a list of files.
:param file_list: list with file names to be checked for being a CMDOWS file
:type file_list: list
:return: name of the CMDOWS file in the list
:rtype: basestring
"""
# Input assertions
assert
isinstance
(
file_list
,
list
),
'
File list should be a list, not it is of type {}.
'
.
format
(
type
(
file_list
))
for
file_name
in
file_list
:
assert
os
.
path
.
isfile
(
file_name
),
'
Item {} in file_list does not appear to be a file.
'
.
format
(
file_name
)
# Loop through the list and check first for XML extension
xml_files
=
[
file_name
for
file_name
in
file_list
if
file_name
.
endswith
(
'
.xml
'
)]
# Loop through the xml_files and check which ones have the root CMDOWS
cmdows_files
=
[]
for
xml_file
in
xml_files
:
try
:
xml_root
=
etree
.
parse
(
xml_file
,
parser
).
getroot
()
if
xml_root
.
tag
==
'
cmdows
'
:
cmdows_files
.
append
(
xml_file
)
except
:
logger
.
warning
(
'
Could not parse XML file {} for some reason.
'
.
format
(
xml_file
))
# Check the results and return the right message
if
not
cmdows_files
:
raise
AssertionError
(
'
Could not find a CMDOWS file in the list of files.
'
)
elif
len
(
cmdows_files
)
==
1
:
return
cmdows_files
[
0
]
elif
len
(
cmdows_files
)
>
1
:
raise
AssertionError
(
'
Multiple CMDOWS files were found {} in the list of files.
'
.
format
(
cmdows_files
))
# Set element on the module level
parser
.
set_element_class_lookup
(
etree
.
ElementDefaultClassLookup
(
element
=
ExtendedElement
))
Element
=
parser
.
makeelement
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment