⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 launchmany-console.py

📁 bittorrent source by python. please enjoy
💻 PY
字号:
#!/usr/bin/env python# The contents of this file are subject to the BitTorrent Open Source License# Version 1.1 (the License).  You may not copy or use this file, in either# source code or executable form, except in compliance with the License.  You# may obtain a copy of the License at http://www.bittorrent.com/license/.## Software distributed under the License is distributed on an AS IS basis,# WITHOUT WARRANTY OF ANY KIND, either express or implied.  See the License# for the specific language governing rights and limitations under the# License.# Written by John Hoffmanif __name__ == '__main__':    from BitTorrent.translation import _import sysimport osfrom BitTorrent import platformfrom BitTorrent.launchmanycore import LaunchManyfrom BitTorrent.defaultargs import get_defaultsfrom BitTorrent.parseargs import parseargs, printHelpfrom BitTorrent.prefs import Preferencesfrom BitTorrent import configfilefrom BitTorrent import versionfrom BitTorrent.platform import encode_for_filesystem, decode_from_filesystemfrom BitTorrent import BTFailurefrom BitTorrent import bt_log_fmtimport loggingfrom logging import ERROR, WARNING, INFOfrom BitTorrent import console, old_stderr, STDERRexceptions = []class HeadlessDisplayer:    def display(self, data):        # formats the data and dumps it to the root logger.        #print ''        if not data:            logging.getLogger('launchmany-console').info( _("no torrents"))        for x in data:            ( name, status, progress, peers, seeds, seedsmsg,               uprate, dnrate, upamt, dnamt, size, t, msg ) = x            logging.getLogger('launchmany-console').info(                '"%s": "%s" (%s) - %sP%s%s u%0.1fK/s-d%0.1fK/s u%dK-d%dK "%s"' % (                name, status, progress, peers, seeds, seedsmsg,                uprate/1000, dnrate/1000, upamt/1024, dnamt/1024, msg))        return Falsedef modify_default( defaults_tuplelist, key, newvalue ):    name,value,doc = [(n,v,d) for (n,v,d) in defaults_tuplelist if n == key][0]    defaults_tuplelist = [(n,v,d) for (n,v,d) in defaults_tuplelist                    if not n == key]    defaults_tuplelist.append( (key,newvalue,doc) )    return defaults_tuplelist    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'] = \                platform.decode_from_filesystem(torrent_dir)        else:            torrent_dir = config['torrent_dir']            torrent_dir,bad = platform.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"))        # the default behavior is to save_in files to the platform        # get_save_dir.  For launchmany, if no command-line argument         # changed the save directory then use the torrent directory.        if config['save_in'] == platform.get_save_dir():            config['save_in'] = config['torrent_dir']    except BTFailure, e:        print _("error: ") + unicode(e.args[0]) + \              _("\nrun with no args for parameter explanations")        sys.exit(1)    except KeyboardInterrupt:        sys.exit(1)    d = HeadlessDisplayer()        # BitTorrent.__init__ installs a StderrProxy that replaces sys.stderr    # and outputs all stderr output to the logger.  Output error log to    # original stderr to avoid infinite loop.    stderr_console = logging.StreamHandler(old_stderr)    stderr_console.setLevel(STDERR)    stderr_console.setFormatter(bt_log_fmt)    logging.getLogger('').addHandler(stderr_console)    logging.getLogger().setLevel(STDERR)    logging.getLogger().removeHandler(console)    # more liberal with logging launchmany-console specific output.    lmany_logger = logging.getLogger('launchmany-console')    lmany_handler = logging.StreamHandler(old_stderr)    lmany_handler.setFormatter(bt_log_fmt)    lmany_handler.setLevel(INFO)    lmany_logger.setLevel(INFO)    lmany_logger.addHandler(lmany_handler)        config = Preferences().initWithDict(config)    LaunchMany(config, d.display, 'launchmany-console')

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -