10
0
mirror of https://github.com/LCPQ/quantum_package synced 2024-07-03 09:55:59 +02:00

Cleaning ezfio_generate_ocaml

This commit is contained in:
Thomas Applencourt 2015-03-27 11:15:55 +01:00
parent 7db2751cdb
commit 5845768b31
2 changed files with 38 additions and 25 deletions

View File

@ -422,11 +422,8 @@ def create_ocaml_check(dict_ezfio_cfg):
from ezfio_generate_ocaml import EZFIO_ocaml from ezfio_generate_ocaml import EZFIO_ocaml
e = EZFIO_ocaml()
for provider_name, d_val in sorted(dict_ezfio_cfg.iteritems()): for provider_name, d_val in sorted(dict_ezfio_cfg.iteritems()):
ocaml_type = d_val["type"].ocaml.capitalize()
ezfio_dir = d_val["ezfio_dir"] ezfio_dir = d_val["ezfio_dir"]
ezfio_name = d_val["ezfio_name"] ezfio_name = d_val["ezfio_name"]
@ -434,7 +431,9 @@ def create_ocaml_check(dict_ezfio_cfg):
"ezfio_name": ezfio_name, "ezfio_name": ezfio_name,
"type": d_val["type"]} "type": d_val["type"]}
template = e.create_read(**d) e = EZFIO_ocaml(**d)
template = e.create_read()
print template print template

View File

@ -5,10 +5,23 @@ import sys
class EZFIO_ocaml(object): class EZFIO_ocaml(object):
def __init__(self): def __init__(self, **kwargs):
pass
def create_read(self, **param): for k, v in kwargs.iteritems():
if k == "type":
self.type = kwargs["type"]
else:
exec "self.{0} = '{1}'".format(k, v)
@property
def Ocaml_type(self):
return self.type.ocaml.capitalize()
@property
def fancy_type(self):
return self.type.fancy
def create_read(self):
''' '''
Take an imput a list of keyword argument Take an imput a list of keyword argument
ezfio_dir = str ezfio_dir = str
@ -18,28 +31,28 @@ class EZFIO_ocaml(object):
Return the read template Return the read template
''' '''
l_name_need = "ezfio_dir ezfio_name type".split() for i in ["ezfio_dir", "ezfio_name", "type"]:
try:
for key in l_name_need: "exec self.{0}".format(i)
if key not in param: except NameError:
print "You need to provide {0} at keyword argument".format(key) msg = "You need to provide a '{0}' for creating read function"
sys.exit(1) raise KeyError(msg.format(i))
# ~#~#~#~#~#~#~#~#~#~#~#~#~#~# # # ~#~#~#~#~#~#~#~#~#~#~#~#~#~# #
# C r e a t e _ t e m pl a t e # # C r e a t e _ t e m pl a t e #
# ~#~#~#~#~#~#~#~#~#~#~#~#~#~# # # ~#~#~#~#~#~#~#~#~#~#~#~#~#~# #
l_template = ['(* Read snippet for {ezfio_name} *)', l_template = ['(* Read snippet for {self.ezfio_name} *)',
'let read_{ezfio_name} () =', 'let read_{self.ezfio_name} () =',
' if not (Ezfio.has_{ezfio_dir}_{ezfio_name} ()) then', ' if not (Ezfio.has_{self.ezfio_dir}_{self.ezfio_name} ()) then',
' get_default "{ezfio_name}"', ' get_default "{self.ezfio_name}"',
' |> {Ocaml_type}.of_string', ' |> {self.Ocaml_type}.of_string',
' |> Ezfio.set_{ezfio_dir}_{ezfio_name}', ' |> Ezfio.set_{self.ezfio_dir}_{self.ezfio_name}',
' ;', ' ;',
' Ezfio.get_{ezfio_dir}_{ezfio_name} ()'] ' Ezfio.get_{self.ezfio_dir}_{self.ezfio_name} ()']
if param["type"].fancy: if self.fancy_type:
l_template += [" |> {fancy_type}.of_{Ocaml_type}"] l_template += [" |> {self.fancy_type}.of_{self.Ocaml_type}"]
l_template += [";;;"] l_template += [";;;"]
@ -49,11 +62,12 @@ class EZFIO_ocaml(object):
# R e n d e r # # R e n d e r #
# ~#~#~#~#~#~ # # ~#~#~#~#~#~ #
param["Ocaml_type"] = param["type"].ocaml.capitalize() template_rendered = template.format(**locals())
param["fancy_type"] = param["type"].fancy
template_rendered = template.format(**param)
# ~#~#~#~#~#~ # # ~#~#~#~#~#~ #
# R e t u r n # # R e t u r n #
# ~#~#~#~#~#~ # # ~#~#~#~#~#~ #
return template_rendered return template_rendered
def create_write(self):
pass