File: btcompletedir.py

package info (click to toggle)
debtorrent 0.1.10
  • links: PTS, VCS
  • area: main
  • in suites: squeeze, wheezy
  • size: 1,464 kB
  • ctags: 1,183
  • sloc: python: 13,703; sh: 282; makefile: 51
file content (72 lines) | stat: -rwxr-xr-x 1,874 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env python
#
# Written by Bram Cohen
# Modified by Cameron Dale
# see LICENSE.txt for license information
#
# $Id: btcompletedir.py 335 2008-01-19 22:05:46Z camrdale-guest $

"""Make a metainfo (.dtorrent) file for every file in a directory.

Creates a new metainfo file for every file in a given directory.

"""

from DebTorrent import PSYCO
if PSYCO.psyco:
    try:
        import psyco
        assert psyco.__version__ >= 0x010100f0
        psyco.full()
    except:
        pass

from sys import argv, version_info, exit
assert version_info >= (2,3), "Install Python 2.3 or greater"
from os.path import split
from DebTorrent.BT1.makemetafile import defaults, completedir, print_announcelist_details
from DebTorrent.parseargs import parseargs, formatDefinitions
import logging

logging.basicConfig()
logger = logging.getLogger()

def prog(amount):
    """Display the current status of the file scan.
    
    @type amount: C{int}
    @param amount: the number of packages that have been found so far in the
        current file
    
    """
    
    print '%d packages found\r' % amount,
    
def next_file(file):
    """Print the name of the file being scanned.
    
    @type file: C{string}
    @param file: the file name
    
    """
    
    print "\nProcessing file: %s" % file
    
if len(argv) < 2:
    a,b = split(argv[0])
    print 'Usage: ' + b + ' <dir> [dir...] [params...]'
    print 'makes a .dtorrent file for every Packages file present in each dir.'
    print
    print formatDefinitions(defaults, 80)
    print_announcelist_details()
    print ('')
    exit(2)

try:
    config, args = parseargs(argv[1:], defaults, 1, None)
    for dir in args:
        completedir(dir, config, vc = prog, fc = next_file)
except ValueError, e:
    logger.exception(str(e))
    print 'error: ' + str(e)
    print 'run with no args for parameter explanations'