changetracker-console.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. #!/usr/bin/env python
  2. # The contents of this file are subject to the BitTorrent Open Source License
  3. # Version 1.1 (the License). You may not copy or use this file, in either
  4. # source code or executable form, except in compliance with the License. You
  5. # may obtain a copy of the License at http://www.bittorrent.com/license/.
  6. #
  7. # Software distributed under the License is distributed on an AS IS basis,
  8. # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  9. # for the specific language governing rights and limitations under the
  10. # License.
  11. # Written by Henry 'Pi' James and Bram Cohen
  12. app_name = "BitTorrent"
  13. from BitTorrent.translation import _
  14. from os.path import basename
  15. from sys import argv, exit
  16. from BTL.bencode import bencode, bdecode
  17. if len(argv) < 3:
  18. print _("Usage: %s TRACKER_URL [TORRENTFILE [TORRENTFILE ... ] ]") % basename(argv[0])
  19. print
  20. exit(2) # common exit code for syntax error
  21. for f in argv[2:]:
  22. h = open(f, 'rb')
  23. metainfo = bdecode(h.read())
  24. h.close()
  25. if metainfo['announce'] != argv[1]:
  26. print _("old announce for %s: %s") % (f, metainfo['announce'])
  27. metainfo['announce'] = argv[1]
  28. h = open(f, 'wb')
  29. h.write(bencode(metainfo))
  30. h.close()