Matt Joiner avatar Matt Joiner committed 27fd288

Rename erutor->download-torrent. Begin huge clean-up.

Comments (0)

Files changed (2)

+#!/usr/bin/env python3
+
+import logging
+
+def main():
+    import argparse
+    parser = argparse.ArgumentParser()
+    parser.add_argument('--port', default=17051, type=int)
+    parser.add_argument('torrent')
+    parser.add_argument('destination')
+    namespace = parser.parse_args()
+
+    import binascii, socket, logging, sys
+
+    logging.basicConfig(level=logging.NOTSET, stream=sys.stderr)
+
+    from lib import Torrent, Metainfo, bencode
+    import lib
+
+    metainfo = Metainfo(next(bencode.decode(open(namespace.torrent, 'rb'))))
+    data = lib.open_data(metainfo, namespace.destination)
+    logging.info('Info hash: %s', binascii.b2a_hex(metainfo.info_hash).decode())
+    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+    sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, True)
+    sock.bind(('', 0 if namespace.port is None else namespace.port))
+    sock.listen(socket.SOMAXCONN)
+    trackers = [lib.Tracker(url) for url in metainfo.tracker_urls]
+    torrent = Torrent(
+        metainfo=metainfo,
+        data=data,
+        socket=sock,
+        trackers=trackers)
+    print(str(torrent.completion() * 100) + '%')
+    torrent.run()
+
+if __name__ == '__main__':
+    main()

erutor

-#!/usr/bin/env python3
-
-import gthread
-import logging
-gthread.logger.setLevel(logging.DEBUG)
-gthread.logger.addHandler(logging.FileHandler('gthread.log'))
-
-def main():
-    import util
-    util.configure_logging()
-
-    try:
-        import argparse
-    except ImportError:
-        import optparse
-        parser = optparse.OptionParser()
-        parser.add_option('--port', default=17051, type=int)
-        namespace, pos_args = parser.parse_args()
-        namespace.torrent, namespace.destination = pos_args
-    else:
-        parser = argparse.ArgumentParser()
-        parser.add_argument('--port', default=17051, type=int)
-        parser.add_argument('torrent')
-        parser.add_argument('destination')
-        namespace = parser.parse_args()
-
-    from torrent import Torrent
-    torrent = Torrent(namespace.torrent, namespace.port, namespace.destination)
-    torrent.print_completion()
-    try:
-        torrent()
-    #~ except KeyboardInterrupt:
-        #~ pass
-    except:
-        logging.exception('Error downloading %s', torrent)
-    finally:
-        logging.critical('Shutting down...')
-        torrent.close()
-        torrent.print_completion()
-
-if __name__ == '__main__':
-    main()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.