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

All Samples(10)  |  Call(5)  |  Derive(0)  |  Import(5)
Parse bencoded files in a directory structure.

Parameters
    str     - path of directory
    {str: {str: *}}
            - dictionary, keyed by sha hash of encoded info dict, of
                torrent file metadata
    {str: [(float, int), str]}
            - dictionary, keyed by file path, of (mtime, length) pairs and
                a hash value (corresponds to keys of parsed)(more...)

        def parsedir(directory, parsed, files, blocked, exts=('.torrent',),
             return_metainfo=False, errfunc=_errfunc):
    """Parse bencoded files in a directory structure.

    Parameters
        str     - path of directory
        {str: {str: *}}
                - dictionary, keyed by sha hash of encoded info dict, of
                    torrent file metadata
        {str: [(float, int), str]}
                - dictionary, keyed by file path, of (mtime, length) pairs and
                    a hash value (corresponds to keys of parsed)
        {str}   - set of previously blocked file paths
        (str,)  - tuple of valid file extensions
        bool    - parsed metadata to include full torrent data
        f(str)  - function to process error messages

    Returns
        {str: {str: *}}
                - dictionary, keyed by sha hash of encoded info dict, of
                    torrent file metadata
        {str: [(float, int), str]}
                - dictionary, keyed by file path, of (mtime, length) pairs and
                    parsed hash value (0 if unable to parse)
        {str}   - set of file paths of unparseable or duplicate torrents
        {str: {str: *}}
                - dictionary, keyed by sha hash of encoded info dict, of
                    metadata of torrent files added during directory parse
        {str: {str: *}}
                - dictionary, keyed by sha hash of encoded info dict, of
                    metadata of torrent files removed during directory parse
    """
    new_files, torrent_type = get_files(directory, exts)

    # removed_files = (files \ new_files) U changed_files
    removed_files = {path: files[path] for path in files
                     if path not in new_files
                     or files[path][0] != new_files[path][0]}

    # Missing files are removed
    removed = {}
    for ((_mtime, _length), filehash) in removed_files.itervalues():
        removed[filehash] = parsed[filehash]

    # unchanged_files = files \ removed_files
    unchanged_files = {path: files[path] for path in files
                       if path not in removed_files}

    # Parse new files and those whose mtime or length has change
    # Block those that are unmodified but unparsed (indicates error)
    new_blocked = set()
    to_parse = []
    for path in new_files:
        if path not in unchanged_files:
            to_parse.append(path)
        elif unchanged_files[path][1] == 0:
            new_blocked.add(path)

    new_files.update(unchanged_files)

    # Keep old parsed files
    new_parsed = {infohash: parsed[infohash]
                  for ((_m, _l), infohash) in unchanged_files.itervalues()}

    # Attempt to parse new files
    added = {}
    for path in sorted(to_parse):
        try:
            torrentinfo, infohash = parse_torrent(path, return_metainfo)
            torrentinfo['type'] = torrent_type[path]
            if infohash not in new_parsed:
                new_parsed[infohash] = torrentinfo
                added[infohash] = torrentinfo
                new_files[path][1] = infohash
            else:
                # Don't warn if we've blocked before
                if path not in blocked:
                    errfunc('**warning** {} is a duplicate torrent for {}'
                            ''.format(path, new_parsed[infohash]['path']))
                new_blocked.add(path)
        except (IOError, ValueError):
            errfunc('**warning** {} has errors'.format(path))
            new_blocked.add(path)

    return (new_parsed, new_files, new_blocked, added, removed)
        


src/o/w/OwnTube-HEAD/videoportal/BitTornadoABC/BitTornado/BT1/track.py   OwnTube(Download)
from BitTornado.RawServer import RawServer, autodetect_socket_style
from BitTornado.HTTPHandler import HTTPHandler, months
from BitTornado.parsedir import parsedir
from NatCheck import NatCheck
from T2T import T2TList
    def parse_allowed(self):
        self.rawserver.add_task(self.parse_allowed, self.parse_dir_interval)
 
        if self.config['allowed_dir']:
            r = parsedir( self.config['allowed_dir'], self.allowed,

src/f/r/FriendlyTorrent-HEAD/src/tornado/BitTornado/BT1/track.py   FriendlyTorrent(Download)
from BitTornado.RawServer import RawServer, autodetect_ipv6, autodetect_socket_style
from BitTornado.HTTPHandler import HTTPHandler, months, weekdays
from BitTornado.parsedir import parsedir
from NatCheck import NatCheck, CHECK_PEER_ID_ENCRYPTED
from BitTornado.BTcrypto import CRYPTO_OK
    def parse_allowed(self):
        self.rawserver.add_task(self.parse_allowed, self.parse_dir_interval)
 
        if self.config['allowed_dir']:
            r = parsedir( self.config['allowed_dir'], self.allowed,

src/h/e/Herd-HEAD/BitTornado/BT1/track.py   Herd(Download)
from BitTornado.RawServer import RawServer, autodetect_ipv6, autodetect_socket_style
from BitTornado.HTTPHandler import HTTPHandler, months, weekdays
from BitTornado.parsedir import parsedir
from NatCheck import NatCheck
from T2T import T2TList
    def parse_allowed(self):
        self.rawserver.add_task(self.parse_allowed, self.parse_dir_interval)
 
        if self.config['allowed_dir']:
            r = parsedir( self.config['allowed_dir'], self.allowed,

src/b/i/BitTornado-HEAD/BitTornado/BT1/track.py   BitTornado(Download)
from BitTornado.RawServer import RawServer, autodetect_socket_style
from BitTornado.HTTPHandler import HTTPHandler, months
from BitTornado.parsedir import parsedir
from NatCheck import NatCheck, CHECK_PEER_ID_ENCRYPTED
from BitTornado.BTcrypto import CRYPTO_OK
    def parse_allowed(self):
        self.rawserver.add_task(self.parse_allowed, self.parse_dir_interval)
 
        if self.config['allowed_dir']:
            r = parsedir(self.config['allowed_dir'], self.allowed,

src/s/w/swarm-HEAD/BitTornado/BT1/track.py   swarm(Download)
from BitTornado.RawServer import RawServer, autodetect_ipv6, autodetect_socket_style
from BitTornado.HTTPHandler import HTTPHandler, months, weekdays
from BitTornado.parsedir import parsedir
from NatCheck import NatCheck
from T2T import T2TList
    def parse_allowed(self):
        self.rawserver.add_task(self.parse_allowed, self.parse_dir_interval)
 
        if self.config['allowed_dir']:
            r = parsedir( self.config['allowed_dir'], self.allowed,