Exemplo n.º 1
0
    def _get_current_bibolamazi_cmd(self):

        if (not self.bibolamaziFile):
            logger.warning("No bibolamazi file open")
            return

        cmds = self.bibolamaziFile.configCmds();
        if (cmds is None):
            # file is not yet parsed
            return None

        cur = self.ui.txtConfig.textCursor()
        block = cur.block()
        thisline = cur.block().blockNumber()+1

        thisline = self.bibolamaziFile.fileLineNo(thisline)

        logger.longdebug("searching for cmd... at file line=%d", thisline)
        for cmd in cmds:
            logger.longdebug("\t -- testing cmd %r", cmd)
            if cmd.lineno <= thisline and cmd.linenoend >= thisline:
                # got the current cmd
                logger.longdebug("\tGot cmd: %r", cmd)
                return cmd

        return None
Exemplo n.º 2
0
    def _do_update_edittools(self):
        if self._ignore_change_for_edittools:
            return

        cmd = self._get_current_bibolamazi_cmd()
        if (cmd is None):
            self.ui.stackEditTools.setCurrentWidget(self.ui.toolspageBase)
            return
        
        if (cmd.cmd == 'src'):
            thesrcs = shlex.split(cmd.text)
            self.ui.sourceListEditor.setSourceList(thesrcs, noemit=True)
            self.ui.sourceListEditor.setRefDir(self.bibolamaziFile.fdir())
            self.ui.stackEditTools.setCurrentWidget(self.ui.toolspageSource)
            return

        if (cmd.cmd == "filter"):
            filtername = cmd.info['filtername']
            text = cmd.text
            if (text and text[-1] == '\n'):
                text = text[:-1]
            self.ui.filterInstanceEditor.setFilterInstanceDefinition(filtername, text,
                                                                     noemit=True)
            self.ui.stackEditTools.setCurrentWidget(self.ui.toolspageFilter)
            return

        logger.warning("Unknown command: %r", cmd)
        return
Exemplo n.º 3
0
    def _open_anchor(self, url):
        logger.debug("Link clicked: %r", url.toString())

        if url.scheme() == "helptopic":
            self.requestHelpTopic.emit(url.path())
            return

        if url.scheme() == "action":
            m = re.match(r'/goto-config-line/(?P<lineno>\d+)', url.path())
            if m:
                self.gotoConfigLineNo(int(m.group('lineno')))
                return

            m = re.match(r'/goto-bibolamazi-file-line/(?P<lineno>\d+)', url.path())
            if m:
                if (self.bibolamaziFile is None or
                    self.bibolamaziFile.getLoadState() < bibolamazifile.BIBOLAMAZIFILE_READ):
                    logger.warning("No bibolamazifile open!")
                    return
                configlineno = self.bibolamaziFile.configLineNo(int(m.group('lineno')))
                self.gotoConfigLineNo(configlineno)
                return

            logger.warning("Unknown action: %s", str(url.toString()))
            return

        logger.debug("Opening URL %r", str(url.toString()))
        QDesktopServices.openUrl(url)
Exemplo n.º 4
0
    def openHelpTopicBySender(self):
        sender = self.sender()
        path = str(sender.property('helppath'))
        if (not path):
            logger.warning("Bad help topic path: %r", path)
            return

        self.openHelpTopic(path)
Exemplo n.º 5
0
    def runBibolamazi(self, bibolamazifilename, verbosity_level, reload_filter_path):

        # reload_filter_path is a list of 2-tuples (fpname, fpdir)

        if self.threadparent.busy:
            logger.warning("Can't run bibolamazi twice simultaneously")
            return

        logger.debug("RunBibolamazi.runBibolamazi(): bibolamazifilename=%r, verbosity_level=%r, "
                     "reload_filter_path=%r. thread id=%r",
                     bibolamazifilename, verbosity_level, reload_filter_path,
                     QThread.currentThread().objectName())

        self._busy = True
        self.threadparent.busy = True
        self.busy.emit(True)

        try:

            rootlogger = logging.getLogger()
            loggerleveltoset = bibolamazimain.verbosity_logger_level(verbosity_level)
            with ContextAttributeSetter(
                    (lambda : rootlogger.level, rootlogger.setLevel, loggerleveltoset), ):
                with LogToGuiContextManager(logqtsig=self.logqtsig,
                                            bibolamazi_fname=bibolamazifilename) as log2sig:
                    try:
                        # TODO: we should reload all relevant packages here, not
                        # in the other method below

                        self._reload_filterpkg_modules(reload_filter_path)

                        bibolamazimain.run_bibolamazi(bibolamazifile=bibolamazifilename)

                        self.logqtsig.dolog(" --> Finished successfully. <--")
                        self.bibolamaziDone.emit()
                    except butils.BibolamaziError as e:
                        logger.error(str(e))
                        self.logqtsig.dolog(" --> Finished with errors. <--")
                        self.bibolamaziDoneError.emit(str(e))
                    except KeyboardInterrupt as e:
                        logger.error("*** interrupted ***")
                        self.logqtsig.dolog(" --> Stop: Interrupted. <--")
                        self.bibolamaziDoneError.emit("Bibolamazi interrupted")
                    except Exception as e:
                        stre = str(e)
                        logger.error(stre)
                        import traceback
                        logger.error(traceback.format_exc())
                        self.logqtsig.dolog(" --> EXCEPTION <--")
                        self.bibolamaziDoneError.emit(stre)

        finally:
            self.busy.emit(False)
            self._busy = False
            self.threadparent.busy = False
Exemplo n.º 6
0
    def on_btnInterrupt_clicked(self):
        self.ui.btnInterrupt.setEnabled(False) # not twice in a row
        import signal

        sig = signal.SIGINT
        if sys.platform.startswith('win'):
            logger.warning("Interrupt does not work on Windows (not implemented).")
            return
            # doesn't work????!?
            #logger.debug("Sending Ctrl+C ...")
            #sig = signal.CTRL_C_EVENT
            
        os.kill(os.getpid(), sig)
Exemplo n.º 7
0
    def _do_update_edittools(self):
        if self._ignore_change_for_edittools:
            return

        cmdlist = self._get_current_bibolamazi_cmdlist()
        if not cmdlist: # None, or empty list
            self.ui.stackEditTools.setCurrentWidget(self.ui.toolspageBase)
            return

        if len(cmdlist) > 1:
            # several commands selected
            self.ui.stackEditTools.setCurrentWidget(self.ui.toolspageSelectedMultiple)
            return

        # single command selected
        cmd = cmdlist[0]
        
        if cmd.cmd == "src":
            try:
                thesrcs = shlex.split(cmd.text)
            except ValueError as e:
                logger.debug("Invalid source list specification, syntax error: %s", str(e))
                self.ui.sourceListEditor.dispSourceListError(str(e))
                return
            self.ui.sourceListEditor.setSourceList(thesrcs, noemit=True)
            self.ui.sourceListEditor.setRefDir(self.bibolamaziFile.fdir())
            self.ui.stackEditTools.setCurrentWidget(self.ui.toolspageSource)
            return

        if cmd.cmd == "package":
            try:
                self.ui.filterPackagePathEditor.setFilterPackageInfo(cmd.text.strip())
                self.ui.filterPackagePathEditor.setRefDir(self.bibolamaziFile.fdir())
            except BibolamaziError as e:
                self.ui.filterPackagePathEditor.setFilterPackageError(str(e))
            self.ui.stackEditTools.setCurrentWidget(self.ui.toolspagePackage)
            return

        if cmd.cmd == "filter":
            filtername = cmd.info['filtername']
            text = cmd.text
            if text and text[-1] == '\n':
                text = text[:-1]
            self.ui.filterInstanceEditor.setFilterPath(self.bibolamaziFile.fullFilterPath())
            self.ui.filterInstanceEditor.setFilterInstanceDefinition(filtername, text, noemit=True)
            self.ui.stackEditTools.setCurrentWidget(self.ui.toolspageFilter)
            return

        logger.warning("Unknown command: %r", cmd)
        return
Exemplo n.º 8
0
    def add_favorite_cmd(self):
        cmd = self._get_current_bibolamazi_cmd()

        if (cmd is None):
            logger.warning("No command to add to favorites!")
            return

        logger.debug("Adding command %s on lines %d--%d to favorites: %r", cmd.cmd, cmd.lineno, cmd.linenoend, cmd)

        cmdtext = []
        doc = self.ui.txtConfig.document();
        for n in xrange(self.bibolamaziFile.configLineNo(cmd.lineno),
                        self.bibolamaziFile.configLineNo(cmd.linenoend)+1):
            cmdtext.append(unicode(doc.findBlockByNumber(n-1).text()))
        cmdtext = "\n".join(cmdtext)

        self.add_favorite_cmdtext(cmdtext)
Exemplo n.º 9
0
    def _open_anchor(self, url):
        if (url.scheme() == "helptopic"):
            self.requestHelpTopic.emit(url.path());
            return

        if (url.scheme() == "action"):
            m = re.match(r'/goto-config-line/(?P<lineno>\d+)', url.path())
            if m:
                self.ui.tabs.setCurrentWidget(self.ui.pageConfig)
                cur = QTextCursor(self.ui.txtConfig.document().findBlockByNumber(int(m.group('lineno'))-1))
                self.ui.txtConfig.setTextCursor(cur)
                return

            logger.warning("Unknown action: %s", str(url.toString()))
            return

        logger.debug("Opening URL %r", str(url.toString()))
        QDesktopServices.openUrl(url)
Exemplo n.º 10
0
    def makeHelpTopicTab(self, pathitems):
        if (not len(pathitems)):
            logger.warning("makeHelpTopicTab(): No Path specified!")
            return

        font = settingswidget.get_typewriter_font(self)

        if (pathitems[0] == 'filters'):
            if (len(pathitems) < 2):
                logger.warning("makeHelpTopicTab(): No filter specified!!")
                return
            filtname = pathitems[1]

            tb = QTextBrowser(self.ui.tabs)
            tb.setFont(font)
            tb.setText(filters_factory.format_filter_help(filtname))

            tb.setProperty('HelpTabTitle', '%s filter' %(filtname))
            tb.setProperty('HelpTabToolTip', filters_factory.get_filter_class(filtname).getHelpDescription())
            return tb

        if (pathitems[0] == 'general'):
            if (len(pathitems) < 2):
                logger.warning("makeHelpTopicTab(): No help topic general page specified!!")
                return

            tb = QTextBrowser(self.ui.tabs)
            tb.setFont(font)

            if pathitems[1] == 'welcome':
                tb.setPlainText(HELP_WELCOME)
                tb.setProperty('HelpTabTitle', 'Welcome')
            elif pathitems[1] == 'version':
                tb.setPlainText(argparseactions.helptext_prolog())
                tb.setProperty('HelpTabTitle', 'Version')
            elif pathitems[1] == 'cmdline':
                tb.setPlainText(argparseactions.helptext_prolog() +
                                bibolamazimain.get_args_parser().format_help())
                tb.setProperty('HelpTabTitle', 'Command-Line Help')
            elif pathitems[1] == 'filter-list':
                tb.setPlainText(argparseactions.help_list_filters())
                tb.setProperty('HelpTabTitle', 'Filter List')
            else:
                tb.setPlainText('<Unknown help page>')
                tb.setProperty('HelpTabTitle', '<Unknown>')

            tb.setProperty('HelpTabToolTip', '')
            return tb
                
        logger.warning("makeHelpTopicTab(): Unknown help topic: %r", "/".join(pathitems))
        return None
Exemplo n.º 11
0
    def _get_current_bibolamazi_cmdlist(self):

        if not self.bibolamaziFile:
            logger.warning("No bibolamazi file open")
            return

        cmds = self.bibolamaziFile.configCmds()
        if cmds is None:
            # file is not yet parsed
            return None

        cur = self.ui.txtConfig.textCursor()
        block = cur.block()
        thisline = cur.block().blockNumber()+1
        thisline = self.bibolamaziFile.fileLineNo(thisline)

        if cur.hasSelection():
            cur2 = QTextCursor(cur)
            cur2.setPosition(cur.anchor())
            otherline = cur2.block().blockNumber()+1
            otherline = self.bibolamaziFile.fileLineNo(otherline)
        else:
            otherline = thisline

        minline = min(thisline, otherline)
        maxline = max(thisline, otherline)

        logger.longdebug("searching for cmds between lines %d and %d", minline, maxline)
        cmdlist = []
        for cmd in cmds:
            logger.longdebug("\t -- testing cmd %r", cmd)
            if cmd.lineno <= maxline and cmd.linenoend >= minline:
                # got the current cmd
                logger.longdebug("\tGot cmd: %r", cmd)
                cmdlist.append(cmd)

        return cmdlist