def create_datadict(catalog):
    # Get default schema
    schema = catalog.defaultSchema

    # Get table objects and sort them alphabetically
    tables = sorted(schema.tables, key=lambda table: table.name)

    # Fill HTML template
    markup = HTML_TEMPLATE
    markup = markup.replace("[PROJECTNAME]", schema.name)
    markup = markup.replace("[DESCRIPTION]", escape(schema.comment))
    markup = markup.replace("[EDITION]", str(datetime.date.today()))
    markup = markup.replace("[INDEX]", html_index(tables))
    markup = markup.replace("[MAIN]", html_main(tables))

    # Write the HTML file to disk (GUI Dialog)
    doc_path = os.path.dirname(grt.root.wb.docPath)
    dialog = gui.FileChooser(gui.SaveFile)
    dialog.set_title("Save HTML data dictionary")
    dialog.set_directory(doc_path)
    response = dialog.run_modal()
    file_path = dialog.get_path()

    if response:
        save(markup, file_path)

    return 0
 def save(self, item):
     ch = mforms.FileChooser(mforms.SaveFile)
     ch.set_extensions("PNG image (*.png)|*.png", "png")
     ch.set_title("Save Image As")
     ch.set_path("explain.png")
     if ch.run_modal():
         self.render(ch.get_path())
 def do_browse(self):
     fc = mforms.FileChooser(mforms.Form.main_form(), mforms.SaveFile)
     fc.set_path(self.file.get_string_value())
     fc.set_title("Print to File...")
     fc.set_extensions("PDF files (*.pdf)|*.pdf|PostScript Files (*.ps)|*.ps", ".pdf")
     if fc.run_modal():
         self.file.set_value(fc.get_path())
def printDiagramToPDF(diagram):
    fc = mforms.FileChooser(mforms.Form.main_form(), mforms.SaveFile)
    fc.set_title("Export to PDF...")
    fc.set_extensions("PDF files (*.pdf)|*.pdf", ".pdf")
    if fc.run_modal():
        path = fc.get_path()
        mforms.App.get().set_status_text("Exporting diagram %s to PDF file..." % diagram.name)
        grt.modules.WbPrinting.printToPDFFile(diagram, path)
        mforms.App.get().set_status_text("Diagram %s exported to %s" % (diagram.name, path))
    return 0
Exemplo n.º 5
0
 def save(self, item):
     ch = mforms.FileChooser(mforms.SaveFile)
     directory = grt.root.wb.options.options.get(
         "wb.VisualExplain:LastFileChooserDirectory", "")
     if directory:
         ch.set_directory(directory)
     ch.set_extensions("PNG image (*.png)|*.png", "png")
     ch.set_title("Save Image As")
     ch.set_path("explain.png")
     if ch.run_modal():
         self._context.export_to_png(ch.get_path())
         grt.root.wb.options.options[
             "wb.VisualExplain:LastFileChooserDirectory"] = ch.get_directory(
             )
Exemplo n.º 6
0
    def run(self):
        chooser = mforms.FileChooser(mforms.OpenFile)
        chooser.set_title("Run SQL Script")
        chooser.set_extensions('SQL Scripts (*.sql)|*.sql', 'sql')
        if chooser.run_modal():
            dlg = ParameterDialog(self.editor)
            if dlg.run(chooser.get_path()):
                schema = dlg.get_default_schema()
                if schema:
                    self.editor.executeManagementCommand(
                        "CREATE SCHEMA IF NOT EXISTS `%s`" % schema, 1)

                self.start_import(chooser.get_path().encode("utf8"),
                                  dlg.get_default_schema(),
                                  dlg.get_default_charset())
                return True
        return False
 def do_export(self):
     chooser = mforms.FileChooser(mforms.SaveFile)
     chooser.set_title("Export Report")
     chooser.add_selector_option("format", "Format:", "CSV|csv")
     if chooser.run_modal():
         save_path = "%s.csv" % chooser.get_path() if not chooser.get_path(
         ).endswith(".csv") else chooser.get_path()
         with open(save_path, 'w') as csvfile:
             try:
                 import csv
                 output = csv.writer(csvfile, quoting=csv.QUOTE_MINIMAL)
                 output.writerow([self.caption])
                 output.writerow(self._column_titles)
                 root = self._tree.root_node()
                 for r in range(root.count()):
                     node = root.get_child(r)
                     output.writerow(self._get_node_values(node))
             except Exception as e:
                 log_error("Error exporting PS report: %s\n" % e)
                 mforms.Utilities.show_error(
                     "Export Report", "Error exporting PS report.\n%s" % e,
                     "OK", "", "")
Exemplo n.º 8
0
 def export_templates(self):
     dlg = mforms.FileChooser(mforms.SaveFile)
     dlg.set_title("Export Table Templates")
     if dlg.run_modal():
         grt.serialize(self.templates, dlg.get_path())
Exemplo n.º 9
0
def htmlDataDictionary(catalog):
    # Select filename for the HTML file
    htmlOut = ""
    filechooser = mforms.FileChooser(mforms.SaveFile)
    filechooser.set_extensions("HTML File (*.html)|*.html","html");
    if filechooser.run_modal():
        htmlOut = filechooser.get_path()
    print(f"HTML File: {htmlOut}")
    if len(htmlOut) <= 1:
        return 1
    
    # open up file
    with open(htmlOut, "w") as htmlFile:
        # iterate through columns from schema
        schema = catalog.schemata[0]
        htmlFile = open(htmlOut, "w")
        print("<html><head>", file=htmlFile)
        print(f"<title>Schema Report for database: {schema.name}</title>", file=htmlFile)
        print("""<style>
            td,th {
            text-align:left;
            vertical-align:middle;
            }
            table {
            border-collapse: collapse;
            border: 1px solid;
            }
            caption, th, td {
            padding: .2em .8em;
            border: 1px solid #000000;
            }
            caption {
            background: #D3D3D3;
            font-weight: bold;
            font-size: 1.1em;
            }
            th {
            font-weight: bold;
            background: #000000;
            color: white;
            }
            td {
            background: #FFFFFF;
            }
            </style>
          </head>
         <body>""", file=htmlFile)
        print(f"<h1>Schema Report for database: {schema.name}</h1>", file=htmlFile)
        print("<a id=\"home\">Table List </a><br /><ul>", file=htmlFile)
        for table in schema.tables:
            print(f"<li><a href=\"#{table.name}\">{table.name} </a></li>", file=htmlFile)
        print("</ul>", file=htmlFile)
        for table in schema.tables:
            print(f"<a id=\"{table.name}\"></a><table style=\"width:100%%\"><caption>Table: {table.name} </caption>", file=htmlFile)
            print(f"<tr><td>Table Comments</td><td colspan=\"6\">{table.comment}</td></tr>", file=htmlFile)
            print("""<tr><td colspan=\"7\">Columns</td></tr>
            <tr>
            <th>Name</th>
            <th>Data Type</th>
            <th>Nullable</th>
            <th>PK</th>
            <th>FK</th>
            <th>Default</th>
            <th>Comment</th>
            </tr>""", file=htmlFile)
            for column in table.columns:
                pk = ('No', 'Yes')[bool(table.isPrimaryKeyColumn(column))]
                fk = ('No', 'Yes')[bool(table.isForeignKeyColumn(column))]
                nn = ('Yes', 'No')[bool(column.isNotNull)]
                print(f"<tr><td>{column.name}</td><td>{column.formattedType}</td><td>{nn}</td><td>{pk}</td><td>{fk}</td><td>{column.defaultValue}</td><td>{column.comment}</td></tr>", file=htmlFile)
            print("</table><a href=\"#home\">Table List </a></br>", file=htmlFile)
        print("</body></html>", file=htmlFile)

    mforms.Utilities.show_message("Report generated", "HTML Report format from current model generated", "OK","","")
    return 0
Exemplo n.º 10
0
def create_datadict(catalog):
    # Get table objects from the model
    #
    schema = catalog.defaultSchema
    tables = schema.tables

    # Organize table objects alphabeticaly
    #
    sorted_tables = sorted(tables, key=lambda table: table.name)

    # Add header to the markup and replace header variables
    #
    markup = get_header()
    markup = markup.replace("[PROJECTNAME]", schema.name)
    markup = markup.replace("[DESCRIPTION]", schema.comment)
    markup = markup.replace("[EDITION]", str(datetime.date.today()))

    # Add alphabetic index links
    #
    markup += "<h2>Alphabetic Index</h2>\n"
    markup += "<ul>\n"
    for table in sorted_tables:
        markup += "<li><a href='#{0}'>{0}</a></li>\n".format(table.name)
    markup += "</ul>\n"

    # Format table objects in HTML
    #
    for table in sorted_tables:
        markup += "<table id='{0}'>\n".format(table.name)
        #markup += "<caption>{0}</caption>\n".format(table.name)
        markup += "<tr><th colspan='7'>{0}</th></tr>\n".format(table.name)
        markup += get_colnames()
        # TODO Make this optional
        #sorted_columns = sorted(table.columns,
        #                        key=lambda column: column.name)
        for column in table.columns:
            markup += "<tr>\n"
            markup += "    <td>{0}</td>\n".format(column.name)
            markup += "    <td>{0}</td>\n".format(column.formattedType)

            # Check for Primary Key
            if table.isPrimaryKeyColumn(column):
                markup += "    <td>&#10004;</td>\n"
            else:
                markup += "    <td>&nbsp;</td>\n"

            # Check for Not Null attribute
            if column.isNotNull == 1:
                markup += "    <td>&#10004;</td>\n"
            else:
                markup += "    <td>&nbsp;</td>\n"

            # TODO Check for Unique attribute
            if False:
                markup += "    <td>&#10004;</td>\n"
            else:
                markup += "    <td>&nbsp;</td>\n"

            # Check for Binary, Unsigned and Zero Fill attributes
            flags = list(column.flags)

            if flags.count("BINARY"):
                markup += "    <td>&#10004;</td>\n"
            else:
                markup += "    <td>&nbsp;</td>\n"

            markup += "    <td>{0}</td>\n".format(column.comment)
            markup += "</tr>\n"

    markup += "</table>\n"

    # Add footer to the markup
    #
    markup += get_footer()

    # Write the HTML file to disk
    #
    doc_path = os.path.dirname(grt.root.wb.docPath)

    dialog = gui.FileChooser(gui.SaveFile)
    dialog.set_title("Save HTML data dictionary")
    dialog.set_directory(doc_path)
    response = dialog.run_modal()
    file_path = dialog.get_path()

    if response:
        try:
            html_file = open(file_path, "w")
        except IOError:
            text = "Could not open {0}.".format(file_path)
            gui.Utilities.show_error("Error saving the file", text, "Ok", "",
                                     "")
        else:
            html_file.write(markup)
            html_file.close()

            title = "{0}'s data dictionary".format(schema.name)
            text = "The data dictionary was successfully generated."
            gui.Utilities.show_message(title, text, "Ok", "", "")

            # Open HTML file in the Web browser
            #
            try:
                webbrowser.open_new(file_path)
            except webbrowser.Error:
                print("Warning: Could not open the data dictionary in " +
                      "the Web browser.")

    return 0
Exemplo n.º 11
0
def create_documentation(catalog):

    schema = catalog.defaultSchema
    tables = schema.tables

    sorted_tables = sorted(tables, key=lambda table: table.name)

    markup = get_header()
    markup = markup.replace("[PROJECTNAME]", schema.name)
    markup = markup.replace("[DESCRIPTION]", schema.comment)
    markup = markup.replace("[EDITION]", str(datetime.date.today()))

    markup += "<h2>Index</h2>\n"
    markup += "<ul>\n"
    for table in sorted_tables:
        markup += "<li><a href='#{0}'>{0}</a></li>\n".format(table.name)
    markup += "</ul>\n"

    for table in sorted_tables:
        markup += "<table id='{0}'>\n".format(table.name)
        markup += "<caption>{0}</caption>\n".format(table.name)
        markup += "<tr><td colspan='11'>{0}</td></tr>\n".format(table.comment)
        markup += get_colnames_columns()

        for column in table.columns:
            markup += "<tr>\n"
            markup += "    <td>{0}</td>\n".format(column.name)
            markup += "    <td>{0}</td>\n".format(column.formattedType)

            if table.isPrimaryKeyColumn(column):
                markup += "    <td>&#10004;</td>\n"
            else:
                markup += "    <td>&nbsp;</td>\n"

            if column.isNotNull == 1:
                markup += "    <td>&#10004;</td>\n"
            else:
                markup += "    <td>&nbsp;</td>\n"

            if False:
                markup += "    <td>&#10004;</td>\n"
            else:
                markup += "    <td>&nbsp;</td>\n"

            flags = list(column.flags)

            if flags.count("BINARY"):
                markup += "    <td>&#10004;</td>\n"
            else:
                markup += "    <td>&nbsp;</td>\n"

            if flags.count("UNSIGNED"):
                markup += "    <td>&#10004;</td>\n"
            else:
                markup += "    <td>&nbsp;</td>\n"

            if flags.count("ZEROFILL"):
                markup += "    <td>&#10004;</td>\n"
            else:
                markup += "    <td>&nbsp;</td>\n"

            if column.autoIncrement == 1:
                markup += "    <td>&#10004;</td>\n"
            else:
                markup += "    <td class='attr'>&nbsp;</td>\n"

            markup += "    <td>{0}</td>\n".format(column.defaultValue)

            markup += "    <td>{0}</td>\n".format(column.comment)
            markup += "</tr>\n"

        markup += "</table>\n"

        if table.indices:
            markup += "<table id='{0}_indices'>\n".format(table.name)
            markup += get_colnames_indices()

            for index in table.indices:
                markup += " <tr>\n"
                markup += "    <td>{0}</td>\n".format(index.name)
                markup += "    <td>{0}</td>\n".format(index.indexType)
                markup += "    <td>"
                markup += ", ".join(
                    map(lambda x: x.referencedColumn.name, index.columns))
                markup += "    </td>\n"
                markup += "    <td>{0}</td>\n".format(index.comment)
                markup += " </tr>\n"

            markup += "</table>\n"

        if table.foreignKeys:
            markup += "<table id='{0}_foreignKeys'>\n".format(table.name)
            markup += get_colnames_foreignKeys()

            for foreignKey in table.foreignKeys:
                markup += " <tr>\n"
                markup += "    <td>{0}</td>\n".format(foreignKey.name)
                markup += "    <td>"
                markup += ", ".join(
                    map(lambda x: x.name, foreignKey.referencedColumns))
                markup += "    </td>\n"
                markup += "    <td>"
                markup += ", ".join(
                    set(
                        map(lambda x: x.owner.name,
                            foreignKey.referencedColumns)))
                markup += "     </td>\n"
                markup += "     <td>{0}</td>\n".format(foreignKey.comment)
                markup += " </tr>\n"

            markup += "</table>\n"

    markup += get_footer()

    doc_path = os.path.dirname(grt.root.wb.docPath)

    dialog = gui.FileChooser(gui.SaveFile)
    dialog.set_title("Save HTML Documentation")
    dialog.set_directory(doc_path)
    response = dialog.run_modal()
    file_path = dialog.get_path()

    if response:
        try:
            html_file = open(file_path, "w")
        except IOError:
            text = "Could not open {0}.".format(file_path)
            gui.Utilities.show_error("Error saving the file", text, "Ok", "",
                                     "")
        else:
            html_file.write(markup)
            html_file.close()

            title = "{0} - Model Documentation".format(schema.name)
            text = "The Documentation was successfully generated."
            gui.Utilities.show_message(title, text, "Ok", "", "")

            try:
                webbrowser.open_new(file_path)
            except webbrowser.Error:
                print("Error: Could not open the Documentation in " +
                      "the Web browser.")

    return 0
Exemplo n.º 12
0
 def advanced_clicked(self):
     filechooser = mforms.FileChooser(mforms.OpenFile)
     filechooser.set_title("Choose Backup File")
     if filechooser.run_modal():
         filename = filechooser.get_path()
         print filename