diff --git a/hshetl/editor.py b/hshetl/editor.py deleted file mode 100644 index 42415c1ede6787bbda8bb98c64114faacd6c8e63..0000000000000000000000000000000000000000 --- a/hshetl/editor.py +++ /dev/null @@ -1,185 +0,0 @@ -from __future__ import print_function -import hshetl -import yaml -import json -import re -from hshetl.exc import * - - -config = { - "TYPE_MAPPING": { - "string" : "!!str", - "unicode" : "!!str", - "int" : "!!int", - "bool" : "!!bool", - "boolean" : "!!bool", - "list" : "!!list", - "dict" : "!!map" - }, - "TYPE_DISPLAY_MAPPING": { - "!!str" : "textfield", - "!!int" : "textfield", - "!!bool" : "checkbox", - "!!list" : "csv", - "!!map" : "table" - }, - "SPECIFIC_TYPE_DISPLAY_MAPPING": { - "ExtractionJob.collision_handling": { - "display" : "select", "str_choices": [ - "BREAKALL", - "BREAKJOIN", - "BREAKCONTAINER", - "BREAKNEVER" - ] - }, - "JobList.jobs": "list" - }, - "IDENTIFIERS": { - #"SQLiteConnector": "name" - }, - "CHILDREN": { - "JobList.jobs": ["!bash", "!sqlquery", "!plsqlquery", "!extract", "!transform", "!inspect", "!load", "!sync", "!copy"] - }, - "REFERENCABLE": [ - "Entity", - "FileConnector", - "LdapConnector", - "OracleConnector", - "MySQLConnector", - "SQLiteConnector", - "PostgreSQLConnector" - ] - } - -def find_subclasses(cls): - result = [] - for subcls in cls.__subclasses__(): - if not subcls.__module__.startswith("hshetl"): - continue - result.append(subcls) - result += find_subclasses(subcls) - return result - -def apply_type_mapping(possible_types): - mapped_types = [] - for p_type in possible_types: - if p_type in config["TYPE_MAPPING"].keys(): - mapped_types.append(config["TYPE_MAPPING"][p_type]) - else: - if p_type.startswith("hshetl."): - cls = eval(p_type) - elif p_type.endswith("Connector"): - cls = eval("hshetl.connectors." + p_type) - elif p_type.endswith("Extractor"): - cls = eval("hshetl.extractors." + p_type) - elif p_type.endswith("Loader"): - cls = eval("hshetl.loaders." + p_type) - else: - continue - if hasattr(cls, "yaml_tag"): - mapped_types.append(cls.yaml_tag) - return mapped_types - -def resolve_param_type(cls, property): - possible_types = [] - pattern = ":type " + property + ": ((:class:\`(.*)`)|(\w*))(( or )?(\\w+)?)*" - result = re.search(pattern, cls.__doc__) - if result == None: - for parent_cls in cls.__mro__: - if parent_cls == yaml.YAMLObject or parent_cls == object: - continue - result = re.search(pattern, parent_cls.__doc__) - if result != None: break - if result == None: - raise DocStringMissesTypeException("The property \"%s\" was not found in class %s or its parents." % (property, cls.__name__)) - for param_type in result.groups(): - if param_type == "" or param_type == None or " " in param_type: - continue - possible_types.append(param_type) - if "." in param_type: - for clas in itersubclasses(eval(param_type)): - if clas.__name__ not in possible_types: - possible_types.append(clas.__name__) - if possible_types == []: - possible_types.append(param_type) - else: - if param_type not in possible_types: - possible_types.append(param_type) - return apply_type_mapping(possible_types) - -def resolve_display_type(sup_type, property, cls_name): - if config["SPECIFIC_TYPE_DISPLAY_MAPPING"].has_key(cls_name + "." + property): - return config["SPECIFIC_TYPE_DISPLAY_MAPPING"][cls_name + "." + property] - elif config["TYPE_DISPLAY_MAPPING"].has_key(sup_type): - return config["TYPE_DISPLAY_MAPPING"][sup_type] - elif sup_type[1] != "!": - return "inline" - else: - return "textfield" - -def json_encode_class(cls): - arg_resolver = hshetl.ConfigurationArgumentMatcher() - props, required = arg_resolver.get_constructor_arguments(cls) - if cls.__name__ in config["REFERENCABLE"]: - cfg = {"yaml_tag": cls.yaml_tag, - "identifier": config["IDENTIFIERS"].get(cls.__name__, "name"), - "verbose_name": cls.__name__, - "properties": {}} - else: - cfg = {"yaml_tag": cls.yaml_tag, - "verbose_name": cls.__name__, - "properties": {}} - for prop in props: - supported_types = resolve_param_type(cls, prop) - param_list = [] - for s_type in supported_types: - children = None - display_type = resolve_display_type(s_type, prop, cls.__name__) - if s_type == "!!list": - children = config["CHILDREN"][cls.__name__ + "." + prop] if config["CHILDREN"].has_key(cls.__name__ + "." + prop) else None - - if children == None: - if isinstance(display_type, dict): - param_list.append({"type": s_type, "form": display_type, "defaults": "foo"}) - else: - param_list.append({"type": s_type, "form": {"display": display_type}, "defaults": "foo"}) - else: - if isinstance(display_type, dict): - param_list.append({"type": s_type, "children": children, "form": display_type, "defaults": "foo"}) - else: - param_list.append({"type": s_type, "children": children, "form": {"display": display_type}, "defaults": "foo"}) - try: - cfg["properties"][prop] = param_list if len(param_list) > 1 else param_list[0] - except Exception: - #this is not supposed to be here in the final version. - cfg["properties"][prop] = {"type" : None, "form": {"display": "textfield"}, "defaults": "foo"} - return cfg - -def dump_schema(): - yaml_subclasses = {} - for cls in find_subclasses(yaml.YAMLObject): - name = cls.__module__ + "." + cls.__name__ - yaml_subclasses.setdefault(name, cls) - docs = {"order": ["connectors", "entities", "jobs"], - "children": {"connectors": [], - "entities": ["!entity"], - "jobs": []}} - classes = [] - for cls in yaml_subclasses.itervalues(): - if cls.yaml_tag == "!void": - continue - if "job" in cls.__name__.lower(): - docs["children"]["jobs"].append(cls.yaml_tag) - elif "connector" in cls.__name__.lower(): - docs["children"]["connectors"].append(cls.yaml_tag) - with open('editor_data.js','w') as f: - print("\"use strict\";\n\nvar hshetl_editor_data = " + - json.dumps({"documents": docs, "classes": classes}, - indent=4, - separators=(',', ': ')), - file=f) - print("editor_data.js successfully generated!") - - -if __name__ == '__main__': - dump_schema()