Skip to content

Commit

Permalink
[Core] Refactor default add torrent flags into a constant
Browse files Browse the repository at this point in the history
  • Loading branch information
cas-- committed Nov 30, 2016
1 parent 915f2bf commit b69ba02
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
15 changes: 9 additions & 6 deletions deluge/core/torrentmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@

log = logging.getLogger(__name__)

LT_DEFAULT_ADD_TORRENT_FLAGS = (
lt.add_torrent_params_flags_t.flag_paused |
lt.add_torrent_params_flags_t.flag_auto_managed |
lt.add_torrent_params_flags_t.flag_update_subscribe |
lt.add_torrent_params_flags_t.flag_apply_ip_filter)


class TorrentState: # pylint: disable=old-style-class
"""Create a torrent state.
Expand Down Expand Up @@ -353,7 +359,8 @@ def add(self, torrent_info=None, state=None, options=None, save_state=True,
if options['mapped_files'] and torrent_info:
for index, fname in options['mapped_files'].items():
fname = sanitize_filepath(decode_string(fname))
log.debug('renaming file index %s to %s', index, fname)
if log.isEnabledFor(logging.DEBUG):
log.debug('renaming file index %s to %s', index, fname)
try:
torrent_info.rename_file(index, fname)
except TypeError:
Expand All @@ -377,12 +384,8 @@ def add(self, torrent_info=None, state=None, options=None, save_state=True,
if resume_data:
add_torrent_params['resume_data'] = resume_data

default_flags = (lt.add_torrent_params_flags_t.flag_paused |
lt.add_torrent_params_flags_t.flag_auto_managed |
lt.add_torrent_params_flags_t.flag_update_subscribe |
lt.add_torrent_params_flags_t.flag_apply_ip_filter)
# Set flags: enable duplicate_is_error & override_resume_data, disable auto_managed.
add_torrent_params['flags'] = ((default_flags |
add_torrent_params['flags'] = ((LT_DEFAULT_ADD_TORRENT_FLAGS |
lt.add_torrent_params_flags_t.flag_duplicate_is_error |
lt.add_torrent_params_flags_t.flag_override_resume_data) ^
lt.add_torrent_params_flags_t.flag_auto_managed)
Expand Down
3 changes: 3 additions & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ def __getattr__(cls, name):
else:
return Mock()

def __or__(self, __):
return Mock()


MOCK_MODULES = ['deluge.ui.gtkui.gtkui', 'deluge._libtorrent',
'libtorrent', 'psyco',
Expand Down

0 comments on commit b69ba02

Please sign in to comment.