Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F87944330
main.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Tue, Oct 15, 21:51
Size
5 KB
Mime Type
text/x-python
Expires
Thu, Oct 17, 21:51 (2 d)
Engine
blob
Format
Raw Data
Handle
21687715
Attached To
rLIBMULTISCALE LibMultiScale
main.py
View Options
#!/usr/bin/env python3
import
sys
import
re
import
pylibmultiscale
as
lm
import
pyparsing
as
pp
from
libmultiscale_doc_parser
import
LibMultiScaleParser
################################################################
def
LMDocData
():
return
{
'name'
:
None
,
'type'
:
None
,
'description'
:
None
,
'children'
:
[],
'var_name'
:
None
,
'c_type'
:
None
,
'filename'
:
None
,
'heritance'
:
None
,
'example'
:
None
,
'defaults'
:
None
}
class
LMDataNode
(
object
):
def
__init__
(
self
):
self
.
name
=
None
self
.
children
=
[]
self
.
data
=
[]
################################################################
def
readListOfSourceFiles
(
fname
):
_f
=
open
(
fname
)
list_files
=
[]
for
line
in
_f
.
readlines
():
fname
=
line
.
strip
()
if
(
line
==
""
):
continue
_str
=
open
(
fname
)
.
read
()
m
=
re
.
search
(
r'.*(declareParams\(\))\s+(\{).*'
,
_str
)
if
not
m
:
continue
source_file
=
fname
list_files
.
append
(
source_file
)
return
list_files
################################################################
def
addDoc
(
root
,
doc
,
_file
):
# path:: iterator end = file.end()
# path:: iterator begin = file.begin()
#
# - -end
#
# for (
# end != begin
# - -end) {
# if (end -> native() == "src"){
# ++end
# break
# }
# }
# if (end == file.end()){
# std:: cerr << "problem in the file structure" << std: : endl
# exit(EXIT_FAILURE)
# }
#
# begin = end
# end = file.end()
# LMDataNode * it = &root
# for (
# begin != end
# + +begin) {
# std:: string sublevel = begin -> native()
# it = &(it -> children[sublevel])
# it -> name = sublevel
# }
# it -> data.push_back(doc)
pass
################################################################
def
addDocByName
(
sorted_by_name
,
doc
,
_file
):
# std: : string short_name = file.stem().native()
# // std: : cerr << "record heritance " << short_name << std: : endl
# sorted_by_name[protectString(short_name)] = doc
pass
################################################################
def
protectUnderscoreInDoc
(
doc
):
# doc.name = protectString(doc.name)
# doc.type = protectString(doc.type)
# doc.var_name = protectString(doc.var_name)
# doc.defaults = protectString(doc.defaults)
# doc.c_type = protectString(doc.c_type)
# doc.example = protectString(doc.example)
# for (UInt i=0
# i < doc.heritance.size()
# + +i) {
# doc.heritance[i] = protectString(doc.heritance[i])
# }
# for (UInt i=0
# i < doc.children.size()
# + +i)
# protectUnderscoreInDoc(doc.children[i])
pass
################################################################
def
generatorInternalKeyWordList
():
return
[
'DomainDD'
,
'DomainAtomic'
,
'DomainContinuum'
,
'ActionInterface'
,
'DomainInterface'
,
'Dumper'
,
'ComposedGeom'
,
'CouplerManager'
,
'DofAssociation'
,
'Bridging'
,
'Geometry'
,
'ArlequinTemplate'
,
'PointAssociation'
,
'LAMMPS_BASE'
,
'AKANTU_BASE'
,
'AKANTU_DYNAMIC'
,
'AKANTU_STATIC'
,
'FILTER'
]
################################################################
def
checkKeywordExistance
(
key
,
key_list
,
internal_key_list
):
if
(
key
not
in
key_list
)
and
(
key
not
in
internal_key_list
):
print
(
"Warning:Undeclared "
+
key
+
": keywords are "
+
', '
.
join
(
key_list
))
return
elif
key
in
key_list
:
key_list
[
key
]
.
pop
()
if
not
key_list
[
key
]:
del
key_list
[
key
]
print
(
"removing key"
)
print
(
''
)
################################################################
def
main
():
p
=
sys
.
argv
[
1
]
files
=
readListOfSourceFiles
(
p
)
key_list
=
lm
.
getKeyWordList
()
internal_key_list
=
generatorInternalKeyWordList
()
parser
=
LibMultiScaleParser
()
root
=
LMDataNode
()
sorted_by_name
=
{}
for
fname
in
files
:
res_doc
=
LMDocData
()
res_doc
[
'filename'
]
=
fname
print
(
"parsing "
+
res_doc
[
'filename'
])
try
:
res
=
parser
.
parse
(
fname
,
internal_key_list
)
for
k
,
v
in
res
.
items
():
print
(
f
'{k}:{v}'
)
res_doc
[
'name'
]
=
res
[
'description'
][
0
]
res_doc
[
'description'
]
=
res
[
'description'
][
1
]
if
'example'
in
res
:
res_doc
[
'example'
]
=
res
[
'example'
]
print
(
res_doc
)
checkKeywordExistance
(
res_doc
[
'name'
],
key_list
,
internal_key_list
)
protectUnderscoreInDoc
(
res
)
for
child
in
res_doc
[
'children'
]:
child
.
filename
=
res
.
filename
protectUnderscoreInDoc
(
res_doc
)
addDoc
(
root
,
res
,
fname
)
addDocByName
(
sorted_by_name
,
res
,
fname
)
except
pp
.
ParseException
as
e
:
print
(
e
,
dir
(
e
))
print
(
f
'{res_doc["filename"]}:{e.lineno}:{e.col}:{e}'
)
except
pp
.
ParseSyntaxException
as
e
:
print
(
e
,
dir
(
e
))
print
(
f
'{res_doc["filename"]}:{e.lineno}:{e.col}:{e}'
)
for
k
,
v
in
key_list
.
items
():
print
(
"Warning: keyword "
+
k
+
" was not documented "
)
fout
=
open
(
"manual-generated.tex"
)
ltx
=
GenerateLatex
()
ltx
.
generateLatex
(
fout
,
root
,
sorted_by_name
)
################################################################
if
__name__
==
"__main__"
:
main
()
Event Timeline
Log In to Comment