Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
opensilecs
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
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
s.kupiecki
opensilecs
Commits
d0ac6638
Commit
d0ac6638
authored
2 years ago
by
Nabywaniec
Browse files
Options
Downloads
Patches
Plain Diff
Create silecs design files
parent
baca1712
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
silecs-cli/silecs.py
+72
-6
72 additions, 6 deletions
silecs-cli/silecs.py
with
72 additions
and
6 deletions
silecs-cli/silecs.py
+
72
−
6
View file @
d0ac6638
...
...
@@ -4,22 +4,54 @@ import os
import
sys
from
info
import
__version__
,
__description__
from
lxml
import
etree
import
getpass
SILECS_VERSION
=
"
2.3.0
"
DESIGN_SHEMA_PATH
=
"
../silecs-model/src/xml/DesignSchema.xsd
"
DEPLOY_SHEMA_PATH
=
"
../silecs-model/src/xml/DeploySchema.xsd
"
SILECSDESIGN
=
"
silecsdesign
"
SILECSDEPLOY
=
"
silecsdeploy
"
DESIGN
=
"
design
"
DEPLOY
=
"
deploy
"
USER
=
getpass
.
getuser
()
def
get_extension
(
path
):
return
path
.
split
(
'
.
'
)[
-
1
]
def
get_project_name
(
path
):
return
os
.
path
.
basename
(
path
)
def
get_project_dir
(
path
):
return
os
.
path
.
dirname
(
path
)
def
get_schema_path
(
path
):
extension
=
get_extension
(
path
)
if
extension
==
'
silecsdesign
'
:
if
extension
==
SILECSDESIGN
:
return
DESIGN_SHEMA_PATH
elif
extension
==
'
silecsdeploy
'
:
elif
extension
==
SILECSDEPLOY
:
return
DEPLOY_SHEMA_PATH
else
:
raise
Exception
(
"
Error: Passed file for validation needs to have the extension
'
.silecsdesign
'
or
'
.silecsdeploy
"
)
def
get_silecs_new_file_path
(
path
):
extension
=
get_extension
(
path
)
project_name
=
get_project_name
(
path
)
project_dir
=
get_project_dir
(
path
)
new_file
=
project_name
if
extension
==
DESIGN
:
extension
=
SILECSDESIGN
elif
extension
==
DEPLOY
:
extension
=
SILECSDEPLOY
else
:
raise
Exception
(
"
Error: Passed FESA file needs to have the extension
'
.design
'
or
'
.deploy
'"
)
return
os
.
path
.
join
(
project_dir
,
project_name
+
"
.
"
+
extension
)
def
validate
(
xml_path
,
xsd_path
):
try
:
...
...
@@ -51,13 +83,48 @@ def silecs_validate(file_paths):
print
(
e
)
def
create_silecs_design
(
filepath
):
date
=
datetime
.
today
().
strftime
(
'
%m/%d/%Y
'
)
design_template
=
f
"""
DESIGN_TEMPLATE=
'
<?xml version=
"
1.0
"
encoding=
"
UTF-8
"
?>
<SILECS-Design silecs-version=
"
{
SILECS_VERSION
}
"
created=
"
{
date
}
"
updated=
"
{
date
}
"
xmlns:xsi=
"
http://www.w3.org/2001/XMLSchema-instance
"
xsi:noNamespaceSchemaLocation=
"'
$SCHEMA_PATH
'"
>
<Information>
<Owner user-login=
"
{
USER
}
"
/>
<Editor user-login=
"
{
USER
}
"
/>
</Information>
<SILECS-Class name=
"'
$PROJECT_NAME
'"
version=
"
0.1.0
"
domain=
"
OPERATIONAL
"
>
<Acquisition-Block name=
"
MyBlock
"
generateFesaProperty=
"
true
"
>
<Acquisition-Register name=
"
myRegister
"
generateFesaValueItem=
"
true
"
>
<scalar format=
"
int32
"
/>
</Acquisition-Register>
</Acquisition-Block>
</SILECS-Class>
</SILECS-Design>
"""
def
create
(
filepath
):
extension
=
get_extension
(
filepath
)
def
silecs_create
(
file_paths
):
if
extension
==
SILECSDESIGN
:
create_silecs_design
(
filepath
)
elif
extension
==
SILECSDEPLOY
:
create_silecs_deploy
(
filepath
)
def
silecs_create
(
file_paths
):
for
path
in
file_paths
:
try
:
new_file_path
=
get_silecs_new_file_path
(
path
)
val_result
=
create
(
path
,
xsd_path
)
if
val_result
:
print
(
"
File is valid
"
)
else
:
print
(
"
File is not valid. Check errors above.
"
)
except
Exception
as
e
:
print
(
e
)
def
_parse_arguments
():
parser
=
argparse
.
ArgumentParser
(
...
...
@@ -107,9 +174,8 @@ def run():
except
:
sys
.
exit
(
0
)
if
options
.
create
:
silecs_
valid
ate
(
options
.
create
)
silecs_
cre
ate
(
options
.
create
)
if
options
.
validate
:
silecs_validate
(
options
.
validate
)
if
options
.
generate
:
...
...
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