~ubuntu-branches/ubuntu/precise/bittornado/precise

« back to all changes in this revision

Viewing changes to .pc/32_use_hashlib_for_sha.patch/btshowmetainfo.py

  • Committer: Barry Warsaw
  • Date: 2011-08-10 23:17:46 UTC
  • mfrom: (7.1.1 bittornado)
  • Revision ID: barry@python.org-20110810231746-5buiob6p54m266s8
Tags: 0.3.18-10ubuntu2
* switch to dh_python2 (LP: #788514)
  - install btmakemetafile.py and btcompletedir.py via pyinstall
  - add build depend on python-all
  - bump debhelper depend to 7 for dh_auto_install

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
 
 
3
# Written by Henry 'Pi' James and Loring Holden
 
4
# modified for multitracker display by John Hoffman
 
5
# see LICENSE.txt for license information
 
6
 
 
7
from sys import *
 
8
from os.path import *
 
9
from sha import *
 
10
from BitTornado.bencode import *
 
11
 
 
12
NAME, EXT = splitext(basename(argv[0]))
 
13
VERSION = '20030621'
 
14
 
 
15
print '%s %s - decode BitTorrent metainfo files' % (NAME, VERSION)
 
16
print
 
17
 
 
18
if len(argv) == 1:
 
19
    print '%s file1.torrent file2.torrent file3.torrent ...' % argv[0]
 
20
    print
 
21
    exit(2) # common exit code for syntax error
 
22
 
 
23
for metainfo_name in argv[1:]:
 
24
    print 'metainfo file.: %s' % basename(metainfo_name)
 
25
 
 
26
    metainfo_file = open(metainfo_name, 'rb')
 
27
    metainfo = metainfo_file.read()
 
28
    metainfo_file.close()
 
29
    metainfo = bdecode(metainfo)
 
30
    try:    
 
31
        info = metainfo['info']
 
32
        info_hash = sha(bencode(info))
 
33
 
 
34
        print 'info hash.....: %s' % info_hash.hexdigest()
 
35
        piece_length = info['piece length']
 
36
        if info.has_key('length'):
 
37
            # let's assume we just have a file
 
38
            print 'file name.....: %s' % info['name']
 
39
            file_length = info['length']
 
40
            name ='file size.....:'
 
41
        else:
 
42
            # let's assume we have a directory structure
 
43
            print 'directory name: %s' % info['name']
 
44
            print 'files.........: '
 
45
            file_length = 0;
 
46
            for file in info['files']:
 
47
                path = ''
 
48
                for item in file['path']:
 
49
                    if (path != ''):
 
50
                       path = path + "/"
 
51
                    path = path + item
 
52
                print '   %s (%d)' % (path, file['length'])
 
53
                file_length += file['length']
 
54
                name ='archive size..:'
 
55
        piece_number, last_piece_length = divmod(file_length, piece_length)
 
56
        print '%s %i (%i * %i + %i)' \
 
57
              % (name,file_length, piece_number, piece_length, last_piece_length)
 
58
        if metainfo.has_key('announce'):
 
59
            print 'announce url..: %s' % metainfo['announce']
 
60
        else:
 
61
            print '***WARNING*** - no announce key'
 
62
        if metainfo.has_key('announce-list'):
 
63
            list = []
 
64
            for tier in metainfo['announce-list']:
 
65
                for tracker in tier:
 
66
                    list+=[tracker,',']
 
67
                del list[-1]
 
68
                list+=['|']
 
69
            del list[-1]
 
70
            liststring = ''
 
71
            for i in list:
 
72
                liststring+=i
 
73
            print 'announce-list.: %s' % liststring
 
74
        if metainfo.has_key('httpseeds'):
 
75
            list = []
 
76
            for seed in metainfo['httpseeds']:
 
77
                list += [seed,'|']
 
78
            del list[-1]
 
79
            liststring = ''
 
80
            for i in list:
 
81
                liststring+=i
 
82
            print 'http seeds....: %s' % liststring
 
83
        if metainfo.has_key('comment'):
 
84
            print 'comment.......: %s' % metainfo['comment']
 
85
 
 
86
    except:
 
87
        print '***ERROR*** - metainfo out of spec'