{"action":"created","comment":{"url":"https://api.github.com/repos/deluge-torrent/deluge/pulls/comments/59203703","id":59203703,"diff_hunk":"@@ -10,165 +10,58 @@\n \n from __future__ import print_function\n \n+import argparse\n import locale\n import logging\n-import optparse\n-import os\n-import re\n import shlex\n import sys\n \n from twisted.internet import defer, reactor\n \n import deluge.common\n import deluge.component as component\n+from deluge.error import DelugeError\n from deluge.ui.client import client\n-from deluge.ui.console import UI_PATH, colors\n+from deluge.ui.console import colors\n+from deluge.ui.console.colors import ConsoleColorFormatter\n from deluge.ui.console.eventlog import EventLog\n from deluge.ui.console.statusbars import StatusBars\n from deluge.ui.coreconfig import CoreConfig\n from deluge.ui.sessionproxy import SessionProxy\n-from deluge.ui.ui import _UI\n \n log = logging.getLogger(__name__)\n \n \n-class Console(_UI):\n-\n-    help = \"\"\"Starts the Deluge console interface\"\"\"\n-\n-    def __init__(self):\n-        super(Console, self).__init__(\"console\")\n-        group = optparse.OptionGroup(self.parser, \"Console Options\", \"These daemon connect options will be \"\n-                                     \"used for commands, or if console ui autoconnect is enabled.\")\n-        group.add_option(\"-d\", \"--daemon\", dest=\"daemon_addr\")\n-        group.add_option(\"-p\", \"--port\", dest=\"daemon_port\", type=\"int\")\n-        group.add_option(\"-u\", \"--username\", dest=\"daemon_user\")\n-        group.add_option(\"-P\", \"--password\", dest=\"daemon_pass\")\n-        self.parser.add_option_group(group)\n-        self.parser.disable_interspersed_args()\n-\n-        self.console_cmds = load_commands(os.path.join(UI_PATH, \"commands\"))\n-\n-        class CommandOptionGroup(optparse.OptionGroup):\n-            def __init__(self, parser, title, description=None, cmds=None):\n-                optparse.OptionGroup.__init__(self, parser, title, description)\n-                self.cmds = cmds\n-\n-            def format_help(self, formatter):\n-                result = formatter.format_heading(self.title)\n-                formatter.indent()\n-                if self.description:\n-                    result += \"%s\\n\" % formatter.format_description(self.description)\n-                for cname in self.cmds:\n-                    cmd = self.cmds[cname]\n-                    if cmd.interactive_only or cname in cmd.aliases:\n-                        continue\n-                    allnames = [cname]\n-                    allnames.extend(cmd.aliases)\n-                    cname = \"/\".join(allnames)\n-                    result += formatter.format_heading(\" - \".join([cname, cmd.__doc__]))\n-                    formatter.indent()\n-                    result += \"%*s%s\\n\" % (formatter.current_indent, \"\", cmd.usage.split(\"\\n\")[0])\n-                    formatter.dedent()\n-                formatter.dedent()\n-                return result\n-        cmd_group = CommandOptionGroup(self.parser, \"Console Commands\",\n-                                       description=\"\"\"These commands can be issued from the command line.\n-                                                    They require quoting and multiple commands separated by ';'\n-                                                    e.g. Pause torrent with id 'abcd' and get information for id 'efgh':\n-                                                    `%s \\\"pause abcd; info efgh\\\"`\"\"\"\n-                                       % os.path.basename(sys.argv[0]), cmds=self.console_cmds)\n-        self.parser.add_option_group(cmd_group)\n+class ConsoleCommandParser(argparse.ArgumentParser):\n \n-    def start(self):\n-        super(Console, self).start()\n-        ConsoleUI(self.args, self.console_cmds, (self.options.daemon_addr, self.options.daemon_port,\n-                                                 self.options.daemon_user, self.options.daemon_pass))\n-\n-\n-def start():\n-    Console().start()\n-\n-\n-class DelugeHelpFormatter(optparse.IndentedHelpFormatter):\n-    \"\"\"\n-    Format help in a way suited to deluge Legacy mode - colors, format, indentation...\n-    \"\"\"\n-\n-    replace_dict = {\n-        \"<torrent-id>\": \"{!green!}%s{!input!}\",\n-        \"<state>\": \"{!yellow!}%s{!input!}\",\n-        \"\\\\.\\\\.\\\\.\": \"{!yellow!}%s{!input!}\",\n-        \"\\\\s\\\\*\\\\s\": \"{!blue!}%s{!input!}\",\n-        \"(?<![\\\\-a-z])(-[a-zA-Z0-9])\": \"{!red!}%s{!input!}\",\n-        # \"(\\-[a-zA-Z0-9])\": \"{!red!}%s{!input!}\",\n-        \"--[_\\\\-a-zA-Z0-9]+\": \"{!green!}%s{!input!}\",\n-        \"(\\\\[|\\\\])\": \"{!info!}%s{!input!}\",\n-\n-        \"<tab>\": \"{!white!}%s{!input!}\",\n-        \"[_A-Z]{3,}\": \"{!cyan!}%s{!input!}\",\n-\n-        \"<download-folder>\": \"{!yellow!}%s{!input!}\",\n-        \"<torrent-file>\": \"{!green!}%s{!input!}\"\n-\n-    }\n-\n-    def __init__(self,\n-                 indent_increment=2,\n-                 max_help_position=24,\n-                 width=None,\n-                 short_first=1):\n-        optparse.IndentedHelpFormatter.__init__(\n-            self, indent_increment, max_help_position, width, short_first)\n-\n-    def _format_colors(self, string):\n-        def r(repl):\n-            return lambda s: repl % s.group()\n-\n-        for key, replacement in self.replace_dict.items():\n-            string = re.sub(key, r(replacement), string)\n-\n-        return string\n-\n-    def format_usage(self, usage):\n-\n-        return _(\"{!info!}Usage{!input!}: %s\\n\") % self._format_colors(usage)\n-\n-    def format_option(self, option):\n-        result = []\n-        opts = self.option_strings[option]\n-        opt_width = self.help_position - self.current_indent - 2\n-        if len(opts) > opt_width:\n-            opts = \"%*s%s\\n\" % (self.current_indent, \"\", opts)\n-            opts = self._format_colors(opts)\n-            indent_first = self.help_position\n-        else:  # start help on same line as opts\n-            opts = \"%*s%-*s  \" % (self.current_indent, \"\", opt_width, opts)\n-            opts = self._format_colors(opts)\n-            indent_first = 0\n-        result.append(opts)\n-        if option.help:\n-            help_text = self.expand_default(option)\n-            help_text = self._format_colors(help_text)\n-            help_lines = optparse.textwrap.wrap(help_text, self.help_width)\n-            result.append(\"%*s%s\\n\" % (indent_first, \"\", help_lines[0]))\n-            result.extend([\"%*s%s\\n\" % (self.help_position, \"\", line)\n-                           for line in help_lines[1:]])\n-        elif opts[-1] != \"\\n\":\n-            result.append(\"\\n\")\n-        return \"\".join(result)\n-\n-\n-class OptionParser(optparse.OptionParser):\n-    \"\"\"subclass from optparse.OptionParser so exit() won't exit.\"\"\"\n-    def __init__(self, **kwargs):\n-        optparse.OptionParser.__init__(self, **kwargs)\n+    def format_help(self):\n+        \"\"\"\n+        Differs from ArgumentParser.format_help by adding the raw epilog\n+        as formatted in the string. Default bahavior mangles the formatting.\n+\n+        \"\"\"\n+        try:\n+            # Handle epilog manually to keep the text formatting\n+            epilog = self.epilog\n+            self.epilog = \"\"\n+            help = super(ConsoleCommandParser, self).format_help()","path":"deluge/ui/console/main.py","position":173,"original_position":173,"commit_id":"5429be6e81b8d05a694c90908c3ea54bc335445a","original_commit_id":"5429be6e81b8d05a694c90908c3ea54bc335445a","user":{"login":"bendikro","id":84580,"avatar_url":"https://avatars.githubusercontent.com/u/84580?v=3","gravatar_id":"","url":"https://api.github.com/users/bendikro","html_url":"https://github.com/bendikro","followers_url":"https://api.github.com/users/bendikro/followers","following_url":"https://api.github.com/users/bendikro/following{/other_user}","gists_url":"https://api.github.com/users/bendikro/gists{/gist_id}","starred_url":"https://api.github.com/users/bendikro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bendikro/subscriptions","organizations_url":"https://api.github.com/users/bendikro/orgs","repos_url":"https://api.github.com/users/bendikro/repos","events_url":"https://api.github.com/users/bendikro/events{/privacy}","received_events_url":"https://api.github.com/users/bendikro/received_events","type":"User","site_admin":false},"body":"Will fix.","created_at":"2016-04-11T13:32:30Z","updated_at":"2016-04-11T13:32:30Z","html_url":"https://github.com/deluge-torrent/deluge/pull/57#discussion_r59203703","pull_request_url":"https://api.github.com/repos/deluge-torrent/deluge/pulls/57","_links":{"self":{"href":"https://api.github.com/repos/deluge-torrent/deluge/pulls/comments/59203703"},"html":{"href":"https://github.com/deluge-torrent/deluge/pull/57#discussion_r59203703"},"pull_request":{"href":"https://api.github.com/repos/deluge-torrent/deluge/pulls/57"}}},"pull_request":{"url":"https://api.github.com/repos/deluge-torrent/deluge/pulls/57","id":56100230,"html_url":"https://github.com/deluge-torrent/deluge/pull/57","diff_url":"https://github.com/deluge-torrent/deluge/pull/57.diff","patch_url":"https://github.com/deluge-torrent/deluge/pull/57.patch","issue_url":"https://api.github.com/repos/deluge-torrent/deluge/issues/57","number":57,"state":"open","locked":false,"title":"UI option handling fixes and cleanup","user":{"login":"bendikro","id":84580,"avatar_url":"https://avatars.githubusercontent.com/u/84580?v=3","gravatar_id":"","url":"https://api.github.com/users/bendikro","html_url":"https://github.com/bendikro","followers_url":"https://api.github.com/users/bendikro/followers","following_url":"https://api.github.com/users/bendikro/following{/other_user}","gists_url":"https://api.github.com/users/bendikro/gists{/gist_id}","starred_url":"https://api.github.com/users/bendikro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bendikro/subscriptions","organizations_url":"https://api.github.com/users/bendikro/orgs","repos_url":"https://api.github.com/users/bendikro/repos","events_url":"https://api.github.com/users/bendikro/events{/privacy}","received_events_url":"https://api.github.com/users/bendikro/received_events","type":"User","site_admin":false},"body":"Includes the four commits from https://github.com/jamielennox/deluge/commits/detach-ui as well as a new commit that replaces the deprecated optparse with argparse.\r\n","created_at":"2016-01-14T21:59:55Z","updated_at":"2016-04-11T13:32:30Z","closed_at":null,"merged_at":null,"merge_commit_sha":"96552b6bdfd0d81d49f145765a8d919f3e3f9d97","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/deluge-torrent/deluge/pulls/57/commits","review_comments_url":"https://api.github.com/repos/deluge-torrent/deluge/pulls/57/comments","review_comment_url":"https://api.github.com/repos/deluge-torrent/deluge/pulls/comments{/number}","comments_url":"https://api.github.com/repos/deluge-torrent/deluge/issues/57/comments","statuses_url":"https://api.github.com/repos/deluge-torrent/deluge/statuses/5429be6e81b8d05a694c90908c3ea54bc335445a","head":{"label":"bendikro:develop-detach-ui","ref":"develop-detach-ui","sha":"5429be6e81b8d05a694c90908c3ea54bc335445a","user":{"login":"bendikro","id":84580,"avatar_url":"https://avatars.githubusercontent.com/u/84580?v=3","gravatar_id":"","url":"https://api.github.com/users/bendikro","html_url":"https://github.com/bendikro","followers_url":"https://api.github.com/users/bendikro/followers","following_url":"https://api.github.com/users/bendikro/following{/other_user}","gists_url":"https://api.github.com/users/bendikro/gists{/gist_id}","starred_url":"https://api.github.com/users/bendikro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bendikro/subscriptions","organizations_url":"https://api.github.com/users/bendikro/orgs","repos_url":"https://api.github.com/users/bendikro/repos","events_url":"https://api.github.com/users/bendikro/events{/privacy}","received_events_url":"https://api.github.com/users/bendikro/received_events","type":"User","site_admin":false},"repo":{"id":17491274,"name":"deluge","full_name":"bendikro/deluge","owner":{"login":"bendikro","id":84580,"avatar_url":"https://avatars.githubusercontent.com/u/84580?v=3","gravatar_id":"","url":"https://api.github.com/users/bendikro","html_url":"https://github.com/bendikro","followers_url":"https://api.github.com/users/bendikro/followers","following_url":"https://api.github.com/users/bendikro/following{/other_user}","gists_url":"https://api.github.com/users/bendikro/gists{/gist_id}","starred_url":"https://api.github.com/users/bendikro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bendikro/subscriptions","organizations_url":"https://api.github.com/users/bendikro/orgs","repos_url":"https://api.github.com/users/bendikro/repos","events_url":"https://api.github.com/users/bendikro/events{/privacy}","received_events_url":"https://api.github.com/users/bendikro/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/bendikro/deluge","description":"Mirror of official deluge repo at http://git.deluge-torrent.org (one way sync)","fork":true,"url":"https://api.github.com/repos/bendikro/deluge","forks_url":"https://api.github.com/repos/bendikro/deluge/forks","keys_url":"https://api.github.com/repos/bendikro/deluge/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bendikro/deluge/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bendikro/deluge/teams","hooks_url":"https://api.github.com/repos/bendikro/deluge/hooks","issue_events_url":"https://api.github.com/repos/bendikro/deluge/issues/events{/number}","events_url":"https://api.github.com/repos/bendikro/deluge/events","assignees_url":"https://api.github.com/repos/bendikro/deluge/assignees{/user}","branches_url":"https://api.github.com/repos/bendikro/deluge/branches{/branch}","tags_url":"https://api.github.com/repos/bendikro/deluge/tags","blobs_url":"https://api.github.com/repos/bendikro/deluge/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bendikro/deluge/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bendikro/deluge/git/refs{/sha}","trees_url":"https://api.github.com/repos/bendikro/deluge/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bendikro/deluge/statuses/{sha}","languages_url":"https://api.github.com/repos/bendikro/deluge/languages","stargazers_url":"https://api.github.com/repos/bendikro/deluge/stargazers","contributors_url":"https://api.github.com/repos/bendikro/deluge/contributors","subscribers_url":"https://api.github.com/repos/bendikro/deluge/subscribers","subscription_url":"https://api.github.com/repos/bendikro/deluge/subscription","commits_url":"https://api.github.com/repos/bendikro/deluge/commits{/sha}","git_commits_url":"https://api.github.com/repos/bendikro/deluge/git/commits{/sha}","comments_url":"https://api.github.com/repos/bendikro/deluge/comments{/number}","issue_comment_url":"https://api.github.com/repos/bendikro/deluge/issues/comments{/number}","contents_url":"https://api.github.com/repos/bendikro/deluge/contents/{+path}","compare_url":"https://api.github.com/repos/bendikro/deluge/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bendikro/deluge/merges","archive_url":"https://api.github.com/repos/bendikro/deluge/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bendikro/deluge/downloads","issues_url":"https://api.github.com/repos/bendikro/deluge/issues{/number}","pulls_url":"https://api.github.com/repos/bendikro/deluge/pulls{/number}","milestones_url":"https://api.github.com/repos/bendikro/deluge/milestones{/number}","notifications_url":"https://api.github.com/repos/bendikro/deluge/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bendikro/deluge/labels{/name}","releases_url":"https://api.github.com/repos/bendikro/deluge/releases{/id}","deployments_url":"https://api.github.com/repos/bendikro/deluge/deployments","created_at":"2014-03-06T20:18:55Z","updated_at":"2016-03-06T11:14:34Z","pushed_at":"2016-04-11T13:21:04Z","git_url":"git://github.com/bendikro/deluge.git","ssh_url":"git@github.com:bendikro/deluge.git","clone_url":"https://github.com/bendikro/deluge.git","svn_url":"https://github.com/bendikro/deluge","homepage":"http://deluge-torrent.org","size":64636,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"develop"}},"base":{"label":"deluge-torrent:develop","ref":"develop","sha":"73220b5116dfc31259fc83508adab38221f004a5","user":{"login":"deluge-torrent","id":6733935,"avatar_url":"https://avatars.githubusercontent.com/u/6733935?v=3","gravatar_id":"","url":"https://api.github.com/users/deluge-torrent","html_url":"https://github.com/deluge-torrent","followers_url":"https://api.github.com/users/deluge-torrent/followers","following_url":"https://api.github.com/users/deluge-torrent/following{/other_user}","gists_url":"https://api.github.com/users/deluge-torrent/gists{/gist_id}","starred_url":"https://api.github.com/users/deluge-torrent/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/deluge-torrent/subscriptions","organizations_url":"https://api.github.com/users/deluge-torrent/orgs","repos_url":"https://api.github.com/users/deluge-torrent/repos","events_url":"https://api.github.com/users/deluge-torrent/events{/privacy}","received_events_url":"https://api.github.com/users/deluge-torrent/received_events","type":"Organization","site_admin":false},"repo":{"id":17009684,"name":"deluge","full_name":"deluge-torrent/deluge","owner":{"login":"deluge-torrent","id":6733935,"avatar_url":"https://avatars.githubusercontent.com/u/6733935?v=3","gravatar_id":"","url":"https://api.github.com/users/deluge-torrent","html_url":"https://github.com/deluge-torrent","followers_url":"https://api.github.com/users/deluge-torrent/followers","following_url":"https://api.github.com/users/deluge-torrent/following{/other_user}","gists_url":"https://api.github.com/users/deluge-torrent/gists{/gist_id}","starred_url":"https://api.github.com/users/deluge-torrent/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/deluge-torrent/subscriptions","organizations_url":"https://api.github.com/users/deluge-torrent/orgs","repos_url":"https://api.github.com/users/deluge-torrent/repos","events_url":"https://api.github.com/users/deluge-torrent/events{/privacy}","received_events_url":"https://api.github.com/users/deluge-torrent/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/deluge-torrent/deluge","description":"Mirror of official deluge repo at http://git.deluge-torrent.org (one way sync)","fork":false,"url":"https://api.github.com/repos/deluge-torrent/deluge","forks_url":"https://api.github.com/repos/deluge-torrent/deluge/forks","keys_url":"https://api.github.com/repos/deluge-torrent/deluge/keys{/key_id}","collaborators_url":"https://api.github.com/repos/deluge-torrent/deluge/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/deluge-torrent/deluge/teams","hooks_url":"https://api.github.com/repos/deluge-torrent/deluge/hooks","issue_events_url":"https://api.github.com/repos/deluge-torrent/deluge/issues/events{/number}","events_url":"https://api.github.com/repos/deluge-torrent/deluge/events","assignees_url":"https://api.github.com/repos/deluge-torrent/deluge/assignees{/user}","branches_url":"https://api.github.com/repos/deluge-torrent/deluge/branches{/branch}","tags_url":"https://api.github.com/repos/deluge-torrent/deluge/tags","blobs_url":"https://api.github.com/repos/deluge-torrent/deluge/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/deluge-torrent/deluge/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/deluge-torrent/deluge/git/refs{/sha}","trees_url":"https://api.github.com/repos/deluge-torrent/deluge/git/trees{/sha}","statuses_url":"https://api.github.com/repos/deluge-torrent/deluge/statuses/{sha}","languages_url":"https://api.github.com/repos/deluge-torrent/deluge/languages","stargazers_url":"https://api.github.com/repos/deluge-torrent/deluge/stargazers","contributors_url":"https://api.github.com/repos/deluge-torrent/deluge/contributors","subscribers_url":"https://api.github.com/repos/deluge-torrent/deluge/subscribers","subscription_url":"https://api.github.com/repos/deluge-torrent/deluge/subscription","commits_url":"https://api.github.com/repos/deluge-torrent/deluge/commits{/sha}","git_commits_url":"https://api.github.com/repos/deluge-torrent/deluge/git/commits{/sha}","comments_url":"https://api.github.com/repos/deluge-torrent/deluge/comments{/number}","issue_comment_url":"https://api.github.com/repos/deluge-torrent/deluge/issues/comments{/number}","contents_url":"https://api.github.com/repos/deluge-torrent/deluge/contents/{+path}","compare_url":"https://api.github.com/repos/deluge-torrent/deluge/compare/{base}...{head}","merges_url":"https://api.github.com/repos/deluge-torrent/deluge/merges","archive_url":"https://api.github.com/repos/deluge-torrent/deluge/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/deluge-torrent/deluge/downloads","issues_url":"https://api.github.com/repos/deluge-torrent/deluge/issues{/number}","pulls_url":"https://api.github.com/repos/deluge-torrent/deluge/pulls{/number}","milestones_url":"https://api.github.com/repos/deluge-torrent/deluge/milestones{/number}","notifications_url":"https://api.github.com/repos/deluge-torrent/deluge/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/deluge-torrent/deluge/labels{/name}","releases_url":"https://api.github.com/repos/deluge-torrent/deluge/releases{/id}","deployments_url":"https://api.github.com/repos/deluge-torrent/deluge/deployments","created_at":"2014-02-20T05:04:35Z","updated_at":"2016-04-10T13:51:41Z","pushed_at":"2016-04-11T10:57:14Z","git_url":"git://github.com/deluge-torrent/deluge.git","ssh_url":"git@github.com:deluge-torrent/deluge.git","clone_url":"https://github.com/deluge-torrent/deluge.git","svn_url":"https://github.com/deluge-torrent/deluge","homepage":"http://deluge-torrent.org","size":67704,"stargazers_count":133,"watchers_count":133,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":71,"mirror_url":null,"open_issues_count":4,"forks":71,"open_issues":4,"watchers":133,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/deluge-torrent/deluge/pulls/57"},"html":{"href":"https://github.com/deluge-torrent/deluge/pull/57"},"issue":{"href":"https://api.github.com/repos/deluge-torrent/deluge/issues/57"},"comments":{"href":"https://api.github.com/repos/deluge-torrent/deluge/issues/57/comments"},"review_comments":{"href":"https://api.github.com/repos/deluge-torrent/deluge/pulls/57/comments"},"review_comment":{"href":"https://api.github.com/repos/deluge-torrent/deluge/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/deluge-torrent/deluge/pulls/57/commits"},"statuses":{"href":"https://api.github.com/repos/deluge-torrent/deluge/statuses/5429be6e81b8d05a694c90908c3ea54bc335445a"}}}}