From d4a8f29957b9f9234a86e574823a047b5c178d98 Mon Sep 17 00:00:00 2001 From: Martijn Voncken Date: Sat, 1 Mar 2008 14:20:04 +0000 Subject: [PATCH] clean up status_fields --- deluge/ui/webui/menu_manager.py | 14 +---- deluge/ui/webui/pages.py | 5 +- deluge/ui/webui/plugin_api.py | 53 ---------------- deluge/ui/webui/pluginmanager.py | 94 +++++++++++++++++++++++++++++ deluge/ui/webui/utils.py | 39 ++++++------ deluge/ui/webui/webserver_common.py | 6 +- 6 files changed, 122 insertions(+), 89 deletions(-) delete mode 100644 deluge/ui/webui/plugin_api.py create mode 100644 deluge/ui/webui/pluginmanager.py diff --git a/deluge/ui/webui/menu_manager.py b/deluge/ui/webui/menu_manager.py index b1d4db02b..d3404045e 100644 --- a/deluge/ui/webui/menu_manager.py +++ b/deluge/ui/webui/menu_manager.py @@ -51,23 +51,20 @@ class TB: torrent = 1 torrent_list = 2 -@logcall def register_toolbar_item(id, title, image, flag, method, url, important): toolbar_items.append((id, title, image, flag, method, url, important)) #todo: remove lower hack. -@logcall def unregister_toolbar_item(item_id): for (i, toolbar) in enumerate(admin_pages): if toolbar[0] == item_id: del toolbar_items[i] #admin: -@logcall + def register_admin_page(id, title, url): admin_pages.append((id, title, url)) -@logcall def unregister_admin_page(page_id): for (i, (id, title, url)) in list(enumerate(admin_pages)): if id == page_id: @@ -75,23 +72,16 @@ def unregister_admin_page(page_id): return #detail: -@logcall + def register_detail_tab(id, title, page): detail_tabs.append((id, title, page)) -@logcall def unregister_detail_tab(tab_id): for (i, (id, title, tab)) in list(enumerate(detail_tabs)): if id == tab_id: del detail_tabs[i] return - -#def register_page -def register_page(url, method): - pass #TODO :( - - #register vars in template. template.Template.globals["admin_pages"] = admin_pages template.Template.globals["detail_tabs"] = detail_tabs diff --git a/deluge/ui/webui/pages.py b/deluge/ui/webui/pages.py index 4ce44da6c..efe7e44b8 100644 --- a/deluge/ui/webui/pages.py +++ b/deluge/ui/webui/pages.py @@ -471,8 +471,9 @@ def register_page(url, klass): urls.append(klass.__name__) page_classes[klass.__name__] = klass -def unregister_page(url, klass): - page_classes[klass.__name__] = None +def unregister_page(url): + raise NotImplemenetedError() + #page_classes[klass.__name__] = None """ class test: diff --git a/deluge/ui/webui/plugin_api.py b/deluge/ui/webui/plugin_api.py deleted file mode 100644 index 074ce9508..000000000 --- a/deluge/ui/webui/plugin_api.py +++ /dev/null @@ -1,53 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- -# -# -# Copyright (C) Martijn Voncken 2008 -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2, or (at your option) -# any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, write to: -# The Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor -# Boston, MA 02110-1301, USA. -# -# In addition, as a special exception, the copyright holders give -# permission to link the code of portions of this program with the OpenSSL -# library. -# You must obey the GNU General Public License in all respects for all of -# the code used other than OpenSSL. If you modify file(s) with this -# exception, you may extend this exception to your version of the file(s), -# but you are not obligated to do so. If you do not wish to do so, delete -# this exception statement from your version. If you delete this exception -# statement from all source files in the program, then also delete it here. -# - -import lib.webpy022 as web -import lib.newforms_plus as forms -from render import render -from utils import logcall -import page_decorators as deco - -from config import register_block as register_config_block -from config import unregister_block as unregister_config_block - -from pages import register_page, unregister_page -from pages import register_page, unregister_page - -from menu_manager import TB -from menu_manager import register_admin_page, unregister_admin_page -from menu_manager import register_toolbar_item, unregister_toolbar_item - -register_template_path = render.register_template_path -unregister_template_path = render.unregister_template_path - - diff --git a/deluge/ui/webui/pluginmanager.py b/deluge/ui/webui/pluginmanager.py new file mode 100644 index 000000000..ca191c75f --- /dev/null +++ b/deluge/ui/webui/pluginmanager.py @@ -0,0 +1,94 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# +# Copyright (C) Martijn Voncken 2008 +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, write to: +# The Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor +# Boston, MA 02110-1301, USA. +# +# In addition, as a special exception, the copyright holders give +# permission to link the code of portions of this program with the OpenSSL +# library. +# You must obey the GNU General Public License in all respects for all of +# the code used other than OpenSSL. If you modify file(s) with this +# exception, you may extend this exception to your version of the file(s), +# but you are not obligated to do so. If you do not wish to do so, delete +# this exception statement from your version. If you delete this exception +# statement from all source files in the program, then also delete it here. +# + +import deluge.component as component +import deluge.pluginmanagerbase +from deluge.configmanager import ConfigManager +from deluge.log import LOG as log + +import lib.webpy022 as web +import lib.newforms_plus as forms +from render import render +from utils import logcall +import page_decorators as deco + +import pages +import config + +from menu_manager import TB +import menu_manager + +class PluginManager(deluge.pluginmanagerbase.PluginManagerBase, + component.Component): + def __init__(self): + component.Component.__init__(self, "PluginManager") + self.config = ConfigManager("gtkui.conf") + deluge.pluginmanagerbase.PluginManagerBase.__init__( + self, "webui.conf", "deluge.plugin.webui") + + def start(self): + """Start the plugin manager""" + # Update the enabled_plugins from the core + client.get_enabled_plugins(self._on_get_enabled_plugins) + + def stop(self): + # Disable the plugins + self.disable_plugins() + + def _on_get_enabled_plugins(self, enabled_plugins): + log.debug("Core has these plugins enabled: %s", enabled_plugins) + self.config["enabled_plugins"] = enabled_plugins + + # Enable the plugins that are enabled in the config and core + self.enable_plugins() + + + register_template_path = staticmethod(render.register_template_path) + unregister_template_path = staticmethod(render.unregister_template_path) + + register_admin_page = staticmethod(menu_manager.register_admin_page) + unregister_admin_page = staticmethod(menu_manager.unregister_admin_page) + + register_toolbar_item = staticmethod(menu_manager.register_toolbar_item) + unregister_toolbar_item = staticmethod(menu_manager.register_toolbar_item) + + register_page = staticmethod(pages.register_page) + unregister_page = staticmethod(pages.unregister_page) + + register_config_form = staticmethod(config.register_block) + unregister_config_form = staticmethod(config.unregister_block) + + +__all__ = ['PluginManager','web','forms','render','logcall','deco','TB'] + + diff --git a/deluge/ui/webui/utils.py b/deluge/ui/webui/utils.py index 5a475f499..9310dc3ac 100644 --- a/deluge/ui/webui/utils.py +++ b/deluge/ui/webui/utils.py @@ -181,7 +181,7 @@ def enhance_torrent_status(torrent_id,status): status.calc_state_str = "downloading" if status.paused: status.calc_state_str= "inactive" - elif status.is_seed: + elif status.state <> 2: status.calc_state_str = "seeding" #action for torrent_pause @@ -190,20 +190,17 @@ def enhance_torrent_status(torrent_id,status): else: status.action = "stop" - if status.user_paused: - status.message = _("Paused") - elif status.paused: - status.message = _("Queued") - else: - status.message = (STATE_MESSAGES[status.state]) + status.message = (STATE_MESSAGES[status.state]) #add some pre-calculated values status.update({ "calc_total_downloaded" : (fsize(status.total_done) - + " (" + fsize(status.total_download) + ")"), - "calc_total_uploaded": (fsize(status.uploaded_memory - + status.total_payload_upload) + " (" - + fsize(status.total_upload) + ")"), + + " (" + "??" + ")" + ), + "calc_total_uploaded": (fsize( + #status.uploaded_memory + + status.total_payload_upload) + " (" + + "??" + ")"), }) #no non-unicode string may enter the templates. @@ -242,12 +239,15 @@ def get_categories(torrent_list): return categories def filter_torrent_state(torrent_list,filter_name): + #redesign filters on status field. filters = { - 'downloading': lambda t: (not t.paused and not t.is_seed) - ,'queued':lambda t: (t.paused and not t.user_paused) - ,'paused':lambda t: (t.user_paused) - ,'seeding':lambda t:(t.is_seed and not t.paused ) - ,'traffic':lambda t: (t.download_rate > 0 or t.upload_rate > 0) + 'allocating': lambda t: (t.state == 0), + 'checking': lambda t: (t.state == 1), + 'downloading': lambda t: (t.state == 2), + 'seeding':lambda t: (t.state == 3), + 'paused':lambda t: (t.state == 4), + 'error':lambda t: (t.state == 5), + 'traffic':lambda t: (t.download_rate > 0 or t.upload_rate > 0) } filter_func = filters[filter_name] return [t for t in torrent_list if filter_func(t)] @@ -263,10 +263,11 @@ def get_category_choosers(torrent_list): #static filters for title, filter_name in [ + (_('Allocating'),'allocating') , + (_('Checking'),'checking') , (_('Downloading'),'downloading') , - (_('Queued'),'queued') , - (_('Paused'),'paused') , - (_('Seeding'),'seeding'), + (_('Paused'),'paused'), + (_('Error'),'error'), (_('Traffic'),'traffic') ]: title += ' (%s)' % ( diff --git a/deluge/ui/webui/webserver_common.py b/deluge/ui/webui/webserver_common.py index 70afb2c84..7f4e1cf4c 100644 --- a/deluge/ui/webui/webserver_common.py +++ b/deluge/ui/webui/webserver_common.py @@ -78,11 +78,11 @@ TORRENT_KEYS = ['name', 'total_size', 'num_files', 'num_pieces', 'piece_length', 'total_wanted', 'tracker', 'trackers', 'tracker_status', 'save_path', 'files', 'file_priorities', 'compact', 'max_connections', 'max_upload_slots', 'max_download_speed', 'prioritize_first_last', - 'private','max_upload_speed','queue', + 'private','max_upload_speed','queue' #REMOVE: - "is_seed","total_download","total_upload","uploaded_memory", - "user_paused" + #"is_seed","total_download","total_upload","uploaded_memory", + #"user_paused" ]