コード例 #1
0
ファイル: configPanel.py プロジェクト: JustMe23/arm
 def __init__(self, option, type, isDefault):
   self.fields = {}
   self.fields[Field.OPTION] = option
   self.fields[Field.TYPE] = type
   self.fields[Field.IS_DEFAULT] = isDefault
   
   # Fetches extra infromation from external sources (the arm config and tor
   # man page). These are None if unavailable for this config option.
   summary = torConfig.getConfigSummary(option)
   manEntry = torConfig.getConfigDescription(option)
   
   if manEntry:
     self.fields[Field.MAN_ENTRY] = manEntry.index
     self.fields[Field.CATEGORY] = manEntry.category
     self.fields[Field.ARG_USAGE] = manEntry.argUsage
     self.fields[Field.DESCRIPTION] = manEntry.description
   else:
     self.fields[Field.MAN_ENTRY] = 99999 # sorts non-man entries last
     self.fields[Field.CATEGORY] = torConfig.Category.UNKNOWN
     self.fields[Field.ARG_USAGE] = ""
     self.fields[Field.DESCRIPTION] = ""
   
   # uses the full man page description if a summary is unavailable
   self.fields[Field.SUMMARY] = summary if summary != None else self.fields[Field.DESCRIPTION]
   
   # cache of what's displayed for this configuration option
   self.labelCache = None
   self.labelCacheArgs = None
コード例 #2
0
 def __init__(self, option, type, isDefault):
   self.fields = {}
   self.fields[Field.OPTION] = option
   self.fields[Field.TYPE] = type
   self.fields[Field.IS_DEFAULT] = isDefault
   
   # Fetches extra infromation from external sources (the arm config and tor
   # man page). These are None if unavailable for this config option.
   summary = torConfig.getConfigSummary(option)
   manEntry = torConfig.getConfigDescription(option)
   
   if manEntry:
     self.fields[Field.MAN_ENTRY] = manEntry.index
     self.fields[Field.CATEGORY] = manEntry.category
     self.fields[Field.ARG_USAGE] = manEntry.argUsage
     self.fields[Field.DESCRIPTION] = manEntry.description
   else:
     self.fields[Field.MAN_ENTRY] = 99999 # sorts non-man entries last
     self.fields[Field.CATEGORY] = torConfig.Category.UNKNOWN
     self.fields[Field.ARG_USAGE] = ""
     self.fields[Field.DESCRIPTION] = ""
   
   # uses the full man page description if a summary is unavailable
   self.fields[Field.SUMMARY] = summary if summary != None else self.fields[Field.DESCRIPTION]
   
   # cache of what's displayed for this configuration option
   self.labelCache = None
   self.labelCacheArgs = None
コード例 #3
0
    def __init__(self, stdscr, configType, config=None):
        panel.Panel.__init__(self, stdscr, "configState", 0)

        self.sortOrdering = DEFAULT_SORT_ORDER
        self._config = dict(DEFAULT_CONFIG)
        if config:
            config.update(
                self._config, {
                    "features.config.selectionDetails.height": 0,
                    "features.config.state.colWidth.option": 5,
                    "features.config.state.colWidth.value": 5
                })

            self.sortOrdering = config.getIntCSV("features.config.order",
                                                 self.sortOrdering, 3, 0, 6)

        self.configType = configType
        self.confContents = []
        self.scroller = uiTools.Scroller(True)
        self.valsLock = threading.RLock()

        if self.configType == TOR_STATE:
            conn = torTools.getConn()
            customOptions = torConfig.getCustomOptions()
            configOptionLines = conn.getInfo("config/names",
                                             "").strip().split("\n")

            for line in configOptionLines:
                # lines are of the form "<option> <type>", like:
                # UseEntryGuards Boolean
                confOption, confType = line.strip().split(" ", 1)

                # skips private and virtual entries if not set to show them
                if not self._config[
                        "features.config.state.showPrivateOptions"] and confOption.startswith(
                            "__"):
                    continue
                elif not self._config[
                        "features.config.state.showVirtualOptions"] and confType == "Virtual":
                    continue

                manEntry = torConfig.getConfigDescription(confOption)
                self.confContents.append(
                    ConfigEntry(confOption, confType,
                                not confOption in customOptions, manEntry))

            self.setSortOrder()  # initial sorting of the contents
        elif self.configType == ARM_STATE:
            # loaded via the conf utility
            armConf = conf.getConfig("arm")
            for key in armConf.getKeys():
                pass  # TODO: implement
コード例 #4
0
ファイル: configPanel.py プロジェクト: katmagic/arm
 def __init__(self, stdscr, configType, config=None):
   panel.Panel.__init__(self, stdscr, "configState", 0)
   
   self.sortOrdering = DEFAULT_SORT_ORDER
   self._config = dict(DEFAULT_CONFIG)
   if config:
     config.update(self._config, {
       "features.config.selectionDetails.height": 0,
       "features.config.state.colWidth.option": 5,
       "features.config.state.colWidth.value": 5})
     
     self.sortOrdering = config.getIntCSV("features.config.order", self.sortOrdering, 3, 0, 6)
   
   self.configType = configType
   self.confContents = []
   self.scroller = uiTools.Scroller(True)
   self.valsLock = threading.RLock()
   
   if self.configType == TOR_STATE:
     conn = torTools.getConn()
     customOptions = torConfig.getCustomOptions()
     configOptionLines = conn.getInfo("config/names", "").strip().split("\n")
     
     for line in configOptionLines:
       # lines are of the form "<option> <type>", like:
       # UseEntryGuards Boolean
       confOption, confType = line.strip().split(" ", 1)
       
       # skips private and virtual entries if not set to show them
       if not self._config["features.config.state.showPrivateOptions"] and confOption.startswith("__"):
         continue
       elif not self._config["features.config.state.showVirtualOptions"] and confType == "Virtual":
         continue
       
       manEntry = torConfig.getConfigDescription(confOption)
       self.confContents.append(ConfigEntry(confOption, confType, not confOption in customOptions, manEntry))
     
     self.setSortOrder() # initial sorting of the contents
   elif self.configType == ARM_STATE:
     # loaded via the conf utility
     armConf = conf.getConfig("arm")
     for key in armConf.getKeys():
       pass # TODO: implement
コード例 #5
0
ファイル: torInterpretor.py プロジェクト: JustMe23/arm
 def doHelp(self, arg, outputEntry):
   """
   Performs the '/help' operation, giving usage information for the given
   argument or a general summary if there wasn't one.
   """
   
   arg = arg.upper()
   
   # If there's multiple arguments then just take the first. This is
   # particularly likely if they're trying to query a full command (for
   # instance "/help GETINFO version")
   
   arg = arg.split(" ")[0]
   
   # strip slash if someone enters an interpretor command (ex. "/help /help")
   if arg.startswith("/"): arg = arg[1:]
   
   if arg:
     if arg in HELP_OPTIONS:
       # Provides information for the tor or interpretor argument. This bolds
       # the usage information and indents the description after it.
       usage, description = HELP_OPTIONS[arg]
       
       outputEntry.append((usage + "\n", OUTPUT_FORMAT + (Attr.BOLD, )))
       
       for line in description.split("\n"):
         outputEntry.append(("  " + line + "\n", OUTPUT_FORMAT))
       
       if arg == "GETINFO":
         # if this is the GETINFO option then also list the valid options
         infoOptions = torTools.getConn().getInfo("info/names")
         
         if infoOptions:
           for line in infoOptions.split("\n"):
             if line.startswith("config/*") or line.startswith("dir-usage"):
               continue
             
             lineMatch = re.match("^(.+) -- (.+)$", line)
             
             if lineMatch:
               opt, description = lineMatch.groups()
               
               outputEntry.append(("%-33s" % opt, OUTPUT_FORMAT + (Attr.BOLD, )))
               outputEntry.append((" - %s\n" % description, OUTPUT_FORMAT))
       elif arg == "GETCONF":
         # lists all of the configuration options
         
         confOptions = torTools.getConn().getInfo("config/names")
         if confOptions:
           confEntries = [opt.split(" ", 1)[0] for opt in confOptions.split("\n")]
           
           # displays two columns of 42 characters
           for i in range(0, len(confEntries), 2):
             lineEntries = confEntries[i : i+2]
             
             lineContent = ""
             for entry in lineEntries:
               lineContent += "%-42s" % entry
             
             outputEntry.append((lineContent + "\n", OUTPUT_FORMAT))
           
           outputEntry.append(("For more information use '/help [CONFIG OPTION]'.", OUTPUT_FORMAT + (Attr.BOLD, )))
       elif arg == "SIGNAL":
         # lists descriptions for all of the signals
         for signal, description in SIGNAL_DESCRIPTIONS:
           outputEntry.append(("%-15s" % signal, OUTPUT_FORMAT + (Attr.BOLD, )))
           outputEntry.append((" - %s\n" % description, OUTPUT_FORMAT))
       elif arg == "SETEVENTS":
         # lists all of the event types
         eventOptions = torTools.getConn().getInfo("events/names")
         if eventOptions:
           eventEntries = eventOptions.split()
           
           # displays four columns of 20 characters
           for i in range(0, len(eventEntries), 4):
             lineEntries = eventEntries[i : i+4]
             
             lineContent = ""
             for entry in lineEntries:
               lineContent += "%-20s" % entry
             
             outputEntry.append((lineContent + "\n", OUTPUT_FORMAT))
       elif arg == "USEFEATURE":
         # lists the feature options
         featureOptions = torTools.getConn().getInfo("features/names")
         if featureOptions:
           outputEntry.append((featureOptions + "\n", OUTPUT_FORMAT))
       elif arg in ("LOADCONF", "POSTDESCRIPTOR"):
         # gives a warning that this option isn't yet implemented
         outputEntry.append(("\n" + MULTILINE_UNIMPLEMENTED_NOTICE + "\n", ERROR_FORMAT))
     else:
       # check if this is a configuration option
       manEntry = torConfig.getConfigDescription(arg)
       
       if manEntry:
         # provides basic usage information in bold, followed an indented
         # copy of the man page description (wrapped to eighty characters)
         
         helpTitle = "%s %s (category: %s)\n" % (manEntry.option, manEntry.argUsage, manEntry.category)
         outputEntry.append((helpTitle, OUTPUT_FORMAT + (Attr.BOLD, )))
         
         descLines = manEntry.description.split("\n")
         
         for line in descLines:
           if not line:
             outputEntry.append(("\n", OUTPUT_FORMAT))
           else:
             while line:
               drawPortion, line = uiTools.cropStr(line, 88, 4, 4, uiTools.Ending.HYPHEN, True)
               outputEntry.append(("  %s\n" % drawPortion.strip(), OUTPUT_FORMAT))
       else:
         outputEntry.append(("No help information available for '%s'..." % arg, ERROR_FORMAT))
   else:
     # provides the GENERAL_HELP with everything bolded except descriptions
     for line in GENERAL_HELP.split("\n"):
       cmdStart = line.find(" - ")
       
       if cmdStart != -1:
         outputEntry.append((line[:cmdStart], OUTPUT_FORMAT + (Attr.BOLD, )))
         outputEntry.append((line[cmdStart:] + "\n", OUTPUT_FORMAT))
       else:
         outputEntry.append((line + "\n", OUTPUT_FORMAT + (Attr.BOLD, )))
コード例 #6
0
    def doHelp(self, arg, outputEntry):
        """
    Performs the '/help' operation, giving usage information for the given
    argument or a general summary if there wasn't one.
    """

        arg = arg.upper()

        # If there's multiple arguments then just take the first. This is
        # particularly likely if they're trying to query a full command (for
        # instance "/help GETINFO version")

        arg = arg.split(" ")[0]

        # strip slash if someone enters an interpretor command (ex. "/help /help")
        if arg.startswith("/"): arg = arg[1:]

        if arg:
            if arg in HELP_OPTIONS:
                # Provides information for the tor or interpretor argument. This bolds
                # the usage information and indents the description after it.
                usage, description = HELP_OPTIONS[arg]

                outputEntry.append(
                    (usage + "\n", OUTPUT_FORMAT + (Attr.BOLD, )))

                for line in description.split("\n"):
                    outputEntry.append(("  " + line + "\n", OUTPUT_FORMAT))

                if arg == "GETINFO":
                    # if this is the GETINFO option then also list the valid options
                    infoOptions = torTools.getConn().getInfo("info/names")

                    if infoOptions:
                        for line in infoOptions.split("\n"):
                            if line.startswith("config/*") or line.startswith(
                                    "dir-usage"):
                                continue

                            lineMatch = re.match("^(.+) -- (.+)$", line)

                            if lineMatch:
                                opt, description = lineMatch.groups()

                                outputEntry.append(
                                    ("%-33s" % opt,
                                     OUTPUT_FORMAT + (Attr.BOLD, )))
                                outputEntry.append(
                                    (" - %s\n" % description, OUTPUT_FORMAT))
                elif arg == "GETCONF":
                    # lists all of the configuration options

                    confOptions = torTools.getConn().getInfo("config/names")
                    if confOptions:
                        confEntries = [
                            opt.split(" ", 1)[0]
                            for opt in confOptions.split("\n")
                        ]

                        # displays two columns of 42 characters
                        for i in range(0, len(confEntries), 2):
                            lineEntries = confEntries[i:i + 2]

                            lineContent = ""
                            for entry in lineEntries:
                                lineContent += "%-42s" % entry

                            outputEntry.append(
                                (lineContent + "\n", OUTPUT_FORMAT))

                        outputEntry.append((
                            "For more information use '/help [CONFIG OPTION]'.",
                            OUTPUT_FORMAT + (Attr.BOLD, )))
                elif arg == "SIGNAL":
                    # lists descriptions for all of the signals
                    for signal, description in SIGNAL_DESCRIPTIONS:
                        outputEntry.append(
                            ("%-15s" % signal, OUTPUT_FORMAT + (Attr.BOLD, )))
                        outputEntry.append(
                            (" - %s\n" % description, OUTPUT_FORMAT))
                elif arg == "SETEVENTS":
                    # lists all of the event types
                    eventOptions = torTools.getConn().getInfo("events/names")
                    if eventOptions:
                        eventEntries = eventOptions.split()

                        # displays four columns of 20 characters
                        for i in range(0, len(eventEntries), 4):
                            lineEntries = eventEntries[i:i + 4]

                            lineContent = ""
                            for entry in lineEntries:
                                lineContent += "%-20s" % entry

                            outputEntry.append(
                                (lineContent + "\n", OUTPUT_FORMAT))
                elif arg == "USEFEATURE":
                    # lists the feature options
                    featureOptions = torTools.getConn().getInfo(
                        "features/names")
                    if featureOptions:
                        outputEntry.append(
                            (featureOptions + "\n", OUTPUT_FORMAT))
                elif arg in ("LOADCONF", "POSTDESCRIPTOR"):
                    # gives a warning that this option isn't yet implemented
                    outputEntry.append(
                        ("\n" + MULTILINE_UNIMPLEMENTED_NOTICE + "\n",
                         ERROR_FORMAT))
            else:
                # check if this is a configuration option
                manEntry = torConfig.getConfigDescription(arg)

                if manEntry:
                    # provides basic usage information in bold, followed an indented
                    # copy of the man page description (wrapped to eighty characters)

                    helpTitle = "%s %s (category: %s)\n" % (
                        manEntry.option, manEntry.argUsage, manEntry.category)
                    outputEntry.append(
                        (helpTitle, OUTPUT_FORMAT + (Attr.BOLD, )))

                    descLines = manEntry.description.split("\n")

                    for line in descLines:
                        if not line:
                            outputEntry.append(("\n", OUTPUT_FORMAT))
                        else:
                            while line:
                                drawPortion, line = uiTools.cropStr(
                                    line, 88, 4, 4, uiTools.Ending.HYPHEN,
                                    True)
                                outputEntry.append(
                                    ("  %s\n" % drawPortion.strip(),
                                     OUTPUT_FORMAT))
                else:
                    outputEntry.append(
                        ("No help information available for '%s'..." % arg,
                         ERROR_FORMAT))
        else:
            # provides the GENERAL_HELP with everything bolded except descriptions
            for line in GENERAL_HELP.split("\n"):
                cmdStart = line.find(" - ")

                if cmdStart != -1:
                    outputEntry.append(
                        (line[:cmdStart], OUTPUT_FORMAT + (Attr.BOLD, )))
                    outputEntry.append((line[cmdStart:] + "\n", OUTPUT_FORMAT))
                else:
                    outputEntry.append(
                        (line + "\n", OUTPUT_FORMAT + (Attr.BOLD, )))