mirror of
https://github.com/LCPQ/quantum_package
synced 2024-11-04 21:24:02 +01:00
137 lines
3.6 KiB
Python
Executable File
137 lines
3.6 KiB
Python
Executable File
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
|
|
import ConfigParser
|
|
from collections import defaultdict
|
|
|
|
def create_dic_fancy_type():
|
|
fancy_type = defaultdict(dict)
|
|
|
|
ocaml_to_fortran = {"int": "integer",
|
|
"float": "double precision",
|
|
"logical": "logical",
|
|
"string": "character*60"}
|
|
|
|
fancy_type['integer'] = {
|
|
"ocaml": "int",
|
|
"fortran": "integer"}
|
|
|
|
fancy_type['double precision'] = {
|
|
"ocaml": "float",
|
|
"fortran": "double precision"}
|
|
fancy_type['logical'] = {
|
|
"ocaml": "logical",
|
|
"fortran": "logical"}
|
|
|
|
src = os.environ.get('QPACKAGE_ROOT') + "/ocaml/qptypes_generator.ml"
|
|
|
|
with open(src, "r") as f:
|
|
l = f.read().splitlines()
|
|
|
|
l = [i for i in l if i.strip().startswith("*")]
|
|
|
|
for i in l:
|
|
ocaml_fancy_type = i.split()[1].strip()
|
|
ocaml_type = i.split()[3]
|
|
fortran_type = ocaml_to_fortran[ocaml_type]
|
|
|
|
fancy_type[ocaml_fancy_type] = {"ocaml": ocaml_type,
|
|
"fortran": fortran_type}
|
|
|
|
return dict(fancy_type)
|
|
|
|
import sys
|
|
|
|
|
|
def dict_config_file(config_file, dic_type):
|
|
d = defaultdict(dict)
|
|
list_key = ["doc", "ezfio_name", "ezfio_dir", "ezfio_default_value"]
|
|
|
|
provider_names = config_file.sections()
|
|
for provider_name in provider_names:
|
|
|
|
if config_file.get(provider_name, "type") not in dic_type:
|
|
print config_file.get(provider_name, "type"), "not avalaible"
|
|
sys.exit(1)
|
|
|
|
for k in list_key:
|
|
d[provider_name][k] = config_file.get(provider_name, k)
|
|
|
|
type_raw = config_file.get(provider_name, "type")
|
|
d[provider_name]["ezfio_type"] = dic_type[type_raw]["fortran"]
|
|
d[provider_name]["ocaml_type"] = dic_type[type_raw]["ocaml"]
|
|
|
|
return dict(d)
|
|
|
|
|
|
def create_ezfio_string(dict_all, t):
|
|
a = {"config": "ezfio_type",
|
|
"default": "ezfio_default_value"}
|
|
|
|
info = a[t]
|
|
d = defaultdict(list)
|
|
|
|
for provider_name, dict_info in dict_all.items():
|
|
l_to_join = [" ", dict_info['ezfio_name'], dict_info[info], "\n"]
|
|
d[dict_info['ezfio_dir']].append(l_to_join)
|
|
|
|
# Only for fun,sry reader...
|
|
return [" ".join([k, "\n"] + [j for i in v for j in i])
|
|
for k, v in d.items()]
|
|
|
|
|
|
def create_ezfio_provider(dict_all):
|
|
from ezfio_with_default import EZFIO_Provider
|
|
lp = []
|
|
|
|
T = EZFIO_Provider()
|
|
for provider_name, dict_info in dict_all.items():
|
|
T.set_type(dict_info['ezfio_type'])
|
|
T.set_name(provider_name)
|
|
T.set_doc(dict_info['doc'])
|
|
T.set_ezfio_dir(dict_info['ezfio_dir'])
|
|
T.set_ezfio_name(dict_info['ezfio_name'])
|
|
T.set_default(dict_info['ezfio_default_value'])
|
|
|
|
T.set_output("output_%s" % dict_info['ezfio_dir'])
|
|
lp.append(str(T))
|
|
|
|
return lp
|
|
|
|
import os
|
|
|
|
def get_dict_cgf():
|
|
|
|
dict_cfg = {}
|
|
fancy_type = create_dic_fancy_type()
|
|
|
|
src = os.environ.get('QPACKAGE_ROOT') + "/src/"
|
|
|
|
for root, dirs, files in os.walk(src, topdown=False):
|
|
|
|
for name in dirs:
|
|
|
|
path_config_folder = src + name
|
|
config = ConfigParser.ConfigParser()
|
|
|
|
try:
|
|
config.readfp(open(path_config_folder + '/EZFIO.cfg'))
|
|
except Exception as inst:
|
|
pass
|
|
else:
|
|
dict_cfg.update(dict_config_file(config, fancy_type))
|
|
|
|
return dict_cfg
|
|
|
|
if __name__ == "__main__":
|
|
src = os.environ.get('QPACKAGE_ROOT') + "/src/"
|
|
|
|
roger = get_dict_cgf()
|
|
print roger
|
|
|
|
for i in create_ezfio_string(roger, "config"):
|
|
print i
|
|
|
|
for i in create_ezfio_string(roger, "default"):
|
|
print i
|