Skip to content

Instantly share code, notes, and snippets.

@apiarian
Created April 19, 2015 11:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apiarian/d0ffef7f7e0488be5c90 to your computer and use it in GitHub Desktop.
Save apiarian/d0ffef7f7e0488be5c90 to your computer and use it in GitHub Desktop.
#! /usr/bin/env python2
# update_TransmissionBT_resumes.py
#
# Goes through the Transmission resume/ directory and changes the destinations
# of the transfers from the old_location to the new_location. This assumes that
# the transfer directories have been mirrored perfectly from the old_location
# to the new_location. TransmissionBT must not be running while this script is
# executed. More information about the resume files can be found at
# https://trac.transmissionbt.com/wiki/ResumeFile . Uses the bencode library
# available on pypi.
from bencode import *
import os, os.path
old_location = '/Volumes/Data (Alice)'
new_location = '/Volumes/Data (Bob)'
resume_directory = os.path.expanduser('~/Library/Application Support/Transmission/Resume')
resume_files = [os.path.join(resume_directory, x) for x in os.listdir(resume_directory)]
for filename in resume_files:
print 'processing "%s"'%(filename,)
with open(filename,'rb') as f:
resume_raw = f.read()
resume_decoded = bdecode(resume_raw)
resume_decoded['destination'] = resume_decoded['destination'].replace(old_location, new_location)
resume_encoded = bencode(resume_decoded)
with open(filename,'wb') as f:
f.write(resume_encoded)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment