def main(self): print "TorrentClient.run" """Main loop""" uiname = 'bittorrent-console' defaults = get_defaults(uiname) defaults.append(( 'twisted', 0, _("Use Twisted network libraries for network connections. 1 means use twisted, 0 means do not use twisted, -1 means autodetect, and prefer twisted" ))) metainfo = None config, args = configfile.parse_configuration_and_args( defaults, uiname) try: metainfo, errors = GetTorrent.get(self.torrentfilename) if errors: raise BTFailure( _("Error reading .torrent file: ") + '\n'.join(errors)) else: self.dl = DLKamaelia(metainfo, config, self) self.dl.run() except BTFailure, e: print str(e) sys.exit(1)
def main(self): """\ Start the Mainline client and block forever listening for connectons """ uiname = "bittorrent-console" defaults = get_defaults(uiname) config, args = configfile.parse_configuration_and_args( defaults, uiname) config = Preferences().initWithDict(config) data_dir = config['data_dir'] self.core_doneflag = DeferredEvent() self.rawserver_doneflag = DeferredEvent() rawserver = RawServer(config) #event and I/O scheduler self.multitorrent = MultiTorrent( config, rawserver, data_dir) #class used to add, control and remove torrents self.tick() #add periodic function call rawserver.add_task(0, self.core_doneflag.addCallback, lambda r: rawserver.external_add_task(0, shutdown)) rawserver.listen_forever( self.rawserver_doneflag) # runs until the component terminates self.send(producerFinished(self), "signal") print "TorrentClient has shutdown"
def main(useHelper=False): defaults = get_defaults('bittorrent-console') config, args = configfile.parse_configuration_and_args(defaults, 'iTorrent', sys.argv[1:], 0, 0) config = Preferences().initWithDict(config) config['tracker_proxy'] = config['http_proxy'] display = Display() btControl = BTControl(config, display) os.chdir(config['data_dir']) prefix = 'http://localhost' if config['control_port'] != 80: prefix += ':%d' % config['control_port'] prefix += '/' # TODO: iTunes drops the connection to a torrent download if a concurrent update takes too long. Figure out what the problem is. (Might have been hangups due to DNS queries) # TODO: make sure we don't buffer up too much data from socket connections and chew up megabytes of memory. # TODO: Allow configuration and feeds.yaml to be re-loaded during runtime. Resolver.startResolverThread(btControl.rawServer) server = HTTPServer(btControl.rawServer, display, btControl, config, useHelper) # TODO: FeedStore should be passed to HTTPServer, not created by it utils.tidyDataDir(config['data_dir'], server.feedStore, btControl.rawServer) btControl.rawServer.install_sigint_handler() if useHelper: btControl.rawServer.add_task(MacLauncher.startHelper, 0, (config['control_port'], server.address[1], btControl)) btControl.rawServer.add_task(display.info, 0, ('Ready on ' + prefix,)) btControl.start()
def main(self): print "TorrentClient.run" """Main loop""" uiname = "bittorrent-console" defaults = get_defaults(uiname) defaults.append( ( "twisted", 0, _( "Use Twisted network libraries for network connections. 1 means use twisted, 0 means do not use twisted, -1 means autodetect, and prefer twisted" ), ) ) metainfo = None config, args = configfile.parse_configuration_and_args(defaults, uiname) try: metainfo, errors = GetTorrent.get(self.torrentfilename) if errors: raise BTFailure(_("Error reading .torrent file: ") + "\n".join(errors)) else: self.dl = DLKamaelia(metainfo, config, self) self.dl.run() except BTFailure, e: print str(e) sys.exit(1)
def track(args): assert type(args) == list and \ len([x for x in args if type(x)==str])==len(args) config = {} defaults = get_defaults('bittorrent-tracker') # hard-coded defaults. try: config, files = parse_configuration_and_args(defaults, 'bittorrent-tracker', args, 0, 0 ) except ValueError, e: print _("error: ") + str_exc(e) print _("run with -? for parameter explanations") return
def main(self): print "TorrentClient.run" """Main loop""" uiname = 'bittorrent-console' defaults = get_defaults(uiname) defaults["twisted"] = 0 metainfo = None config, args = configfile.parse_configuration_and_args(defaults, uiname) try: metainfo, errors = GetTorrent.get( self.torrentfilename ) if errors: raise BTFailure(_("Error reading .torrent file: ") + '\n'.join(errors)) else: self.dl = DLKamaelia(metainfo, config, self) self.dl.run() except BTFailure, e: print str(e) sys.exit(1)
def main(self): print "TorrentClient.run" """Main loop""" uiname = 'bittorrent-console' defaults = get_defaults(uiname) defaults["twisted"] = 0 metainfo = None config, args = configfile.parse_configuration_and_args( defaults, uiname) try: metainfo, errors = GetTorrent.get(self.torrentfilename) if errors: raise BTFailure( _("Error reading .torrent file: ") + '\n'.join(errors)) else: self.dl = DLKamaelia(metainfo, config, self) self.dl.run() except BTFailure, e: print str(e) sys.exit(1)
def main(self): """\ Start the Mainline client and block indefinitely, listening for connectons. """ uiname = "bittorrent-console" defaults = get_defaults(uiname) config, args = configfile.parse_configuration_and_args(defaults, uiname) config = Preferences().initWithDict(config) data_dir = config['data_dir'] self.core_doneflag = DeferredEvent() self.rawserver_doneflag = DeferredEvent() rawserver = RawServer(config) #event and I/O scheduler self.multitorrent = MultiTorrent(config, rawserver, data_dir) #class used to add, control and remove torrents self.tick() #add periodic function call rawserver.add_task(0, self.core_doneflag.addCallback, lambda r: rawserver.external_add_task(0, shutdown)) rawserver.listen_forever(self.rawserver_doneflag) # runs until the component terminates self.send(producerFinished(self), "signal")
def __init__(self,url,save_in,selfish=1): self.status = 0 if __btversion__ >= 4.2: uiname = 'bittorrent-console' else: uiname = 'btdownloadheadless' defaults = get_defaults(uiname) try: config, args = configfile.parse_configuration_and_args(defaults, uiname) config["url"] = url config["save_in"] = save_in config["selfish"] = selfish if args: if config['responsefile']: raise BTFailure, 'must have responsefile as arg or ' \ 'parameter, not both' config['responsefile'] = args[0] try: if config['responsefile']: h = file(config['responsefile'], 'rb') metainfo = h.read() h.close() elif config['url']: h = urlopen(config['url']) metainfo = h.read() h.close() else: raise BTFailure('you need to specify a .torrent file') except IOError, e: raise BTFailure('Error reading .torrent file: ', str(e)) except BTFailure, e: print str(e) self.status = 1
def run(argv=[]): config, args = configfile.parse_configuration_and_args( defaults, 'maketorrent', argv, 0, None) # BUG: hack to make verbose mode be the default config['verbose'] = not config['verbose'] MainLoop(config)
if __name__ == '__main__': uiname = 'launchmany-console' defaults = get_defaults(uiname) try: if len(sys.argv) < 2: printHelp(uiname, defaults) sys.exit(1) # Modifying default values from get_defaults is annoying... # Implementing specific default values for each uiname in # defaultargs.py is even more annoying. --Dave ddir = os.path.join(platform.get_dot_dir(), "launchmany-console") ddir = decode_from_filesystem(ddir) modify_default(defaults, 'data_dir', ddir) config, args = configfile.parse_configuration_and_args( defaults, uiname, sys.argv[1:], 0, 1) # returned from here config['save_in'] is /home/dave/Desktop/... if args: torrent_dir = args[0] config['torrent_dir'] = decode_from_filesystem(torrent_dir) else: torrent_dir = config['torrent_dir'] torrent_dir, bad = encode_for_filesystem(torrent_dir) if bad: raise BTFailure( _("Warning: ") + config['torrent_dir'] + _(" is not a directory")) if not os.path.isdir(torrent_dir): raise BTFailure(
from BitTorrent import PiecePicker psyco.bind(PiecePicker.PieceBuckets) psyco.bind(PiecePicker.PiecePicker) from BitTorrent import PieceSetBuckets psyco.bind(PieceSetBuckets.PieceSetBuckets) psyco.bind(PieceSetBuckets.SortedPieceBuckets) psyco.profile(memorymax=30000) # that's 30MB for the whole process #psyco.log() # see below for more except ImportError: pass zurllib.add_unsafe_thread() try: config, args = configfile.parse_configuration_and_args( defaults, 'bittorrent', sys.argv[1:], 0, None) if debug: config['upnp'] = False config['one_connection_per_ip'] = False except BTFailure, e: print unicode(e.args[0]) sys.exit(1) config = Preferences().initWithDict(config) # bug set in DownloadInfoFrame rawserver = RawServer(config) zurllib.set_zurllib_rawserver(rawserver) rawserver.install_sigint_handler()
# Copyright 2005 (C) Sune Kirkeby -- Licensed under the "X11 License" # BitTorrent is a stinking heap of dung, so I have to # work around it with these hacks, import sys if not hasattr(sys, 'argv'): sys.argv = ['/usr/bin/python'] import BitTorrent import BitTorrent.configfile del sys.argv from BitTorrent import ConvertedMetainfo from BitTorrent.defaultargs import get_defaults from BitTorrent import configfile uiname = 'btdownloadheadless' defaults = get_defaults(uiname) config, _ = configfile.parse_configuration_and_args(defaults, uiname, [], 0, 1) ConvertedMetainfo.set_filesystem_encoding('utf-8', None)
try: checkDir(saveLocation) params = [ "--url", torrent, "--max_upload_rate", maxUploadRate, "--minport", iPXSettings.torrentMinPort, "--maxport", iPXSettings.torrentMinPort, "--save_as", saveLocation + "/" + saveName, ] config, args = configfile.parse_configuration_and_args(defaults, uiname, params, 0, 1) if config["url"]: h = urlopen(config["url"]) metainfo = h.read() h.close() except Exception, msg: logIt("Torrent Download Failed") logIt("ERRORMSG: %s" % str(msg)) status = 0 try: dl = DL(metainfo, config) dl.run() if globals()["torrentStatus"] == 1: logIt("Completed Download: %s" % saveName)
def getTorrent(feedName, torrent, maxUploadRate, saveLocation, saveName): from BitTorrent.download import Feedback, Multitorrent from BitTorrent.defaultargs import get_defaults from BitTorrent.parseargs import printHelp from BitTorrent.zurllib import urlopen from BitTorrent.bencode import bdecode from BitTorrent.ConvertedMetainfo import ConvertedMetainfo from BitTorrent import configfile from BitTorrent import BTFailure from BitTorrent import version import re, threading uiname = "bittorrent-console" defaults = get_defaults(uiname) config, args = configfile.parse_configuration_and_args(defaults, uiname, "", 0, 1) def fmtsize(n): return float(n) class DL(Feedback): def __init__(self, metainfo, config): self.doneflag = threading.Event() self.metainfo = metainfo self.config = config logIt("BT url: %s" % self.config["url"]) logIt("BT save_as: %s" % self.config["save_as"]) if self.config["max_upload_rate"] > 0: logIt("BT max_upload_rate: %s" % str(self.config["max_upload_rate"])) def run(self): import os try: config = self.config self.d = HeadlessDisplayer(self.doneflag) self.multitorrent = Multitorrent(self.config, self.doneflag, self.global_error) # raises BTFailure if bad metainfo = ConvertedMetainfo(bdecode(self.metainfo)) torrent_name = metainfo.name_fs if config["save_as"]: if config["save_in"]: raise BTFailure("You cannot specify both --save_as and " "--save_in") saveas = config["save_as"] elif config["save_in"]: saveas = os.path.join(config["save_in"], torrent_name) else: saveas = torrent_namef self.d.set_torrent_values( metainfo.name, os.path.abspath(saveas), metainfo.total_bytes, len(metainfo.hashes) ) self.torrent = self.multitorrent.start_torrent(metainfo, self.config, self, saveas) except BTFailure, e: globals()["torrentStatus"] = 0 logIt(str(e)) return self.get_status() self.multitorrent.rawserver.listen_forever() self.d.display({"activity": "shutting down", "fractionDone": 0}) self.torrent.shutdown() def reread_config(self): try: newvalues = configfile.get_config(self.config, "btdownloadcurses") except Exception, e: globals()["torrentStatus"] = 0 self.d.error("Error reading config: " + str(e)) return self.config.update(newvalues) # The set_option call can potentially trigger something that kills # the torrent (when writing this the only possibility is a change in # max_files_open causing an IOError while closing files), and so # the self.failed() callback can run during this loop. for option, value in newvalues.iteritems(): self.multitorrent.set_option(option, value) for option, value in newvalues.iteritems(): self.torrent.set_option(option, value)
def run(argv=[]): config, args = configfile.parse_configuration_and_args(defaults, 'maketorrent', argv, 0, None) # BUG: hack to make verbose mode be the default config['verbose'] = not config['verbose'] MainLoop(config)
from BitTorrent import PiecePicker psyco.bind(PiecePicker.PieceBuckets) psyco.bind(PiecePicker.PiecePicker) from BitTorrent import PieceSetBuckets psyco.bind(PieceSetBuckets.PieceSetBuckets) psyco.bind(PieceSetBuckets.SortedPieceBuckets) psyco.profile(memorymax=30000) # that's 30MB for the whole process #psyco.log() # see below for more except ImportError: pass zurllib.add_unsafe_thread() try: config, args = configfile.parse_configuration_and_args(defaults, 'bittorrent', sys.argv[1:], 0, None) if debug: config['upnp'] = False config['one_connection_per_ip'] = False except BTFailure, e: print unicode(e.args[0]) sys.exit(1) config = Preferences().initWithDict(config) # bug set in DownloadInfoFrame rawserver = RawServer(config) zurllib.set_zurllib_rawserver(rawserver) rawserver.install_sigint_handler()
_("optional target file for the torrent")), ]) defconfig = dict([(name, value) for (name, value, doc) in defaults]) del name, value, doc def dc(v): print v def prog(amount): print '%.1f%% complete\r' % (amount * 100), if __name__ == '__main__': config, args = configfile.parse_configuration_and_args(defaults, 'maketorrent-console', sys.argv[1:], minargs=2) le = locale.getpreferredencoding() try: url_list = None if config.get('url'): url_list = [config['url']] make_meta_files(args[0], [s.decode(le) for s in args[1:]], url_list=url_list, progressfunc=prog, filefunc=dc, piece_len_pow2=config['piece_size_pow2'], title=config['title'],
]) defconfig = dict([(name, value) for (name, value, doc) in defaults]) del name, value, doc def dc(v): print v def prog(amount): print '%.1f%% complete\r' % (amount * 100), if __name__ == '__main__': config, args = configfile.parse_configuration_and_args( defaults, 'maketorrent-console', sys.argv[1:], 0, None) if len(sys.argv) <= 1: printHelp('maketorrent-console', defaults) else: try: make_meta_files(args[0], args[1:], progressfunc=prog, filefunc=dc, piece_len_pow2=config['piece_size_pow2'], comment=config['comment'], target=config['target'], filesystem_encoding=config['filesystem_encoding'], use_tracker=config['use_tracker'], data_dir=config['data_dir'])
if __name__ == '__main__': uiname = 'launchmany-console' defaults = get_defaults(uiname) try: if len(sys.argv) < 2: printHelp(uiname, defaults) sys.exit(1) # Modifying default values from get_defaults is annoying... # Implementing specific default values for each uiname in # defaultargs.py is even more annoying. --Dave ddir = os.path.join( platform.get_dot_dir(), "launchmany-console" ) ddir = decode_from_filesystem(ddir) modify_default(defaults, 'data_dir', ddir) config, args = configfile.parse_configuration_and_args(defaults, uiname, sys.argv[1:], 0, 1) # returned from here config['save_in'] is /home/dave/Desktop/... if args: torrent_dir = args[0] config['torrent_dir'] = decode_from_filesystem(torrent_dir) else: torrent_dir = config['torrent_dir'] torrent_dir,bad = encode_for_filesystem(torrent_dir) if bad: raise BTFailure(_("Warning: ")+config['torrent_dir']+ _(" is not a directory")) if not os.path.isdir(torrent_dir): raise BTFailure(_("Warning: ")+torrent_dir+ _(" is not a directory"))
def run(): config, args = configfile.parse_configuration_and_args(defaults, 'maketorrent', [], 0, None) MainWindow(config)