File: btrename.py

package info (click to toggle)
debtorrent 0.1.9
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 1,452 kB
  • ctags: 1,183
  • sloc: python: 13,526; sh: 274; makefile: 51
file content (43 lines) | stat: -rwxr-xr-x 1,046 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env python
#
# Written by Henry 'Pi' James
# Modified by Cameron Dale
# see LICENSE.txt for license information
#
# $Id: btrename.py 71 2007-05-29 05:58:07Z camrdale-guest $

"""Change the name field in a metainfo file.

Rename the directory that will be created (suggested) when the metainfo file's
download is started.

"""

from sys import *
from os.path import *
from sha import *
from DebTorrent.bencode import *

NAME, EXT = splitext(basename(argv[0]))
VERSION = '20021119'

print '%s %s - change the suggested filename in a .dtorrent file' % (NAME, VERSION)
print

if len(argv) != 3:
  print '%s file.dtorrent new.filename.ext' % argv[0]
  print
  exit(2) # common exit code for syntax error

metainfo_file = open(argv[1], 'rb')
metainfo = bdecode(metainfo_file.read())
metainfo_file.close()
print 'old filename: %s' % metainfo['name']
metainfo['name'] = argv[2]
print 'new filename: %s' % metainfo['name']
metainfo_file = open(argv[1], 'wb')
metainfo_file.write(bencode(metainfo))
metainfo_file.close
print
print 'done.'
print