Author: andar

Revision: 5780

Log:
        Remove 'state_location' and 'config_location' preferences and all 
references from the code.  We should use configmanager.get_config_dir() instead.

Diff:
Modified: trunk/deluge/core/core.py
===================================================================
--- trunk/deluge/core/core.py   2009-09-24 16:42:36 UTC (rev 5779)
+++ trunk/deluge/core/core.py   2009-09-25 00:57:22 UTC (rev 5780)
@@ -315,6 +315,8 @@
         Gets the session status values for 'keys', these keys are taking
         from libtorrent's session status.
 
+        See: http://www.rasterbar.com/products/libtorrent/manual.html#status
+
         :param keys: the keys for which we want values
         :type keys: list
         :returns: a dictionary of {key: value, ...}
@@ -658,7 +660,7 @@
         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 = open(os.path.join(deluge.configmanager.get_config_dir(), 
"plugins", filename), "wb")
         f.write(plugin_data.data)
         f.close()
         component.get("CorePluginManager").scan_for_plugins()

Modified: trunk/deluge/core/oldstateupgrader.py
===================================================================
--- trunk/deluge/core/oldstateupgrader.py       2009-09-24 16:42:36 UTC (rev 
5779)
+++ trunk/deluge/core/oldstateupgrader.py       2009-09-25 00:57:22 UTC (rev 
5780)
@@ -42,7 +42,7 @@
 
 from deluge._libtorrent import lt
 
-from deluge.configmanager import ConfigManager
+from deluge.configmanager import ConfigManager, get_config_dir
 import deluge.core.torrentmanager
 from deluge.log import LOG as log
 
@@ -69,8 +69,8 @@
 class OldStateUpgrader:
     def __init__(self):
         self.config = ConfigManager("core.conf")
-        self.state05_location = os.path.join(self.config["config_location"], 
"persistent.state")
-        self.state10_location = os.path.join(self.config["state_location"], 
"torrents.state")
+        self.state05_location = os.path.join(get_config_dir(), 
"persistent.state")
+        self.state10_location = os.path.join(get_config_dir(), "state", 
"torrents.state")
         if os.path.exists(self.state05_location) and not 
os.path.exists(self.state10_location):
             # If the 0.5 state file exists and the 1.0 doesn't, then let's 
upgrade it
             self.upgrade05()
@@ -89,7 +89,7 @@
 
         new_state = deluge.core.torrentmanager.TorrentManagerState()
         for ti, uid in state.torrents.items():
-            torrent_path = os.path.join(self.config["config_location"], 
"torrentfiles", ti.filename)
+            torrent_path = os.path.join(get_config_dir(), "torrentfiles", 
ti.filename)
             try:
                 torrent_info = None
                 log.debug("Attempting to create torrent_info from %s", 
torrent_path)
@@ -101,7 +101,7 @@
 
             # Copy the torrent file to the new location
             import shutil
-            shutil.copyfile(torrent_path, 
os.path.join(self.config["state_location"], str(torrent_info.info_hash()) + 
".torrent"))
+            shutil.copyfile(torrent_path, os.path.join(get_config_dir(), 
"state", str(torrent_info.info_hash()) + ".torrent"))
 
             # Set the file prioritiy property if not already there
             if not hasattr(ti, "priorities"):
@@ -127,7 +127,7 @@
         try:
             log.debug("Saving torrent state file.")
             state_file = open(
-                os.path.join(self.config["state_location"], "torrents.state"), 
"wb")
+                os.path.join(get_config_dir(), "state", "torrents.state"), 
"wb")
             cPickle.dump(new_state, state_file)
             state_file.close()
         except IOError, e:

Modified: trunk/deluge/core/preferencesmanager.py
===================================================================
--- trunk/deluge/core/preferencesmanager.py     2009-09-24 16:42:36 UTC (rev 
5779)
+++ trunk/deluge/core/preferencesmanager.py     2009-09-25 00:57:22 UTC (rev 
5780)
@@ -49,7 +49,6 @@
 from deluge.log import LOG as log
 
 DEFAULT_PREFS = {
-    "config_location": deluge.configmanager.get_config_dir(),
     "send_info": False,
     "info_sent": 0.0,
     "daemon_port": 58846,
@@ -61,7 +60,6 @@
     "copy_torrent_file": False,
     "torrentfiles_location": deluge.common.get_default_download_dir(),
     "plugins_location": os.path.join(deluge.configmanager.get_config_dir(), 
"plugins"),
-    "state_location": os.path.join(deluge.configmanager.get_config_dir(), 
"state"),
     "prioritize_first_last_pieces": False,
     "random_port": True,
     "dht": True,
@@ -158,8 +156,6 @@
         # Register set functions in the Config
         self.config.register_set_function("torrentfiles_location",
             self._on_set_torrentfiles_location)
-        self.config.register_set_function("state_location",
-            self._on_set_state_location)
         self.config.register_set_function("listen_ports",
             self._on_set_listen_ports)
         self.config.register_set_function("listen_interface",
@@ -246,13 +242,6 @@
             except Exception, e:
                 log.debug("Unable to make directory: %s", e)
 
-    def _on_set_state_location(self, key, value):
-        if not os.access(value, os.F_OK):
-            try:
-                os.makedirs(value)
-            except Exception, e:
-                log.debug("Unable to make directory: %s", e)
-
     def _on_set_listen_ports(self, key, value):
         # Only set the listen ports if random_port is not true
         if self.config["random_port"] is not True:

Modified: trunk/deluge/core/torrent.py
===================================================================
--- trunk/deluge/core/torrent.py        2009-09-24 16:42:36 UTC (rev 5779)
+++ trunk/deluge/core/torrent.py        2009-09-25 00:57:22 UTC (rev 5780)
@@ -42,7 +42,7 @@
 
 import deluge.common
 import deluge.component as component
-from deluge.configmanager import ConfigManager
+from deluge.configmanager import ConfigManager, get_config_dir
 from deluge.log import LOG as log
 from deluge.event import *
 
@@ -759,7 +759,7 @@
         """Writes the .fastresume file for the torrent"""
         resume_data = lt.bencode(resume_data)
         path = "%s/%s.fastresume" % (
-            self.config["state_location"],
+            os.path.join(get_config_dir(), "state"),
             self.torrent_id)
         try:
             self.delete_fastresume()
@@ -777,7 +777,7 @@
     def delete_fastresume(self):
         """Deletes the .fastresume file"""
         path = "%s/%s.fastresume" % (
-            self.config["state_location"],
+            os.path.join(get_config_dir(), "state"),
             self.torrent_id)
         log.debug("Deleting fastresume file: %s", path)
         try:
@@ -788,7 +788,7 @@
     def write_torrentfile(self):
         """Writes the torrent file"""
         path = "%s/%s.torrent" % (
-            self.config["state_location"],
+            os.path.join(get_config_dir(), "state"),
             self.torrent_id)
         log.debug("Writing torrent file: %s", path)
         try:
@@ -804,7 +804,7 @@
     def delete_torrentfile(self):
         """Deletes the .torrent file in the state"""
         path = "%s/%s.torrent" % (
-            self.config["state_location"],
+            os.path.join(get_config_dir(), "state"),
             self.torrent_id)
         log.debug("Deleting torrent file: %s", path)
         try:

Modified: trunk/deluge/core/torrentmanager.py
===================================================================
--- trunk/deluge/core/torrentmanager.py 2009-09-24 16:42:36 UTC (rev 5779)
+++ trunk/deluge/core/torrentmanager.py 2009-09-25 00:57:22 UTC (rev 5780)
@@ -52,7 +52,7 @@
 from deluge.error import *
 import deluge.common
 import deluge.component as component
-from deluge.configmanager import ConfigManager
+from deluge.configmanager import ConfigManager, get_config_dir
 from deluge.core.torrent import Torrent
 from deluge.core.torrent import TorrentOptions
 import deluge.core.oldstateupgrader
@@ -269,7 +269,7 @@
         try:
             _file = open(
                 os.path.join(
-                    self.config["state_location"],
+                    get_config_dir(), "state",
                     torrent_id + ".fastresume"),
                     "rb")
             fastresume = _file.read()
@@ -323,7 +323,7 @@
             if not state.magnet:
                 add_torrent_params["ti"] =\
                     self.get_torrent_info_from_file(
-                        os.path.join(self.config["state_location"], 
state.torrent_id + ".torrent"))
+                        os.path.join(get_config_dir(), "state", 
state.torrent_id + ".torrent"))
 
                 if not add_torrent_params["ti"]:
                     log.error("Unable to add torrent!")
@@ -412,7 +412,7 @@
         # Write the .torrent file to the state directory
         if filedump:
             try:
-                save_file = open(os.path.join(self.config["state_location"],
+                save_file = open(os.path.join(get_config_dir(), "state",
                         torrent.torrent_id + ".torrent"),
                         "wb")
                 save_file.write(filedump)
@@ -449,7 +449,7 @@
             log.debug("Attempting to open %s for add.", torrent_id)
             _file = open(
                 os.path.join(
-                    self.config["state_location"], torrent_id + ".torrent"),
+                    get_config_dir(), "state", torrent_id + ".torrent"),
                         "rb")
             filedump = lt.bdecode(_file.read())
             _file.close()
@@ -462,22 +462,22 @@
     def remove(self, torrent_id, remove_data=False):
         """
         Remove a torrent from the session.
-        
+
         :param torrent_id: the torrent to remove
         :type torrent_id: string
         :param remove_data: if True, remove the downloaded data
         :type remove_data: bool
-        
+
         :returns: True if removed successfully, False if not
         :rtype: bool
-        
+
         :raises InvalidTorrentError: if the torrent_id is not in the session
-        
+
         """
-        
+
         if torrent_id not in self.torrents:
             raise InvalidTorrentError("torrent_id not in session")
-            
+
         # Emit the signal to the clients
         component.get("EventManager").emit(PreTorrentRemovedEvent(torrent_id))
 



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"deluge-commit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/deluge-commit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to