mirror of
https://git.deluge-torrent.org/deluge
synced 2025-08-08 01:18:39 +00:00
Removed leftovers from the core autoadd. All autoadd features are now addressed by the AutoAdd plugin. NOTE: Console UI and Web UI should also remove the core auto add stuff.
This commit is contained in:
parent
fb5005e3f6
commit
f1730dc4d4
5 changed files with 5 additions and 196 deletions
|
@ -1,137 +0,0 @@
|
||||||
#
|
|
||||||
# autoadd.py
|
|
||||||
#
|
|
||||||
# Copyright (C) 2008 Andrew Resch <andrewresch@gmail.com>
|
|
||||||
#
|
|
||||||
# Deluge is free software.
|
|
||||||
#
|
|
||||||
# You may redistribute it and/or modify it under the terms of the
|
|
||||||
# GNU General Public License, as published by the Free Software
|
|
||||||
# Foundation; either version 3 of the License, or (at your option)
|
|
||||||
# any later version.
|
|
||||||
#
|
|
||||||
# deluge 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 deluge. 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 os
|
|
||||||
import logging
|
|
||||||
|
|
||||||
from deluge._libtorrent import lt
|
|
||||||
|
|
||||||
import deluge.component as component
|
|
||||||
from deluge.configmanager import ConfigManager
|
|
||||||
|
|
||||||
MAX_NUM_ATTEMPTS = 10
|
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
class AutoAdd(component.Component):
|
|
||||||
def __init__(self):
|
|
||||||
component.Component.__init__(self, "AutoAdd", depend=["TorrentManager"], interval=5)
|
|
||||||
# Get the core config
|
|
||||||
self.config = ConfigManager("core.conf")
|
|
||||||
|
|
||||||
# A list of filenames
|
|
||||||
self.invalid_torrents = []
|
|
||||||
# Filename:Attempts
|
|
||||||
self.attempts = {}
|
|
||||||
|
|
||||||
# Register set functions
|
|
||||||
self.config.register_set_function("autoadd_enable",
|
|
||||||
self._on_autoadd_enable, apply_now=True)
|
|
||||||
self.config.register_set_function("autoadd_location",
|
|
||||||
self._on_autoadd_location)
|
|
||||||
|
|
||||||
def update(self):
|
|
||||||
if not self.config["autoadd_enable"]:
|
|
||||||
# We shouldn't be updating because autoadd is not enabled
|
|
||||||
component.pause("AutoAdd")
|
|
||||||
return
|
|
||||||
|
|
||||||
# Check the auto add folder for new torrents to add
|
|
||||||
if not os.path.isdir(self.config["autoadd_location"]):
|
|
||||||
log.warning("Invalid AutoAdd folder: %s", self.config["autoadd_location"])
|
|
||||||
component.pause("AutoAdd")
|
|
||||||
return
|
|
||||||
|
|
||||||
for filename in os.listdir(self.config["autoadd_location"]):
|
|
||||||
try:
|
|
||||||
filepath = os.path.join(self.config["autoadd_location"], filename)
|
|
||||||
except UnicodeDecodeError, e:
|
|
||||||
log.error("Unable to auto add torrent due to improper filename encoding: %s", e)
|
|
||||||
continue
|
|
||||||
if os.path.isfile(filepath) and filename.endswith(".torrent"):
|
|
||||||
try:
|
|
||||||
filedump = self.load_torrent(filepath)
|
|
||||||
except (RuntimeError, Exception), e:
|
|
||||||
# If the torrent is invalid, we keep track of it so that we
|
|
||||||
# can try again on the next pass. This is because some
|
|
||||||
# torrents may not be fully saved during the pass.
|
|
||||||
log.debug("Torrent is invalid: %s", e)
|
|
||||||
if filename in self.invalid_torrents:
|
|
||||||
self.attempts[filename] += 1
|
|
||||||
if self.attempts[filename] >= MAX_NUM_ATTEMPTS:
|
|
||||||
os.rename(filepath, filepath + ".invalid")
|
|
||||||
del self.attempts[filename]
|
|
||||||
self.invalid_torrents.remove(filename)
|
|
||||||
else:
|
|
||||||
self.invalid_torrents.append(filename)
|
|
||||||
self.attempts[filename] = 1
|
|
||||||
continue
|
|
||||||
|
|
||||||
# The torrent looks good, so lets add it to the session
|
|
||||||
component.get("TorrentManager").add(filedump=filedump, filename=filename)
|
|
||||||
|
|
||||||
os.remove(filepath)
|
|
||||||
|
|
||||||
def load_torrent(self, filename):
|
|
||||||
try:
|
|
||||||
log.debug("Attempting to open %s for add.", filename)
|
|
||||||
_file = open(filename, "rb")
|
|
||||||
filedump = _file.read()
|
|
||||||
if not filedump:
|
|
||||||
raise RuntimeError, "Torrent is 0 bytes!"
|
|
||||||
_file.close()
|
|
||||||
except IOError, e:
|
|
||||||
log.warning("Unable to open %s: %s", filename, e)
|
|
||||||
raise e
|
|
||||||
|
|
||||||
# Get the info to see if any exceptions are raised
|
|
||||||
info = lt.torrent_info(lt.bdecode(filedump))
|
|
||||||
|
|
||||||
return filedump
|
|
||||||
|
|
||||||
def _on_autoadd_enable(self, key, value):
|
|
||||||
log.debug("_on_autoadd_enable")
|
|
||||||
if value:
|
|
||||||
component.resume("AutoAdd")
|
|
||||||
else:
|
|
||||||
component.pause("AutoAdd")
|
|
||||||
|
|
||||||
def _on_autoadd_location(self, key, value):
|
|
||||||
log.debug("_on_autoadd_location")
|
|
||||||
# We need to resume the component just incase it was paused due to
|
|
||||||
# an invalid autoadd location.
|
|
||||||
if self.config["autoadd_enable"]:
|
|
||||||
component.resume("AutoAdd")
|
|
|
@ -86,8 +86,6 @@ DEFAULT_PREFS = {
|
||||||
"max_upload_speed_per_torrent": -1,
|
"max_upload_speed_per_torrent": -1,
|
||||||
"max_download_speed_per_torrent": -1,
|
"max_download_speed_per_torrent": -1,
|
||||||
"enabled_plugins": [],
|
"enabled_plugins": [],
|
||||||
"autoadd_location": deluge.common.get_default_download_dir(),
|
|
||||||
"autoadd_enable": False,
|
|
||||||
"add_paused": False,
|
"add_paused": False,
|
||||||
"max_active_seeding": 5,
|
"max_active_seeding": 5,
|
||||||
"max_active_downloading": 3,
|
"max_active_downloading": 3,
|
||||||
|
|
|
@ -115,23 +115,10 @@
|
||||||
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
|
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
|
||||||
<property name="spacing">5</property>
|
<property name="spacing">5</property>
|
||||||
<child>
|
<child>
|
||||||
<widget class="GtkFileChooserButton" id="folder_autoadd">
|
<placeholder/>
|
||||||
<property name="visible">True</property>
|
|
||||||
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
|
|
||||||
<property name="action">select-folder</property>
|
|
||||||
</widget>
|
|
||||||
<packing>
|
|
||||||
<property name="position">0</property>
|
|
||||||
</packing>
|
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<widget class="GtkEntry" id="entry_autoadd">
|
<placeholder/>
|
||||||
<property name="can_focus">True</property>
|
|
||||||
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
|
|
||||||
</widget>
|
|
||||||
<packing>
|
|
||||||
<property name="position">1</property>
|
|
||||||
</packing>
|
|
||||||
</child>
|
</child>
|
||||||
</widget>
|
</widget>
|
||||||
</child>
|
</child>
|
||||||
|
@ -179,22 +166,6 @@
|
||||||
<property name="bottom_attach">2</property>
|
<property name="bottom_attach">2</property>
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
|
||||||
<widget class="GtkCheckButton" id="chk_autoadd">
|
|
||||||
<property name="label" translatable="yes">Auto add .torrents from:</property>
|
|
||||||
<property name="visible">True</property>
|
|
||||||
<property name="can_focus">True</property>
|
|
||||||
<property name="receives_default">False</property>
|
|
||||||
<property name="events">GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK</property>
|
|
||||||
<property name="draw_indicator">True</property>
|
|
||||||
<signal name="toggled" handler="on_toggle"/>
|
|
||||||
</widget>
|
|
||||||
<packing>
|
|
||||||
<property name="top_attach">2</property>
|
|
||||||
<property name="bottom_attach">3</property>
|
|
||||||
<property name="x_options">GTK_FILL</property>
|
|
||||||
</packing>
|
|
||||||
</child>
|
|
||||||
<child>
|
<child>
|
||||||
<widget class="GtkCheckButton" id="chk_move_completed">
|
<widget class="GtkCheckButton" id="chk_move_completed">
|
||||||
<property name="label" translatable="yes">Move completed to:</property>
|
<property name="label" translatable="yes">Move completed to:</property>
|
||||||
|
@ -323,6 +294,9 @@
|
||||||
<property name="x_padding">15</property>
|
<property name="x_padding">15</property>
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
|
<child>
|
||||||
|
<placeholder/>
|
||||||
|
</child>
|
||||||
</widget>
|
</widget>
|
||||||
</child>
|
</child>
|
||||||
</widget>
|
</widget>
|
||||||
|
|
|
@ -135,9 +135,6 @@ DEFAULT_PREFS = {
|
||||||
"autoconnect": False,
|
"autoconnect": False,
|
||||||
"autoconnect_host_id": None,
|
"autoconnect_host_id": None,
|
||||||
"autostart_localhost": False,
|
"autostart_localhost": False,
|
||||||
"autoadd_queued": False,
|
|
||||||
"autoadd_enable": False,
|
|
||||||
"autoadd_location": "",
|
|
||||||
"choose_directory_dialog_path": deluge.common.get_default_download_dir(),
|
"choose_directory_dialog_path": deluge.common.get_default_download_dir(),
|
||||||
"show_new_releases": True,
|
"show_new_releases": True,
|
||||||
"signal_port": 40000,
|
"signal_port": 40000,
|
||||||
|
|
|
@ -275,10 +275,6 @@ class Preferences(component.Component):
|
||||||
("active", self.core_config["del_copy_torrent_file"]),
|
("active", self.core_config["del_copy_torrent_file"]),
|
||||||
"torrent_files_button": \
|
"torrent_files_button": \
|
||||||
("filename", self.core_config["torrentfiles_location"]),
|
("filename", self.core_config["torrentfiles_location"]),
|
||||||
"chk_autoadd": \
|
|
||||||
("active", self.core_config["autoadd_enable"]),
|
|
||||||
"folder_autoadd": \
|
|
||||||
("filename", self.core_config["autoadd_location"]),
|
|
||||||
"radio_compact_allocation": \
|
"radio_compact_allocation": \
|
||||||
("active", self.core_config["compact_allocation"]),
|
("active", self.core_config["compact_allocation"]),
|
||||||
"radio_full_allocation": \
|
"radio_full_allocation": \
|
||||||
|
@ -375,11 +371,6 @@ class Preferences(component.Component):
|
||||||
self.glade.get_widget("torrent_files_button").hide()
|
self.glade.get_widget("torrent_files_button").hide()
|
||||||
core_widgets.pop("torrent_files_button")
|
core_widgets.pop("torrent_files_button")
|
||||||
core_widgets["entry_torrents_path"] = ("text", self.core_config["torrentfiles_location"])
|
core_widgets["entry_torrents_path"] = ("text", self.core_config["torrentfiles_location"])
|
||||||
|
|
||||||
self.glade.get_widget("entry_autoadd").show()
|
|
||||||
self.glade.get_widget("folder_autoadd").hide()
|
|
||||||
core_widgets.pop("folder_autoadd")
|
|
||||||
core_widgets["entry_autoadd"] = ("text", self.core_config["autoadd_location"])
|
|
||||||
else:
|
else:
|
||||||
self.glade.get_widget("entry_download_path").hide()
|
self.glade.get_widget("entry_download_path").hide()
|
||||||
self.glade.get_widget("download_path_button").show()
|
self.glade.get_widget("download_path_button").show()
|
||||||
|
@ -387,8 +378,6 @@ class Preferences(component.Component):
|
||||||
self.glade.get_widget("move_completed_path_button").show()
|
self.glade.get_widget("move_completed_path_button").show()
|
||||||
self.glade.get_widget("entry_torrents_path").hide()
|
self.glade.get_widget("entry_torrents_path").hide()
|
||||||
self.glade.get_widget("torrent_files_button").show()
|
self.glade.get_widget("torrent_files_button").show()
|
||||||
self.glade.get_widget("entry_autoadd").hide()
|
|
||||||
self.glade.get_widget("folder_autoadd").show()
|
|
||||||
|
|
||||||
# Update the widgets accordingly
|
# Update the widgets accordingly
|
||||||
for key in core_widgets.keys():
|
for key in core_widgets.keys():
|
||||||
|
@ -427,8 +416,6 @@ class Preferences(component.Component):
|
||||||
"chk_copy_torrent_file",
|
"chk_copy_torrent_file",
|
||||||
"chk_del_copy_torrent_file",
|
"chk_del_copy_torrent_file",
|
||||||
"torrent_files_button",
|
"torrent_files_button",
|
||||||
"chk_autoadd",
|
|
||||||
"folder_autoadd",
|
|
||||||
"radio_compact_allocation",
|
"radio_compact_allocation",
|
||||||
"radio_full_allocation",
|
"radio_full_allocation",
|
||||||
"chk_prioritize_first_last_pieces",
|
"chk_prioritize_first_last_pieces",
|
||||||
|
@ -589,15 +576,6 @@ class Preferences(component.Component):
|
||||||
new_core_config["torrentfiles_location"] = \
|
new_core_config["torrentfiles_location"] = \
|
||||||
self.glade.get_widget("entry_torrents_path").get_text()
|
self.glade.get_widget("entry_torrents_path").get_text()
|
||||||
|
|
||||||
new_core_config["autoadd_enable"] = \
|
|
||||||
self.glade.get_widget("chk_autoadd").get_active()
|
|
||||||
if client.is_localhost():
|
|
||||||
new_core_config["autoadd_location"] = \
|
|
||||||
self.glade.get_widget("folder_autoadd").get_filename()
|
|
||||||
else:
|
|
||||||
new_core_config["autoadd_location"] = \
|
|
||||||
self.glade.get_widget("entry_autoadd").get_text()
|
|
||||||
|
|
||||||
new_core_config["compact_allocation"] = \
|
new_core_config["compact_allocation"] = \
|
||||||
self.glade.get_widget("radio_compact_allocation").get_active()
|
self.glade.get_widget("radio_compact_allocation").get_active()
|
||||||
new_core_config["prioritize_first_last_pieces"] = \
|
new_core_config["prioritize_first_last_pieces"] = \
|
||||||
|
@ -836,7 +814,6 @@ class Preferences(component.Component):
|
||||||
"chk_move_completed" : {"move_completed_path_button" : True},
|
"chk_move_completed" : {"move_completed_path_button" : True},
|
||||||
"chk_copy_torrent_file" : {"torrent_files_button" : True,
|
"chk_copy_torrent_file" : {"torrent_files_button" : True,
|
||||||
"chk_del_copy_torrent_file" : True},
|
"chk_del_copy_torrent_file" : True},
|
||||||
"chk_autoadd" : {"folder_autoadd" : True},
|
|
||||||
"chk_seed_ratio" : {"spin_share_ratio": True,
|
"chk_seed_ratio" : {"spin_share_ratio": True,
|
||||||
"chk_remove_ratio" : True}
|
"chk_remove_ratio" : True}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue