def generate(extent="all", save_dotfile="", save_plot="", label="", linker_tables=False): """Retreive the LabbookDB schema and save either a DOT file, or a PNG or PDF plot. """ if extent == "all": nodes = ALLOWED_CLASSES.values() elif type(extent) is list: nodes = [ALLOWED_CLASSES[key] for key in extent] if linker_tables: nodes.extend(linker_tables) desc = sadisplay.describe(nodes) if save_dotfile: save_dotfile = path.abspath(path.expanduser(save_dotfile)) with codecs.open(save_dotfile, 'w', encoding='utf-8') as f: f.write(sadisplay.dot(desc)) if save_plot: save_plot = path.abspath(path.expanduser(save_plot)) dot = sadisplay.dot(desc) dot = dot.replace('label = "generated by sadisplay v0.4.8"', 'label = "{}"'.format(label)) graph = pydotplus.graph_from_dot_data(dot) filename, extension = path.splitext(save_plot) if extension in [".png", ".PNG"]: graph.write_png(save_plot) elif extension in [".pdf", ".PDF"]: graph.write_pdf(save_plot)
def render_vars(self, request): tables = self.Base.metadata.tables.values() desc = sadisplay.describe(tables) dot_data = sadisplay.dot(desc) graph = pydot.graph_from_dot_data(str(dot_data)) svg_img = graph.create_svg() return {'svg_img': svg_img}
def create_uml_files(list_of_models, file_prefix): desc = sadisplay.describe(list_of_models) path_prefix = os.path.join(base_folder, file_prefix) with codecs.open(path_prefix + '.dot', 'w', encoding='utf-8') as f: f.write(sadisplay.dot(desc)) os.system(''.join( ['dot -Tpng ', path_prefix, '.dot > ', path_prefix, '.png']))
def generate_schema(): p_dot = Path(BASE_DIR, 'utils', 'schema.dot') p_png = Path(BASE_DIR, 'utils', 'schema.png') desc = sadisplay.describe( [getattr(models, attr) for attr in dir(models)], show_methods=True, show_properties=True, show_indexes=True, ) with codecs.open(p_dot, 'w', encoding='utf-8') as f: f.write(sadisplay.dot(desc)) with open(p_dot, 'r', encoding='utf-8') as f: s = f.read() with open(p_dot, 'w', encoding='cp1251') as f: f.write(s.encode('cp1251', errors='ignore').decode('cp1251')) if os.name == 'nt': try: from .config_dot_win import DOT_PATH except ModuleNotFoundError: pass else: os.environ["PATH"] += os.pathsep + DOT_PATH try: (graph, ) = pydot.graph_from_dot_file(p_dot, encoding='utf-8') graph.write_png(p_png) except FileNotFoundError as e: print(e.args[1]) if e.args[1] == '"dot" not found in path.': print('Probably "dot" not installed')
def Creatediagram(): desc = sadisplay.describe(globals().values()) with codecs.open('schema.plantuml', 'w', encoding='utf-8') as f: f.write(sadisplay.plantuml(desc)) with codecs.open('schema.dot', 'w', encoding='utf-8') as f: f.write(sadisplay.dot(desc))
def main(): classes = [c for c in list(chain.from_iterable([[getattr(m, a) for a in dir(m)] for m in (terms, factset, network)])) if type(c) is DeclarativeMeta and issubclass(c, Base)] print(classes) desc = sadisplay.describe(classes, show_methods=False) open('schema.plantuml', 'w').write(sadisplay.plantuml(desc)) open('schema.dot', 'w').write(sadisplay.dot(desc))
def render(self, node): all_names = [] for module_name in node['module']: __import__(module_name, globals(), locals()) module = sys.modules[module_name] for attr in dir(module): try: m = getattr(module, attr) # !!! # Ugly hack repr(m) # without this statement - exception raises # any ideas? all_names.append(m) except: pass names = [] if node['exclude']: for i in all_names: try: if i.__name__ not in node['exclude']: names.append(i) except AttributeError: pass elif node['include']: for i in all_names: try: if i.__name__ in node['include']: names.append(i) except AttributeError: pass else: names = all_names desc = sadisplay.describe(names) render = node['render'] or self.builder.config.sadisplay_default_render if render == 'plantuml': content = sadisplay.plantuml(desc) command = generate_plantuml_args(self) elif render == 'graphviz': content = sadisplay.dot(desc) command = generate_graphviz_args(self) return render_image(self, content, command)
def render(self, node): all_names = [] for module_name in node['module']: __import__(module_name, globals(), locals(), [], -1) module = sys.modules[module_name] for attr in dir(module): try: m = getattr(module, attr) # !!! # Ugly hack repr(m) # without this statement - exception raises # any ideas? all_names.append(m) except: pass names = [] if node['exclude']: for i in all_names: try: if i.__name__ not in node['exclude']: names.append(i) except AttributeError: pass elif node['include']: for i in all_names: try: if i.__name__ in node['include']: names.append(i) except AttributeError: pass else: names = all_names desc = sadisplay.describe(names) render = node['render'] or self.builder.config.sadisplay_default_render if render == 'plantuml': content = sadisplay.plantuml(desc) command = generate_plantuml_args(self) elif render == 'graphviz': content = sadisplay.dot(desc) command = generate_graphviz_args(self) return render_image(self, content, command)
def get_ulm(): desc = sadisplay.describe( [getattr(models, attr) for attr in dir(models)], show_methods=True, show_properties=True, show_indexes=True, ) with codecs.open('doc/database/schema.plantuml', 'w', encoding='utf-8') as f: f.write(sadisplay.plantuml(desc)) with codecs.open('doc/database/schema.dot', 'w', encoding='utf-8') as f: f.write(sadisplay.dot(desc))
def models_diagram(): default_models = db.load_default_models() models = [ m for m in util.collect_subclasses(db.Model) if sys.modules[m.__module__] != default_models ] desc = sadisplay.describe(models, show_methods=True, show_properties=True, show_indexes=True) return sadisplay.dot(desc)
def generate_schema_dot(): """ Generate a .dot file for the current database schema. Render the graphviz directed graphs with: $ dot -Tpng schema.dot > schema.png """ import sys import sadisplay reload(sys) sys.setdefaultencoding('utf8') desc = sadisplay.describe(globals().values()) with open('schema.dot', 'w') as f: f.write(sadisplay.dot(desc))
def generate_erd(): """ Generate UML that represents an ERD Command wrapper for sadisplay. Must have graphviz installed. See https://bitbucket.org/estin/sadisplay/wiki/Home """ import sadisplay from ton import models desc = sadisplay.describe([getattr(models, attr) for attr in dir(models)]) with open('schema.dot', 'w') as f: f.write(sadisplay.dot(desc)) ret = call("dot -Tpng schema.dot > schema.png", shell=True) if ret == 0: os.remove("schema.dot")
def render(self, node): all_names = [] for module_name in node["module"]: __import__(module_name, globals(), locals(), [], -1) module = sys.modules[module_name] all_names += [getattr(module, attr) for attr in dir(module)] names = [] if node["exclude"]: for i in all_names: try: if i.__name__ not in node["exclude"]: names.append(i) except AttributeError: pass elif node["include"]: for i in all_names: try: if i.__name__ in node["include"]: names.append(i) except AttributeError: pass else: names = all_names desc = sadisplay.describe(names) render = node["render"] or self.builder.config.sadisplay_default_render if render == "plantuml": content = sadisplay.plantuml(desc) command = generate_plantuml_args(self) elif render == "graphviz": content = sadisplay.dot(desc) command = generate_graphviz_args(self) return render_image(self, content, command)
def render(self, node): all_names = [] for module_name in node['module']: __import__(module_name, globals(), locals(), [], -1) module = sys.modules[module_name] all_names += [getattr(module, attr) for attr in dir(module)] names = [] if node['exclude']: for i in all_names: try: if i.__name__ not in node['exclude']: names.append(i) except AttributeError: pass elif node['include']: for i in all_names: try: if i.__name__ in node['include']: names.append(i) except AttributeError: pass else: names = all_names desc = sadisplay.describe(names) render = node['render'] or self.builder.config.sadisplay_default_render if render == 'plantuml': content = sadisplay.plantuml(desc) command = generate_plantuml_args(self) elif render == 'graphviz': content = sadisplay.dot(desc) command = generate_graphviz_args(self) return render_image(self, content, command)
def generate_schema(schema_file: str, include=None, include_performance_models=True): """Generate an image out of the current schema.""" try: import sadisplay import pydot except ImportError: _LOGGER.error( "Failed to import required libraries to perform schema generation") raise import thoth.storages.graph.models_performance as performance_models from thoth.storages.graph.models import ALL_MAIN_MODELS from thoth.storages.graph.models import ALL_RELATION_MODELS all_models = list(ALL_MAIN_MODELS.union(ALL_RELATION_MODELS)) if include: desc_models = [ m for m in all_models if any( re.fullmatch(p, m.__name__) for p in include) ] else: desc_models = all_models if include_performance_models: desc_models += list(vars(performance_models).values()) desc = sadisplay.describe( desc_models, show_methods=True, show_properties=True, show_indexes=False, show_simple_indexes=False, show_columns_of_indexes=False, ) dot_data = sadisplay.dot(desc) graph, = pydot.graph_from_dot_data(dot_data) _LOGGER.info("Writing schema to %r...", schema_file) graph.write_png(schema_file)
def rel(file_format): ''' outputs relational diagram into rel.png ''' try: from sh import dot, cp desc = sadisplay.describe([ User, Role, Reservation, Room, Timeslot, Weekday, reservations_users, reservations_timeslots ]) with open('schema.dot', 'w', encoding='utf-8') as f: f.write(sadisplay.dot(desc)) dot("-T"+file_format, "schema.dot", "-o", "app/static/rel."+file_format) except ImportError as e: print(str(e))
import sadisplay from happypanda.core import db def exclude(attr): "" if attr.endswith('_profiles'): return True if 'life' == attr.lower(): return True if 'event' == attr.lower(): return True if 'user' == attr.lower(): return True attrs = [getattr(db, attr) for attr in dir(db) if not exclude(attr)] desc = sadisplay.describe( attrs, show_methods=False, show_properties=True, show_indexes=False, show_simple_indexes=False, show_columns_of_indexes=False ) with open('schema.dot', 'w', encoding='utf-8') as f: f.write(sadisplay.dot(desc))
sys.path.insert(0, os.path.abspath('.')) from tools import create_flow_docs # Generate our flow diagrams create_flow_docs.generate('tools/flow-list.txt', 'doc/source/contributor/devref/flow_diagrams') # Generate entity relationship diagram desc = sadisplay.describe( [getattr(models, attr) for attr in dir(models)], show_methods=True, show_properties=True, show_indexes=True, ) graph = graphviz.graph_from_dot_data(sadisplay.dot(desc).encode('utf-8')) graph.write('contributor/devref/erd.svg', format='svg') # If extensions (or modules to document with autodoc) are in another directory, # add these directories to sys.path here. If the directory is relative to the # documentation root, use os.path.abspath to make it absolute, like shown here. # sys.path.insert(0, os.path.abspath('.')) # -- General configuration ---------------------------------------------------- # If your documentation needs a minimal Sphinx version, state it here. # needs_sphinx = '1.0' # Add any Sphinx extension module names here, as strings. They can be # extensions # coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
def __generate_graphviz_dot_file_content(self, db_models) -> str: desc = sadisplay.describe(db_models, show_indexes=self.__show_indexes, show_methods=self.__show_active_components, show_properties=self.__show_active_components) return sadisplay.dot(desc)
import sadisplay from ws import schema desc = sadisplay.describe([getattr(schema, attr) for attr in dir(schema)]) open('schema.dot', 'w').write(sadisplay.dot(desc))
#!/usr/bin/env python from sys import stdout import sadisplay from app import create_app from app import models def _build_desc(): return sadisplay.describe( [getattr(models, attr) for attr in dir(models)], show_methods=True, show_properties=True, show_indexes=True, ) if __name__ == "__main__": app = create_app("development") with app.app_context(): desc = _build_desc() stdout.write(sadisplay.dot(desc).encode("utf8"))
#!/usr/bin/env python import sys import sadisplay from irdata import model if __name__ == '__main__': outfile = sys.argv[1] desc = sadisplay.describe([getattr(model, attr) for attr in dir(model)]) open(outfile, 'w').write(sadisplay.dot(desc))
) class Book(object): pass mapper(Book, books, {'user': relation(User, backref='books')}) # Not mapped table notes = Table( 'notes', BASE.metadata, Column('id', Integer, primary_key=True), Column('name', Unicode(200), nullable=False), Column('user_id', Integer, ForeignKey('user_table.id')), ) if __name__ == '__main__': import sadisplay desc = sadisplay.describe(globals().values()) with open('schema.plantuml', 'w') as f: f.write(sadisplay.plantuml(desc)) with open('schema.dot', 'w') as f: f.write(sadisplay.dot(desc))
#-*- coding:utf-8 -*- import sadisplay from app import models desc = sadisplay.describe([models.User,models.Question,models.Answer,models.Role,models.Tag,models.Follow,models.Vote, models.Unvote,models.assoc_question_tag_table]) file = open('schema.dot', 'w') file.write(sadisplay.dot(desc).encode('utf-8')) file.close()
import sadisplay from app import models import os desc = sadisplay.describe([models.Survey, models.Consent,models.Section,models.Question, models.Condition, models.User, models.StateSurvey,models.Answer]) open('schema1_alto_nivel.dot', 'w').write(sadisplay.dot(desc)) os.system("dot -Tsvg schema1_alto_nivel.dot > schema1_alto_nivel.svg") #esquema preguntas: desc = sadisplay.describe([models.Question,models.QuestionText,models.QuestionYN, models.QuestionChoice, models.QuestionLikertScale]) open('preguntas.dot', 'w').write(sadisplay.dot(desc)) os.system("dot -Tsvg preguntas.dot > preguntas.svg") #esquema juegos: desc = sadisplay.describe([models.GameImpatience, models.Game, models.Raffle, models.User, models.Survey]) open('games_sin_detalle.dot', 'w').write(sadisplay.dot(desc)) os.system("dot -Tsvg games_sin_detalle.dot > games_sin_detalle.svg") desc = sadisplay.describe([models.Game, models.GameLottery1, models.GameLottery2, models.GameRent1, models.GameRent2, models.GameUltimatum, models.GameDictador]) open('games.dot', 'w').write(sadisplay.dot(desc)) os.system("dot -Tsvg games.dot > games.svg") #esquema base de datos os.system("sadisplay -u sqlite:////home/jarenere/frame_game_theory_esquemas/data-dev.sqlite -i answer,condition,consent,question,section,stateSurvey,survey,user -r dot > schema_bbdd.dot") os.system("dot -Tsvg schema_bbdd.dot > schema_bbdd.svg") os.system("sadisplay -u sqlite:////home/jarenere/frame_game_theory_esquemas/data-dev.sqlite -i answer,user,raffle,game,gameImpatience,survey -r dot > schema_bbdd_game.dot") os.system("dot -Tsvg schema_bbdd_game.dot > schema_bbdd_game.svg")