root/makeatorrent.py

Revision 8db1bf9195884e757be3752e6bff1fd0e80500d3, 2.1 kB (checked in by John M. Schanck <jms07@…>, 9 months ago)

chmod u+x'd all our executable files, so they can be run with ./filename by default instead of python filename

  • Property mode set to 100755
Line 
1#!/usr/bin/env python
2
3# This program is free software: you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by
5# the Free Software Foundation, either version 3 of the License, or
6# (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11# GNU General Public License for more details.
12#
13# You should have received a copy of the GNU General Public License
14# along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
16# Written by Bram Cohen
17
18import sys
19from Anomos.makemetafile import make_meta_files
20from Anomos.parseargs import parseargs, printHelp
21from Anomos import BTFailure
22
23defaults = [
24    ('piece_size_pow2', 18,
25        "which power of 2 to set the piece size to"),
26    ('comment', '',
27        "optional human-readable comment to put in .torrent"),
28    ('target', '',
29        "optional target file for the torrent"),
30    ('filesystem_encoding', '',
31     "character encoding used on the local filesystem. If left empty, autodetected. Autodetection doesn't work under python versions older than 2.3.")
32    ]
33
34
35def dc(v):
36    print v
37
38def prog(amount):
39    print '%.1f%% complete\r' % (amount * 100),
40
41if __name__ == '__main__':
42    if len(sys.argv) <= 1:
43        printHelp('btmaketorrent', defaults)
44    else:
45        try:
46            config, args = parseargs(sys.argv[1:], defaults, 2, None)
47            print config
48            print args
49            if len(sys.argv) == 3:
50                make_meta_files(args[0], args[1:], piece_len_pow2=config['piece_size_pow2'], progressfunc=prog, filefunc=dc, comment=config['comment'], target=config['target'], filesystem_encoding=config['filesystem_encoding'])
51            else:
52                make_meta_files(args[0], args[2:], piece_len_pow2=config['piece_size_pow2'], progressfunc=prog, filefunc=dc, comment=config['comment'], target=config['target'], filesystem_encoding=config['filesystem_encoding'])
53        except BTFailure, e:
54            print str(e)
55            sys.exit(1)
Note: See TracBrowser for help on using the browser.