Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(6)  |  Call(3)  |  Derive(0)  |  Import(3)
Make a .torrent file for each entry in a directory

        def completedir(directory, url, params=None, flag=None,
                progress=lambda x: None, filestat=lambda x: None):
    """Make a .torrent file for each entry in a directory"""
    if params is None:
        params = {}
    if flag is None:
        flag = threading.Event()

    files = sorted(os.listdir(directory))
    ext = '.torrent'

    togen = [os.path.join(directory, fname) for fname in files
             if (fname + ext) not in files and not fname.endswith(ext)]

    trees = [BTTree(loc, []) for loc in togen]

    def subprog(update, subtotal=[0], total=sum(tree.size for tree in trees),
                progress=progress):
        """Aggregate progress callback
        Uses static subtotal to track across files"""
        subtotal[0] += update
        progress(float(subtotal[0]) / total)

    for fname in togen:
        filestat(fname)
        try:
            base = os.path.basename(fname)
            if base not in ignore and base[0] != '.':
                subparams = params.copy()
                if 'target' in params and params['target'] != '':
                    subparams['target'] = os.path.join(params['target'],
                                                       base + ext)
                make_meta_file(fname, url, subparams, flag,
                               progress=subprog, progress_percent=False)
        except ValueError:
            print_exc()
        


src/b/i/BitTornado-HEAD/btmaketorrentgui.py   BitTornado(Download)
import os
import threading
from BitTornado.BT1.makemetafile import make_meta_file, completedir
from BitTornado.Info import MetaInfo
try:
    def complete(self):
        try:
            if self.separatetorrents:
                completedir(self.d, self.a, self.params, self.flag,
                            self.valcallback, self.filecallback)

src/b/i/BitTornado-HEAD/btcompletedirgui.py   BitTornado(Download)
import os
import threading
from BitTornado.BT1.makemetafile import completedir
try:
    from wxPython import wx
    def complete(self):
        params = {'piece_size_pow2': self.pl}
        try:
            completedir(self.d, self.a, params, self.flag, self.valcallback,
                        self.filecallback)

src/b/i/BitTornado-HEAD/btcompletedir.py   BitTornado(Download)
import sys
import os
from BitTornado.BT1.makemetafile import defaults, completedir, \
    announcelist_details
from BitTornado.parseargs import parseargs, formatDefinitions
        config, args = parseargs(argv[1:], defaults, 2, None)
        for dir in args[1:]:
            completedir(dir, args[0], config)
    except ValueError as e:
        print 'error: ' + str(e)