Also handle moving the torrent files after adding them besides renaming or deleting(per whatchdir)

This commit is contained in:
Pedro Algarvio 2011-04-25 16:38:49 +01:00
commit 4432e6e6e3
3 changed files with 29 additions and 15 deletions

View file

@ -60,6 +60,7 @@ OPTIONS_AVAILABLE = { #option: builtin
"enabled":False, "enabled":False,
"path":False, "path":False,
"append_extension":False, "append_extension":False,
"copy_torrent": False,
"abspath":False, "abspath":False,
"download_location":True, "download_location":True,
"max_download_speed":True, "max_download_speed":True,
@ -120,7 +121,7 @@ class Core(CorePluginBase):
def update(self): def update(self):
pass pass
@export() @export
def set_options(self, watchdir_id, options): def set_options(self, watchdir_id, options):
"""Update the options for a watch folder.""" """Update the options for a watch folder."""
watchdir_id = str(watchdir_id) watchdir_id = str(watchdir_id)
@ -192,6 +193,7 @@ class Core(CorePluginBase):
if OPTIONS_AVAILABLE.get(option): if OPTIONS_AVAILABLE.get(option):
if watchdir.get(option+'_toggle', True): if watchdir.get(option+'_toggle', True):
opts[option] = value opts[option] = value
for filename in os.listdir(watchdir["abspath"]): for filename in os.listdir(watchdir["abspath"]):
if filename.split(".")[-1] == "torrent": if filename.split(".")[-1] == "torrent":
try: try:
@ -239,6 +241,9 @@ class Core(CorePluginBase):
if not watchdir.get('append_extension'): if not watchdir.get('append_extension'):
watchdir['append_extension'] = ".added" watchdir['append_extension'] = ".added"
os.rename(filepath, filepath + watchdir['append_extension']) os.rename(filepath, filepath + watchdir['append_extension'])
elif watchdir.get('copy_torrent_toggle'):
copy_torrent_path = watchdir['copy_torrent']
os.rename(filepath, copy_torrent_path)
else: else:
os.remove(filepath) os.remove(filepath)
@ -291,7 +296,7 @@ class Core(CorePluginBase):
"""Returns the config dictionary.""" """Returns the config dictionary."""
return self.config.config return self.config.config
@export() @export
def get_watchdirs(self): def get_watchdirs(self):
return self.watchdirs.keys() return self.watchdirs.keys()
@ -303,13 +308,16 @@ class Core(CorePluginBase):
opts[key] = options[key] opts[key] = options[key]
return opts return opts
@export() @export
def add(self, options={}): def add(self, options={}):
"""Add a watch folder.""" """Add a watch folder."""
options = self._make_unicode(options) options = self._make_unicode(options)
abswatchdir = os.path.abspath(options['path']) abswatchdir = os.path.abspath(options['path'])
CheckInput(os.path.isdir(abswatchdir) , _("Path does not exist.")) CheckInput(os.path.isdir(abswatchdir) , _("Path does not exist."))
CheckInput(os.access(abswatchdir, os.R_OK|os.W_OK), "You must have read and write access to watch folder.") CheckInput(
os.access(abswatchdir, os.R_OK|os.W_OK),
"You must have read and write access to watch folder."
)
if abswatchdir in [wd['abspath'] for wd in self.watchdirs.itervalues()]: if abswatchdir in [wd['abspath'] for wd in self.watchdirs.itervalues()]:
raise Exception("Path is already being watched.") raise Exception("Path is already being watched.")
options.setdefault('enabled', False) options.setdefault('enabled', False)
@ -327,7 +335,8 @@ class Core(CorePluginBase):
def remove(self, watchdir_id): def remove(self, watchdir_id):
"""Remove a watch folder.""" """Remove a watch folder."""
watchdir_id = str(watchdir_id) watchdir_id = str(watchdir_id)
CheckInput(watchdir_id in self.watchdirs, "Unknown Watchdir: %s" % self.watchdirs) CheckInput(watchdir_id in self.watchdirs,
"Unknown Watchdir: %s" % self.watchdirs)
if self.watchdirs[watchdir_id]['enabled']: if self.watchdirs[watchdir_id]['enabled']:
self.disable_watchdir(watchdir_id) self.disable_watchdir(watchdir_id)
del self.watchdirs[watchdir_id] del self.watchdirs[watchdir_id]
@ -338,3 +347,7 @@ class Core(CorePluginBase):
for watchdir_id in config['watchdirs'].iterkeys(): for watchdir_id in config['watchdirs'].iterkeys():
config['watchdirs'][watchdir_id]['owner'] = 'localclient' config['watchdirs'][watchdir_id]['owner'] = 'localclient'
return config return config
### XXX: Handle torrent finished / remove torrent file per whatchdir
### deluge/core/torrentmanager.py:
### filename = self.torrents[torrent_id].filename

View file

@ -295,7 +295,6 @@
<widget class="GtkFileChooserButton" id="copy_torrent_chooser"> <widget class="GtkFileChooserButton" id="copy_torrent_chooser">
<property name="visible">True</property> <property name="visible">True</property>
<property name="action">select-folder</property> <property name="action">select-folder</property>
<property name="show_hidden">True</property>
<property name="title" translatable="yes">Select A Folder</property> <property name="title" translatable="yes">Select A Folder</property>
</widget> </widget>
<packing> <packing>

View file

@ -90,9 +90,6 @@ class OptionsDialog():
self.load_options(options) self.load_options(options)
# Not implemented feateures present in UI # Not implemented feateures present in UI
self.glade.get_widget("copy_torrent_toggle").hide()
self.glade.get_widget("copy_torrent_entry").hide()
self.glade.get_widget("copy_torrent_chooser").hide()
self.glade.get_widget("delete_copy_torrent_toggle").hide() self.glade.get_widget("delete_copy_torrent_toggle").hide()
self.dialog.run() self.dialog.run()
@ -108,6 +105,9 @@ class OptionsDialog():
self.glade.get_widget('download_location_toggle').set_active( self.glade.get_widget('download_location_toggle').set_active(
options.get('download_location_toggle', False) options.get('download_location_toggle', False)
) )
self.glade.get_widget('copy_torrent_toggle').set_active(
options.get('copy_torrent_toggle', False)
)
self.accounts.clear() self.accounts.clear()
self.labels.clear() self.labels.clear()
combobox = self.glade.get_widget('OwnerCombobox') combobox = self.glade.get_widget('OwnerCombobox')
@ -137,7 +137,7 @@ class OptionsDialog():
for field in ['move_completed_path', 'path', 'download_location', for field in ['move_completed_path', 'path', 'download_location',
'copy_torrent']: 'copy_torrent']:
if client.is_localhost(): if client.is_localhost():
self.glade.get_widget(field+"_chooser").set_filename( self.glade.get_widget(field+"_chooser").set_current_folder(
options.get(field, os.path.expanduser("~")) options.get(field, os.path.expanduser("~"))
) )
self.glade.get_widget(field+"_chooser").show() self.glade.get_widget(field+"_chooser").show()
@ -268,19 +268,21 @@ class OptionsDialog():
options['path'] = self.glade.get_widget('path_chooser').get_filename() options['path'] = self.glade.get_widget('path_chooser').get_filename()
options['download_location'] = self.glade.get_widget('download_location_chooser').get_filename() options['download_location'] = self.glade.get_widget('download_location_chooser').get_filename()
options['move_completed_path'] = self.glade.get_widget('move_completed_path_chooser').get_filename() options['move_completed_path'] = self.glade.get_widget('move_completed_path_chooser').get_filename()
options['copy_torrent'] = self.glade.get_widget('copy_torrent_chooser').get_filename()
else: else:
options['path'] = self.glade.get_widget('path_entry').get_text() options['path'] = self.glade.get_widget('path_entry').get_text()
options['download_location'] = self.glade.get_widget('download_location_entry').get_text() options['download_location'] = self.glade.get_widget('download_location_entry').get_text()
options['move_completed_path'] = self.glade.get_widget('move_completed_path_entry').get_text() options['move_completed_path'] = self.glade.get_widget('move_completed_path_entry').get_text()
options['copy_torrent'] = self.glade.get_widget('copy_torrent_entry').get_text()
options['label'] = self.glade.get_widget('label').child.get_text().lower()
options['append_extension'] = self.glade.get_widget('append_extension').get_text()
options['owner'] = self.accounts[ options['owner'] = self.accounts[
self.glade.get_widget('OwnerCombobox').get_active()][0] self.glade.get_widget('OwnerCombobox').get_active()][0]
options['append_extension_toggle'] = self.glade.get_widget('append_extension_toggle').get_active() for key in ['append_extension_toggle', 'download_location_toggle',
options['append_extension'] = self.glade.get_widget('append_extension').get_text() 'label_toggle', 'copy_torrent_toggle']:
options['download_location_toggle'] = self.glade.get_widget('download_location_toggle').get_active() options[key] = self.glade.get_widget(key).get_active()
options['label'] = self.glade.get_widget('label').child.get_text().lower()
options['label_toggle'] = self.glade.get_widget('label_toggle').get_active()
for id in self.spin_ids: for id in self.spin_ids:
options[id] = self.glade.get_widget(id).get_value() options[id] = self.glade.get_widget(id).get_value()