Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Gino Tosti
pygen
Commits
b06e557a
Commit
b06e557a
authored
Jul 02, 2021
by
Gino Tosti
Browse files
code cleaning
parent
1d8ad749
Changes
1
Hide whitespace changes
Inline
Side-by-side
test/genDevice.py
View file @
b06e557a
...
@@ -13,7 +13,7 @@ from GenDevice.acsUtils import *
...
@@ -13,7 +13,7 @@ from GenDevice.acsUtils import *
import
pandas
as
pd
import
pandas
as
pd
import
glob
import
glob
outdir
=
"/tmp/"
OUTDIR
=
"/tmp/"
gendir
=
os
.
environ
[
"PYGEN"
]
gendir
=
os
.
environ
[
"PYGEN"
]
if
gendir
==
""
:
if
gendir
==
""
:
...
@@ -22,39 +22,36 @@ if gendir=="":
...
@@ -22,39 +22,36 @@ if gendir=="":
if
not
checkACS
():
if
not
checkACS
():
print
(
"ACS Enviroment is not set"
)
print
(
"ACS Enviroment is not set"
)
exit
()
exit
()
def
generateComponent
(
config
,
install
=
False
):
def
generateComponent
(
config
):
pwd
=
os
.
getcwd
()
pwd
=
os
.
getcwd
()
wb
=
excelIcd
(
config
[
'icdfile'
])
wb
=
excelIcd
(
config
[
'icdfile'
])
smain
=
wb
.
book
.
parse
(
"Main"
)
devs
=
wb
.
MainSheet
[
'Device Name'
]
devs
=
smain
[
'Device Name'
]
#comp=smain['Component Name']
assembly
=
smain
[
'Assembly'
]
#outfile=[]
if
len
(
devs
)
>
1
:
if
len
(
devs
)
>
1
:
print
(
"the Assembly:"
+
assembly
[
0
]
+
" includes more than one device
\n
"
,
devs
)
print
(
"The Assembly:"
+
wb
.
MainSheet
[
'Assembly'
][
0
]
+
" includes more than one device
\n
"
,
devs
)
for
dev
in
devs
:
genMulti
(
wb
,
config
)
print
(
"working On device:"
,
dev
)
outf
=
manageICDFiles
(
dev
,
outdir
,
wb
)
#outfile.append(outf)
print
(
"Working on files:"
,
dev
)
wb1
=
excelIcd
(
outf
)
mygen
=
genFromTemplates
(
wb1
,
outf
,
config
[
'prefix'
],
config
[
'module'
],
config
[
'basedir'
])
mygen
.
generateFileInDir
()
if
install
:
build
(
mygen
)
removetmpfiles
()
else
:
else
:
print
(
"the Assembly:"
+
assembly
[
0
]
+
" includes one device
\n
"
,
devs
)
print
(
"The Assembly:"
+
wb
.
MainSheet
[
'Assembly'
][
0
]
+
" includes one device
\n
"
,
devs
)
#outf=manageICDFiles(devs[0],outdir,wb)
genSingle
(
wb
,
config
)
mygen
=
genFromTemplates
(
wb
,
config
[
'icdfile'
],
config
[
'prefix'
],
config
[
'module'
],
config
[
'basedir'
])
mygen
.
generateFileInDir
()
checkCDB
(
mygen
)
if
install
:
build
(
mygen
)
checkCDB
(
mygen
)
os
.
chdir
(
pwd
)
os
.
chdir
(
pwd
)
def
genMulti
(
wb
,
config
):
for
dev
in
wb
.
MainSheet
[
'Device Name'
]:
print
(
"working On device:"
,
dev
)
outf
=
manageICDFiles
(
dev
,
OUTDIR
,
wb
)
print
(
"Working on files:"
,
outf
)
wb1
=
excelIcd
(
outf
)
config
[
'icdfile'
]
=
outf
genSingle
(
wb1
,
config
)
removetmpfiles
()
def
genSingle
(
wb
,
config
):
mygen
=
genFromTemplates
(
wb
,
config
[
'icdfile'
],
config
[
'prefix'
],
config
[
'module'
],
config
[
'basedir'
])
mygen
.
generateFileInDir
()
if
config
[
'install'
]
:
build
(
mygen
)
checkCDB
(
mygen
)
def
manageICDFiles
(
dev
,
outdir
,
wb
):
def
manageICDFiles
(
dev
,
outdir
,
wb
):
query
=
"`Device Name` =="
+
"'"
+
dev
+
"'"
query
=
"`Device Name` =="
+
"'"
+
dev
+
"'"
main
=
(
wb
.
book
.
parse
(
"Main"
)).
query
(
query
)
main
=
(
wb
.
book
.
parse
(
"Main"
)).
query
(
query
)
...
@@ -103,17 +100,15 @@ def checkCDB(mygen):
...
@@ -103,17 +100,15 @@ def checkCDB(mygen):
def
removetmpfiles
():
def
removetmpfiles
():
filelist
=
glob
.
glob
(
outdir
+
'*.xlsx'
)
filelist
=
glob
.
glob
(
OUTDIR
+
'*.xlsx'
)
for
fil
in
filelist
:
for
fil
in
filelist
:
try
:
try
:
os
.
remove
(
fil
)
os
.
remove
(
fil
)
except
OSError
as
e
:
except
OSError
as
e
:
print
(
"Error: %s - %s."
%
(
e
.
filename
,
e
.
strerror
))
print
(
"Error: %s - %s."
%
(
e
.
filename
,
e
.
strerror
))
if
__name__
==
"__main__"
:
def
getInput
()
:
parser
=
OptionParser
()
parser
=
OptionParser
()
today
=
date
.
today
()
pwd
=
os
.
getcwd
()
parser
.
add_option
(
"-f"
,
"--file"
,
dest
=
"bookfile"
,
parser
.
add_option
(
"-f"
,
"--file"
,
dest
=
"bookfile"
,
help
=
"ICD Exel File "
,
metavar
=
"FILE"
)
help
=
"ICD Exel File "
,
metavar
=
"FILE"
)
parser
.
add_option
(
"-d"
,
"--dir"
,
dest
=
"basedir"
,
default
=
"./tmp"
,
parser
.
add_option
(
"-d"
,
"--dir"
,
dest
=
"basedir"
,
default
=
"./tmp"
,
...
@@ -125,13 +120,19 @@ if __name__ =="__main__":
...
@@ -125,13 +120,19 @@ if __name__ =="__main__":
parser
.
add_option
(
"-i"
,
"--install"
,
dest
=
"install"
,
default
=
False
,
parser
.
add_option
(
"-i"
,
"--install"
,
dest
=
"install"
,
default
=
False
,
help
=
"execute the Makefile in src dir "
,
metavar
=
"INSTALL"
)
help
=
"execute the Makefile in src dir "
,
metavar
=
"INSTALL"
)
(
options
,
args
)
=
parser
.
parse_args
()
(
options
,
args
)
=
parser
.
parse_args
()
print
(
"running genDevice with the following options:
\n
"
,
options
)
#
print("running genDevice with the following options:\n", options)
config
=
{}
config
=
{}
config
[
'icdfile'
]
=
options
.
bookfile
config
[
'icdfile'
]
=
options
.
bookfile
config
[
'prefix'
]
=
options
.
prefix
config
[
'prefix'
]
=
options
.
prefix
config
[
'module'
]
=
options
.
module
config
[
'module'
]
=
options
.
module
config
[
'basedir'
]
=
options
.
basedir
config
[
'basedir'
]
=
options
.
basedir
generateComponent
(
config
,
install
=
options
.
install
)
config
[
'install'
]
=
options
.
install
return
config
if
__name__
==
"__main__"
:
pwd
=
os
.
getcwd
()
config
=
getInput
()
generateComponent
(
config
)
print
(
"ALL Done"
)
print
(
"ALL Done"
)
os
.
chdir
(
pwd
)
os
.
chdir
(
pwd
)
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment