예제 #1
0
def create_ocaml_input_global(l_module_with_auto_generate_ocaml_lower):
    """
    Create the Input_auto_generated.ml and qp_edit.ml str
    """

    # ~#~#~#~#~#~#~#~# #
    #  C r e a t i o n #
    # ~#~#~#~#~#~#~#~# #

    from ezfio_generate_ocaml import EZFIO_ocaml

    path = QP_ROOT + "/scripts/ezfio_interface/qp_edit_template"

    with open(path, "r") as f:
        template_raw = f.read()

    e = EZFIO_ocaml(l_module_lower=l_module_with_auto_generate_ocaml_lower)

    template = template_raw.format(
        keywords=e.create_qp_keywords(),
        keywords_to_string=e.create_qp_keywords_to_string(),
        section_to_rst=e.create_qp_section_to_rst(),
        write=e.create_qp_write(),
        tasks=e.create_qp_tasks())

    input_auto = e.create_input_auto_generated()

    return (template, input_auto)
예제 #2
0
def create_ocaml_input_global(l_module_with_auto_generate_ocaml_lower):
    """
    Create the Input_auto_generated.ml and qp_edit.ml str
    """

    # ~#~#~#~#~#~#~#~# #
    #  C r e a t i o n #
    # ~#~#~#~#~#~#~#~# #

    from ezfio_generate_ocaml import EZFIO_ocaml

    path = QP_ROOT + "/scripts/ezfio_interface/qp_edit_template"

    with open(path, "r") as f:
        template_raw = f.read()

    e = EZFIO_ocaml(l_module_lower=l_module_with_auto_generate_ocaml_lower)

    template = template_raw.format(keywords=e.create_qp_keywords(),
                                   keywords_to_string=e.create_qp_keywords_to_string(),
                                   section_to_rst=e.create_qp_section_to_rst(),
                                   write=e.create_qp_write(),
                                   tasks=e.create_qp_tasks())

    input_auto = e.create_input_auto_generated()

    return (template, input_auto)
예제 #3
0
def create_ocaml_input_global():
    """
    Check for all the EZFIO.cfg get the module lower
    then create incule {module_lower}.ml
    """

    # ~#~#~#~# #
    #  I n i t #
    # ~#~#~#~# #

    l_module_lower = get_l_module_lower()

    # ~#~#~#~#~#~#~#~# #
    #  C r e a t i o n #
    # ~#~#~#~#~#~#~#~# #

    from ezfio_generate_ocaml import EZFIO_ocaml

    qpackage_root = os.environ['QPACKAGE_ROOT']
    path = qpackage_root + "/scripts/ezfio_interface/qp_edit_template"

    with open(path, "r") as f:
        template_raw = f.read()

    e = EZFIO_ocaml(l_module_lower=l_module_lower)

    template = template_raw.format(keywords=e.create_qp_keywords(),
                                   keywords_to_string=e.create_qp_keywords_to_string(),
                                   section_to_rst=e.create_qp_section_to_rst(),
                                   write=e.create_qp_write(),
                                   tasks=e.create_qp_tasks())

    input_auto = e.create_input_auto_generated()

    return (template, input_auto)
예제 #4
0
def create_ocaml_input(dict_ezfio_cfg, module_lower):

    # ~#~#~#~# #
    #  I n i t #
    # ~#~#~#~# #

    from ezfio_generate_ocaml import EZFIO_ocaml

    l_ezfio_name = []
    l_type = []
    l_doc = []

    for k, v in dict_ezfio_cfg.iteritems():
        if "ocaml" in v['interface']:
            l_ezfio_name.append(v['ezfio_name'])
            l_type.append(v["type"])
            l_doc.append(v["doc"])

    if not l_ezfio_name:
        raise ValueError

    e_glob = EZFIO_ocaml(l_ezfio_name=l_ezfio_name, l_type=l_type, l_doc=l_doc)

    # ~#~#~#~#~#~#~#~# #
    #  C r e a t i o n #
    # ~#~#~#~#~#~#~#~# #

    template = ['(* =~=~ *)', '(* Init *)', '(* =~=~ *)', ""]

    template += [
        "open Qptypes;;", "open Qputils;;", "open Core;;", "",
        "module {0} : sig".format(module_lower.capitalize())
    ]

    template += [e_glob.create_type()]

    template += [
        "  val read  : unit -> t option", "  val write : t-> unit",
        "  val to_string : t -> string", "  val to_rst : t -> Rst_string.t",
        "  val of_rst : Rst_string.t -> t option", "end = struct"
    ]

    template += [e_glob.create_type()]

    template += [
        '', '  let get_default = Qpackage.get_ezfio_default "{0}";;'.format(
            module_lower), ''
    ]

    template += [
        '(* =~=~=~=~=~=~==~=~=~=~=~=~ *)', '(* Generate Special Function *)',
        '(* =~=~=~==~=~~=~=~=~=~=~=~=~ *)', ""
    ]

    for provider_name, d_val in sorted(dict_ezfio_cfg.iteritems()):

        if 'default' not in d_val:
            continue

        ezfio_dir = d_val["ezfio_dir"]
        ezfio_name = d_val["ezfio_name"]

        e = EZFIO_ocaml(ezfio_dir=ezfio_dir,
                        ezfio_name=ezfio_name,
                        type=d_val["type"])

        template += [e.create_read(), e.create_write(), ""]

    template += [
        '(* =~=~=~=~=~=~=~=~=~=~=~=~ *)', '(* Generate Global Function *)',
        '(* =~=~=~=~=~=~=~=~=~=~=~=~ *)', ""
    ]

    template += [
        e_glob.create_read_global(),
        e_glob.create_write_global(),
        e_glob.create_to_string(),
        e_glob.create_to_rst()
    ]

    template += [
        "  include Generic_input_of_rst;;",
        "  let of_rst = of_rst t_of_sexp;;", "", "end"
    ]

    return "\n".join(template)
예제 #5
0
def create_ocaml_input(dict_ezfio_cfg, module_lower):

    # ~#~#~#~# #
    #  I n i t #
    # ~#~#~#~# #

    from ezfio_generate_ocaml import EZFIO_ocaml

    l_ezfio_name = []
    l_type = []
    l_doc = []

    for k, v in dict_ezfio_cfg.iteritems():
        if "ocaml" in v['interface']:
            l_ezfio_name.append(v['ezfio_name'])
            l_type.append(v["type"])
            l_doc.append(v["doc"])

    if not l_ezfio_name:
        raise ValueError

    e_glob = EZFIO_ocaml(l_ezfio_name=l_ezfio_name,
                         l_type=l_type,
                         l_doc=l_doc)

    # ~#~#~#~#~#~#~#~# #
    #  C r e a t i o n #
    # ~#~#~#~#~#~#~#~# #

    template = ['(* =~=~ *)',
                '(* Init *)',
                '(* =~=~ *)',
                ""]

    template += ["open Qptypes;;",
                 "open Qputils;;",
                 "open Core.Std;;",
                 "",
                 "module {0} : sig".format(module_lower.capitalize())]

    template += [e_glob.create_type()]

    template += ["  val read  : unit -> t option",
                 "  val write : t-> unit",
                 "  val to_string : t -> string",
                 "  val to_rst : t -> Rst_string.t",
                 "  val of_rst : Rst_string.t -> t option",
                 "end = struct"]

    template += [e_glob.create_type()]

    template += ['',
                 '  let get_default = Qpackage.get_ezfio_default "{0}";;'.format(module_lower),
                 '']

    template += ['(* =~=~=~=~=~=~==~=~=~=~=~=~ *)',
                 '(* Generate Special Function *)',
                 '(* =~=~=~==~=~~=~=~=~=~=~=~=~ *)',
                 ""]

    for provider_name, d_val in sorted(dict_ezfio_cfg.iteritems()):

        if 'default' not in d_val:
            continue

        ezfio_dir = d_val["ezfio_dir"]
        ezfio_name = d_val["ezfio_name"]

        e = EZFIO_ocaml(ezfio_dir=ezfio_dir,
                        ezfio_name=ezfio_name,
                        type=d_val["type"])

        template += [e.create_read(),
                     e.create_write(),
                     ""]

    template += ['(* =~=~=~=~=~=~=~=~=~=~=~=~ *)',
                 '(* Generate Global Function *)',
                 '(* =~=~=~=~=~=~=~=~=~=~=~=~ *)',
                 ""]

    template += [e_glob.create_read_global(),
                 e_glob.create_write_global(),
                 e_glob.create_to_string(),
                 e_glob.create_to_rst()]

    template += ["  include Generic_input_of_rst;;",
                 "  let of_rst = of_rst t_of_sexp;;",
                 "",
                 "end"]

    return "\n".join(template)