Skip to content

Instantly share code, notes, and snippets.

@mattatcha
Forked from cas--/deluge_tracker_rename.py
Last active June 29, 2016 03:41
Show Gist options
  • Save mattatcha/2d4bdd6f0c2079b7c7521e5a2b7b0417 to your computer and use it in GitHub Desktop.
Save mattatcha/2d4bdd6f0c2079b7c7521e5a2b7b0417 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import os
import sys
import platform
import shutil
import cPickle
if platform.system() in ('Windows', 'Microsoft'):
state_file_path = os.path.join(os.environ.get('APPDATA'), 'deluge', 'state', 'torrents.state')
deluge_dir = os.path.join(os.environ['ProgramFiles'], 'Deluge')
if os.path.isdir(deluge_dir):
sys.path.append(deluge_dir)
for item in os.listdir(deluge_dir):
if item.endswith(('.egg', '.zip')):
sys.path.append(os.path.join(deluge_dir, item))
else:
state_file_path = os.path.expanduser('~/.config/deluge/state/torrents.state')
print("State file: %s" % state_file_path)
state_file = open(state_file_path, 'rb')
state = cPickle.load(state_file)
state_file.close()
state_modified = False
for torrent in state.torrents:
if torrent.auto_managed:
torrent.auto_managed = False
state_modified = True
if state_modified:
shutil.copyfile(state_file_path, state_file_path + '.old')
state_file = open(state_file_path, 'wb')
cPickle.dump(state, state_file)
state_file.close()
print("State Updated")
else:
print("Nothing to do")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment