From c67bfe74a77e1c04bddd5d2e340b0169be756f88 Mon Sep 17 00:00:00 2001 From: Martijn Voncken Date: Thu, 25 Sep 2008 19:08:43 +0000 Subject: [PATCH] persistent sessions #486 --- deluge/core/core.py | 22 ++++++++++++---------- deluge/ui/webui/page_decorators.py | 2 +- deluge/ui/webui/utils.py | 8 ++++++-- deluge/ui/webui/webserver_common.py | 3 ++- 4 files changed, 21 insertions(+), 14 deletions(-) diff --git a/deluge/core/core.py b/deluge/core/core.py index 66e4d9596..2f4b00036 100644 --- a/deluge/core/core.py +++ b/deluge/core/core.py @@ -173,7 +173,7 @@ class Core( # Load the GeoIP DB for country look-ups self.session.load_country_db( pkg_resources.resource_filename("deluge", os.path.join("data", "GeoIP.dat"))) - + # Set the user agent self.settings = lt.session_settings() self.settings.user_agent = "Deluge %s" % deluge.common.get_version() @@ -186,7 +186,7 @@ class Core( # Load metadata extension self.session.add_extension(lt.create_metadata_plugin) self.session.add_extension(lt.create_ut_metadata_plugin) - + # Start the AlertManager self.alerts = AlertManager(self.session) @@ -363,6 +363,7 @@ class Core( 'upload_rate':float(), 'num_connections':int(), 'dht_nodes',int(), + 'free_space':float() 'max_num_connections':int(), 'max_download':float(), 'max_upload':float() @@ -374,6 +375,7 @@ class Core( "upload_rate":self.session.status().payload_upload_rate, "num_connections":self.session.num_connections(), "dht_nodes":self.session.status().dht_nodes, + "free_space":deluge.common.free_space(self.config["download_location"]), #max config values: "max_download":self.config["max_download_speed"], "max_upload":self.config["max_upload_speed"], @@ -415,7 +417,7 @@ class Core( # Run the plugin hooks for 'post_torrent_add' self.plugins.run_post_torrent_add(torrent_id) - + def export_remove_torrent(self, torrent_ids, remove_torrent, remove_data): log.debug("Removing torrent %s from the core.", torrent_ids) for torrent_id in torrent_ids: @@ -645,11 +647,11 @@ class Core( """Returns the size of the file or folder 'path' and -1 if the path is unaccessible (non-existent or insufficient privs)""" return deluge.common.get_path_size(path) - - def export_create_torrent(self, path, tracker, piece_length, comment, target, + + def export_create_torrent(self, path, tracker, piece_length, comment, target, url_list, private, created_by, httpseeds, add_to_session): - log.debug("creating torrent..") + log.debug("creating torrent..") threading.Thread(target=_create_torrent_thread, args=( path, @@ -662,7 +664,7 @@ class Core( created_by, httpseeds, add_to_session)).start() - + def _create_torrent_thread(self, path, tracker, piece_length, comment, target, url_list, private, created_by, httpseeds, add_to_session): import deluge.metafile @@ -685,16 +687,16 @@ class Core( when connecting to the daemon remotely and installing a new plugin on the client side. 'plugin_data' is a xmlrpc.Binary object of the file data, ie, plugin_file.read()""" - + f = open(os.path.join(self.config["config_location"], "plugins", filename), "wb") f.write(plugin_data.data) f.close() component.get("PluginManager").scan_for_plugins() - + def export_rescan_plugins(self): """Rescans the plugin folders for new plugins""" component.get("PluginManager").scan_for_plugins() - + ## Queueing functions ## def export_queue_top(self, torrent_ids): log.debug("Attempting to queue %s to top", torrent_ids) diff --git a/deluge/ui/webui/page_decorators.py b/deluge/ui/webui/page_decorators.py index a200a02aa..775368d74 100644 --- a/deluge/ui/webui/page_decorators.py +++ b/deluge/ui/webui/page_decorators.py @@ -48,7 +48,7 @@ def check_session(func): #check session: vars = web.input(redir_after_login = None) ck = cookies() - if ck.has_key("session_id") and ck["session_id"] in utils.SESSIONS: + if ck.has_key("session_id") and ck["session_id"] in utils.config.get("sessions"): return func(self, name) #check_session:ok elif vars.redir_after_login: utils.seeother(url("/login",redir=self_url())) diff --git a/deluge/ui/webui/utils.py b/deluge/ui/webui/utils.py index 1cf746a23..0459cfbeb 100644 --- a/deluge/ui/webui/utils.py +++ b/deluge/ui/webui/utils.py @@ -68,15 +68,19 @@ def setcookie(key, val): return w_setcookie(key, val , expires=2592000) #really simple sessions, to bad i had to implement them myself. -SESSIONS = [] def start_session(): session_id = str(random.random()) - SESSIONS.append(session_id) + config.set("sessions", config.get("sessions") + [session_id]) + if len(config.get("sessions")) > 30: #store a max of 20 sessions. + config.set("sessions",config["sessions"][:-20]) setcookie("session_id", session_id) + config.save() def end_session(): session_id = getcookie("session_id") setcookie("session_id","") + if session_id in config.get("sessions"): + config.set("sessions", config.get("sessions").append(session_id)) #/sessions def seeother(url, *args, **kwargs): diff --git a/deluge/ui/webui/webserver_common.py b/deluge/ui/webui/webserver_common.py index f899cef33..74f9a3505 100644 --- a/deluge/ui/webui/webserver_common.py +++ b/deluge/ui/webui/webserver_common.py @@ -60,5 +60,6 @@ CONFIG_DEFAULTS = { "cache_templates":True, "daemon":"http://localhost:58846", "base":"", - "disallow":{} + "disallow":{}, + "sessions":[] }