예제 #1
0
class HelpView(urwid.Frame):
    def __init__(self):
        self.load_help()
        self.ftext = urwid.Text("Dummy")
        self.filler = urwid.Filler(self.ftext)
        self.parser = HelpParser(logger=ilog)
        return super(HelpView, self).__init__(self.filler, urwid.Text("Hilfe-Ansicht"))

    def load_help(self):
        """ Parse the yaml-file with the help information
        """
        try:
            path = find_resource("record_help.yaml")
            with open(path, "r") as f:
                self.helpmap = yaml.load(f)
                ilog.debug("help-file successfully loaded")
        except IOError:
            ilog.warn("help-file could not be opened! - no help availiable")
            self.helpmap = None
        except yaml.YAMLError as e:
            ilog.warn("help-file could not be parsed! - no help availiable")
            ilog.warn("Error in help-file: %s" % e)

    def show_topic(self, arguments):
        text = []
        arg0 = arguments[0]
        if not self.helpmap:
            ilog.warn("Help not avaliable (look for previous errors)")
            return False
        if not arguments[0] in self.helpmap:
            ilog.info("Help on the topic %s could not be found" % arg0)
            return False
        topic = self.helpmap
        while arguments:
            arg = arguments.pop()
            if not arg in topic:
                ilog.info("Help on the subtopic %s could not be found." % arg)
                return False
            topic = topic[arg]
        if "usage" in topic:
            text.append(("help_usage", topic["usage"] + "\n\n"))
        ilog.debug("Calling Parser for topic %s" % arg0)
        text.extend(self.parser.parse(topic["help"]))
        self.ftext.set_text(text)
        return True
예제 #2
0
 def __init__(self):
     self.load_help()
     self.ftext = urwid.Text("Dummy")
     self.filler = urwid.Filler(self.ftext)
     self.parser = HelpParser(logger=ilog)
     return super(HelpView, self).__init__(self.filler, urwid.Text("Hilfe-Ansicht"))