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
nomad-lab
parser-siesta
Commits
6677991a
Commit
6677991a
authored
Jul 06, 2016
by
Ask Hjorth Larsen
Browse files
add script to autogenerate json
parent
778ee19e
Changes
1
Hide whitespace changes
Inline
Side-by-side
parser/parser-siesta/mkjson.py
0 → 100644
View file @
6677991a
from
__future__
import
print_function
# TEMPLATES TAKEN FROM OCTOPUS. KEEP SYNCHRONIZED.
json_header
=
"""{
"type": "nomad_meta_info_1_0",
"description": "autogenerated nomad meta info for %(parser)s parser. The file which generates this maintained in the parser's git repository.",
"dependencies": [ {
"relativePath": "common.nomadmetainfo.json"
}],
"metaInfos": [ %(info)s]
}"""
json_template
=
"""{
"description": "%(description)s",
"dtypeStr": "%(dtypeStr)s",
"name": "%(name)s",
"repeats": false,
"shape": [],
"superNames": [
"%(supername)s"
]
}"""
json_section_template
=
"""{
"description": "%(description)s",
"kindStr": "type_abstract_document_content",
"name": "%(name)s",
"superNames": [
"section_run"
]
}"""
# END OF TEMPLATES FROM OCTOPUS
import
sys
fname
=
sys
.
argv
[
1
]
with
open
(
fname
)
as
fd
:
varnames
=
[]
for
line
in
fd
:
if
not
line
[:
1
].
isalpha
():
# Get rid of blocks
continue
# Get rid of comments
line
=
line
.
strip
().
rsplit
(
'#'
,
1
)[
0
]
varname
=
line
.
split
()[
0
]
varnames
.
append
(
varname
)
varnames
=
list
(
set
(
varnames
))
varnames
.
sort
()
jsontokens
=
[]
for
var
in
varnames
:
json
=
json_template
%
dict
(
description
=
r
'siesta input variable \"%s\"'
%
var
,
name
=
'x_siesta_input_%s'
%
var
,
dtypeStr
=
'C'
,
supername
=
'x_siesta_input'
)
jsontokens
.
append
(
json
)
section
=
json_section_template
%
dict
(
description
=
'siesta input '
'variables'
,
name
=
'x_siesta_input'
)
jsontokens
.
append
(
section
)
txt
=
json_header
%
dict
(
parser
=
'siesta'
,
info
=
', '
.
join
(
jsontokens
))
print
(
txt
)
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