1
0

maketorrent-console.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 Bram Cohen
  12. app_name = "BitTorrent"
  13. from BTL.translation import _
  14. import sys
  15. import locale
  16. from BitTorrent.defaultargs import get_defaults
  17. from BitTorrent import configfile
  18. from BitTorrent.makemetafile import make_meta_files
  19. from BitTorrent.parseargs import parseargs, printHelp
  20. from BitTorrent import BTFailure
  21. defaults = get_defaults('maketorrent-console')
  22. defaults.extend([
  23. ('target', '',
  24. _("optional target file for the torrent")),
  25. ])
  26. defconfig = dict([(name, value) for (name, value, doc) in defaults])
  27. del name, value, doc
  28. def dc(v):
  29. print v
  30. def prog(amount):
  31. print '%.1f%% complete\r' % (amount * 100),
  32. if __name__ == '__main__':
  33. config, args = configfile.parse_configuration_and_args(defaults,
  34. 'maketorrent-console',
  35. sys.argv[1:], minargs=2)
  36. le = locale.getpreferredencoding()
  37. try:
  38. make_meta_files(args[0],
  39. [s.decode(le) for s in args[1:]],
  40. progressfunc=prog,
  41. filefunc=dc,
  42. piece_len_pow2=config['piece_size_pow2'],
  43. title=config['title'],
  44. comment=config['comment'],
  45. content_type=config['content_type'], # what to do in
  46. # multifile case?
  47. target=config['target'],
  48. use_tracker=config['use_tracker'],
  49. data_dir=config['data_dir'])
  50. except BTFailure, e:
  51. print unicode(e.args[0])
  52. sys.exit(1)