Esempio n. 1
0
def RunReport(dbstate, uistate, mod_str, name, trans_name, report_str, options_str):

    dialog_class = TextReportDialog

    mod = __import__(mod_str)
    report_class = getattr(mod, report_str)
    options_class = getattr(mod, options_str)

    dialog = dialog_class(dbstate, uistate, options_class, name, trans_name)

    while True:
        response = dialog.window.run()
        if response == Gtk.ResponseType.OK:
            dialog.close()
            try:
                user = User()
                MyReport = report_class(dialog.db, dialog.options, user)

                def do_report():
                    MyReport.doc.init()
                    MyReport.begin_report()
                    MyReport.write_report()
                    MyReport.end_report()

                do_report()

                if dialog.open_with_app.get_active():
                    out_file = dialog.options.get_output()
                    open_file_with_default_application(out_file)

            except Errors.FilterError as msg:
                (m1, m2) = msg.messages()
                ErrorDialog(m1, m2)
            except IOError as msg:
                ErrorDialog(_("Report could not be created"), str(msg))
            except Errors.ReportError as msg:
                (m1, m2) = msg.messages()
                ErrorDialog(m1, m2)
            except Errors.DatabaseError as msg:
                ErrorDialog(_("Report could not be created"), str(msg))
                raise
            except:
                LOG.error("Failed to run report.", exc_info=True)
            break
        elif response == Gtk.ResponstType.CANCEL:
            dialog.close()
            break
        elif response == Gtk.ResponseType.DELETE_EVENT:
            #just stop, in ManagedWindow, delete-event is already coupled to
            #correct action.
            break

    #do needed cleanup
    dialog.db = None
    dialog.options = None
    if hasattr(dialog, 'window'):
        delattr(dialog, 'window')
    if hasattr(dialog, 'notebook'):
        delattr(dialog, 'notebook')
    del dialog
Esempio n. 2
0
    def run(self, obj):
        """
        Method that is run when you click the Run button.
        The date is retrieved from the entry box, parsed as a date,
        and then handed to the quick report.
        """
        user = User(callback=self.myprogress)

        message = _("Import done")
        buffer = self.import_text.get_buffer()
        start = buffer.get_start_iter()
        end = buffer.get_end_iter()
        text = buffer.get_text(start, end, True).strip()
        if not text:
            return
        print(text)
        self.uistate.set_busy_cursor(1)
        self.uistate.progress.show()
        self.uistate.push_message(self.dbstate, _("Importing Text..."))
        database = self.dbstate.db
        if text.startswith("0 HEAD"):
            raise NotImplementedError
        elif text.startswith("BEGIN:VCARD"):
            parser = AtomicVCardParser(database)
            ifile = StringIO(text)
            parser.parse(ifile)
        elif text.find("""<!DOCTYPE database PUBLIC "-//Gramps//""") > 0:
            ifile = BytesIO(text.encode('utf-8'))
            ofile = StringIO(text)
            person_count = 0
            line_count = 0
            for line in ofile:
                line_count += 1
                if PERSON_RE.match(line):
                    person_count += 1
            change = int(time.time())
            parser = AtomicGrampsParser(database, user, change)
            try:
                info = parser.parse(ifile, line_count, person_count)
                print(info.info_text())
            except:
                import traceback
                traceback.print_exc()
        else:
            try:
                parser = AtomicCSVParser(database)
                ifile = StringIO(text)
                parser.parse(ifile)
            except:
                ErrorDialog(_("Can't determine type of import"))
                message = _("Import failed")
        # FIXME: allow file:/// imports as well
        self.uistate.set_busy_cursor(0)
        self.uistate.progress.hide()
        self.uistate.push_message(self.dbstate, message)
Esempio n. 3
0
    def __init__(self, dbstate, user, options_class, name, callback=None):
        tool.Tool.__init__(self, dbstate, options_class, name)
        if not dbstate.db:
            return

        if not Topola.server:
            Topola.server = TopolaServer()
            Topola.server.start()

        temp_file = mkstemp()[1]
        ged_writer = GedcomWriter(dbstate.db, User())
        ged_writer.write_gedcom_file(temp_file)
        Topola.server.set_path(temp_file)
        display_url('https://pewu.github.io/topola-viewer/#/view' +
                    '?utm_source=gramps&handleCors=false&standalone=false' +
                    '&url=http://127.0.0.1:{}/'.format(HTTP_PORT))
Esempio n. 4
0
 def doit(self, dialog, uistate):
     from gi.repository import Gtk
     response = dialog.window.run()
     if response == Gtk.ResponseType.OK:
         dialog.close()
         try:
             from gramps.gui.user import User
             user = User(uistate=uistate)
             my_report = TAMexportReport(dialog.db, dialog.options, user)
             my_report.doc.init()
             my_report.begin_report()
             my_report.write_report()
             my_report.end_report()
         except FilterError as msg:
             from gramps.gui.dialog import ErrorDialog
             (msg1, msg2) = msg.messages()
             ErrorDialog(msg1, msg2, parent=uistate.window)
         except IOError as msg:
             from gramps.gui.dialog import ErrorDialog
             ErrorDialog(_("Report could not be created"),
                         str(msg),
                         parent=uistate.window)
         except ReportError as msg:
             from gramps.gui.dialog import ErrorDialog
             (msg1, msg2) = msg.messages()
             ErrorDialog(msg1, msg2, parent=uistate.window)
         except DatabaseError as msg:
             from gramps.gui.dialog import ErrorDialog
             ErrorDialog(_("Report could not be created"),
                         str(msg),
                         parent=uistate.window)
             raise
         except:
             log.error("Failed to run report.", exc_info=True)
         return True
     elif response == Gtk.ResponseType.CANCEL:
         dialog.close()
         return True
     elif response == Gtk.ResponseType.DELETE_EVENT:
         #just stop, in ManagedWindow, delete-event is already coupled to
         #correct action.
         return True
Esempio n. 5
0
    def set_database(self, database):
        """Takes a snapshot of the database as a GEDCOM file.

      Note that this call may take some time to generate the GEDCOM file.
      """

        # Export GEDCOM to a temporary file.
        exported_file = mkstemp()[1]
        ged_writer = GedcomWriter(database, User())
        ged_writer.write_gedcom_file(exported_file)

        # Postprocess the exported file replacing referenced files with links
        # back to Gramps that will read these files.
        content = open(exported_file, 'r', encoding='utf-8').readlines()
        gedcom_path = mkstemp()[1]
        # Store all served files in a map from requested URL path to path on
        # disk.
        file_map = {'/': gedcom_path}
        gedcom_file = open(gedcom_path, 'w', encoding='utf-8')
        for line in content:
            if line.startswith('1 FILE'):
                file_name = line[6:].strip()
                # Don't replace web links.
                if file_name.startswith('http://') or file_name.startswith(
                        'https://'):
                    continue
                # Use hash instead of file path to avoid encoding problems.
                hash = md5(file_name.encode()).hexdigest()
                # Preserve file extension.
                extension = splitext(file_name)[1]
                remote_name = '/file/{}{}'.format(hash, extension)
                file_map[remote_name] = file_name
                line = '1 FILE http://127.0.0.1:8156{}\n'.format(remote_name)
            gedcom_file.write(line)

        # Replace the file map in a thread-safe way.
        with self.lock:
            self.file_map = file_map