[UI] Move Gtk console entry point class to __init__

To avoid unnecessarily importing modules from gtkui.py, move Gtk
console entry point class to __init__.py. This reduces load time
when showing help (deluge -h) with many hundred miliseconds

Also cleanup unnecessary WebUI code.
This commit is contained in:
bendikro 2016-05-12 20:18:58 +02:00 committed by Calum Lind
parent fd9e68e7e7
commit d6fec88932
5 changed files with 49 additions and 45 deletions

View File

@ -50,7 +50,7 @@ def load_commands(command_dir):
class Console(UI):
cmd_description = """A console or command-line interface"""
cmd_description = """Console or command-line user interface"""
def __init__(self, *args, **kwargs):
super(Console, self).__init__("console", *args, description="Test", **kwargs)

View File

@ -1,4 +1,47 @@
from deluge.ui.gtkui.gtkui import Gtk
# -*- coding: utf-8 -*-
#
# Copyright (C) 2007-2009 Andrew Resch <andrewresch@gmail.com>
#
# This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with
# the additional special exception to link portions of this program with the OpenSSL library.
# See LICENSE for more details.
#
import logging
from deluge.ui.ui import UI
log = logging.getLogger(__name__)
# Keep this class in __init__.py to avoid the console having to import everything in gtkui.py
class Gtk(UI):
cmd_description = """GTK-based graphical user interface"""
def __init__(self, *args, **kwargs):
super(Gtk, self).__init__("gtk", *args, description="Starts the Deluge GTK+ interface", **kwargs)
group = self.parser.add_argument_group(_("GTK Options"))
group.add_argument("torrents", metavar="<torrent>", nargs="*", default=None,
help=_("Add one or more torrent files, torrent URLs or magnet URIs"
" to a currently running Deluge GTK instance"))
def start(self, args=None):
super(Gtk, self).start(args)
from deluge.ui.gtkui.gtkui import GtkUI
import deluge.common
def run(options):
try:
gtkui = GtkUI(options)
gtkui.start()
except Exception as ex:
log.exception(ex)
raise
deluge.common.run_profiled(run, self.options, output_file=self.options.profile,
do_profile=self.options.profile)
def start():

View File

@ -53,7 +53,6 @@ from deluge.ui.gtkui.torrentdetails import TorrentDetails
from deluge.ui.gtkui.torrentview import TorrentView
from deluge.ui.sessionproxy import SessionProxy
from deluge.ui.tracker_icons import TrackerIcons
from deluge.ui.ui import UI
from deluge.ui.util import lang
@ -133,33 +132,6 @@ DEFAULT_PREFS = {
}
class Gtk(UI):
cmd_description = """A GTK-based graphical user interface"""
def __init__(self, *args, **kwargs):
super(Gtk, self).__init__("gtk", *args, description="Starts the Deluge GTK+ interface", **kwargs)
group = self.parser.add_argument_group(_("GTK Options"))
group.add_argument("torrents", metavar="<torrent>", nargs="*", default=None,
help=_("Add one or more torrent files, torrent URLs or magnet URIs"
" to a currently running Deluge GTK instance"))
def start(self, args=None):
super(Gtk, self).start(args)
def run(options):
try:
gtkui = GtkUI(options)
gtkui.start()
except Exception as ex:
log.exception(ex)
raise
deluge.common.run_profiled(run, self.options, output_file=self.options.profile,
do_profile=self.options.profile)
class GtkUI(object):
def __init__(self, args):
# Setup gtkbuilder/glade translation

View File

@ -2,4 +2,5 @@ from deluge.ui.web.web import Web
def start():
Web().start()
web = Web()
web.start()

View File

@ -19,19 +19,12 @@ from deluge.ui.ui import UI
log = logging.getLogger(__name__)
class WebUI(object):
def __init__(self, args):
from deluge.ui.web import server
deluge_web = server.DelugeWeb()
deluge_web.start()
class Web(UI):
cmd_description = """A web-based interface (http://localhost:8112)"""
cmd_description = """Web-based user interface (http://localhost:8112)"""
def __init__(self, *args, **kwargs):
super(Web, self).__init__("web", *args, description="Starts the Deluge web interface", **kwargs)
super(Web, self).__init__("web", *args, description="Starts the Deluge Web interface", **kwargs)
self.__server = None
group = self.parser.add_argument_group(_("Web Server Options"))
@ -65,8 +58,3 @@ class Web(UI):
log.exception(ex)
raise
run_profiled(run, output_file=self.options.profile, do_profile=self.options.profile)
def start():
web = Web()
web.start()