From a74356ce9f759f876ccb897ebeb14d8149d91579 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Sat, 27 Jan 2007 13:45:58 +0000 Subject: [PATCH] autoload (watch) a directory facility --- deluge.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/deluge.py b/deluge.py index 5671ba8e3..1c57bc1df 100644 --- a/deluge.py +++ b/deluge.py @@ -100,6 +100,8 @@ class InvalidEncodingError(DelugeError): class FilesystemError(DelugeError): pass +# Note: this may be raised both from deluge-core.cpp and deluge.py, for +# different reasons, both related to duplicate torrents class DuplicateTorrentError(DelugeError): pass @@ -330,6 +332,19 @@ class Manager: for unique_ID in self.unique_IDs: deluge_core.save_fastresume(unique_ID, self.unique_IDs[unique_ID].filename) + # Load all NEW torrents in a directory. The GUI can call this every minute or so, + # if one wants a directory to be 'watched' (personally, I think it should only be + # done on user command). + def autoload_directory(self, directory, save_dir, compact): + for filename in os.listdir(directory): + if filename[-len(".torrent"):].lower() == ".torrent": + try: + self.add_torrent_ns(self, filename, save_dir, compact) + except DuplicateTorrentError: + pass + + self.sync() + # State retrieval functions def get_state(self): @@ -560,7 +575,7 @@ class Manager: (temp, filename_short) = os.path.split(filename) if filename_short in os.listdir(self.base_dir + "/" + TORRENTS_SUBDIR): - raise DelugeError("Duplicate Torrent, it appears: " + filename_short) + raise DuplicateTorrentError("Duplicate Torrent, it appears: " + filename_short) full_new_name = self.base_dir + "/" + TORRENTS_SUBDIR + "/" + filename_short