Changeset 624f2f


Ignore:
Timestamp:
01/17/2014 12:21:08 PM (12 years ago)
Author:
Calum Lind <calumlind+deluge@gmail.com>
Branches:
2.0.x, develop, master
Children:
ec56ea
Parents:
b0c3c3
git-author:
Calum Lind <calumlind+deluge@gmail.com> (01/17/2014 12:20:59 PM)
git-committer:
Calum Lind <calumlind+deluge@gmail.com> (01/17/2014 12:21:08 PM)
Message:

Replace deprecated session.num_connections with session_status.num_peers

This commit removes get_num_connections() from core and updates UIs
to use get_session_status with num_peers key.

Extra noise is from Flake8 changes

Location:
deluge
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • deluge/core/core.py

    rb0c3c3 r624f2f  
    7070log = logging.getLogger(__name__)
    7171
     72
    7273class Core(component.Component):
    7374    def __init__(self, listen_interface=None):
     
    9091        # Set the user agent
    9192        self.settings = lt.session_settings()
    92         self.settings.user_agent = "Deluge/%(deluge_version)s libtorrent/%(lt_version)s" % \
    93                         { 'deluge_version': deluge.common.get_version(),
    94                           'lt_version': self.get_libtorrent_version().rpartition(".")[0] }
     93        self.settings.user_agent = "Deluge/%(deluge_version)s libtorrent/%(lt_version)s" % {
     94            'deluge_version': deluge.common.get_version(),
     95            'lt_version': self.get_libtorrent_version().rpartition(".")[0]
     96        }
    9597        # Increase the alert queue size so that alerts don't get lost
    9698        self.settings.alert_queue_size = 10000
     
    265267        """
    266268        log.info("Attempting to add url %s", url)
     269
    267270        def on_download_success(filename):
    268271            # We got the file, so add it to the session
     
    381384        # Add in a couple ratios
    382385        try:
    383             cache["write_hit_ratio"] = float((cache["blocks_written"] - cache["writes"])) / float(cache["blocks_written"])
     386            cache["write_hit_ratio"] = float((cache["blocks_written"] -
     387                                              cache["writes"])) / float(cache["blocks_written"])
    384388        except ZeroDivisionError:
    385389            cache["write_hit_ratio"] = 0.0
     
    454458    def get_torrent_status(self, torrent_id, keys, diff=False):
    455459        torrent_keys, plugin_keys = self.torrentmanager.separate_keys(keys, [torrent_id])
    456         return self.create_torrent_status(torrent_id, torrent_keys, plugin_keys, diff=diff, update=True, all_keys=not keys)
     460        return self.create_torrent_status(torrent_id, torrent_keys, plugin_keys, diff=diff, update=True,
     461                                          all_keys=not keys)
    457462
    458463    @export
     
    462467        """
    463468        torrent_ids = self.filtermanager.filter_torrent_ids(filter_dict)
    464         status_dict = {}.fromkeys(torrent_ids)
    465469        d = self.torrentmanager.torrents_status_update(torrent_ids, keys, diff=diff)
    466470
     
    476480
    477481    @export
    478     def get_filter_tree(self , show_zero_hits=True, hide_cat=None):
     482    def get_filter_tree(self, show_zero_hits=True, hide_cat=None):
    479483        """
    480484        returns {field: [(value,count)] }
     
    519523
    520524    @export
    521     def get_num_connections(self):
    522         """Returns the current number of connections"""
    523         return self.session.num_connections()
    524 
    525     @export
    526525    def get_available_plugins(self):
    527526        """Returns a list of plugins available in the core"""
     
    659658    @export
    660659    def create_torrent(self, path, tracker, piece_length, comment, target,
    661                         webseeds, private, created_by, trackers, add_to_session):
     660                       webseeds, private, created_by, trackers, add_to_session):
    662661
    663662        log.debug("creating torrent..")
    664663        threading.Thread(target=self._create_torrent_thread,
    665             args=(
    666                 path,
    667                 tracker,
    668                 piece_length,
    669                 comment,
    670                 target,
    671                 webseeds,
    672                 private,
    673                 created_by,
    674                 trackers,
    675                 add_to_session)).start()
     664                         args=(
     665                             path,
     666                             tracker,
     667                             piece_length,
     668                             comment,
     669                             target,
     670                             webseeds,
     671                             private,
     672                             created_by,
     673                             trackers,
     674                             add_to_session)).start()
    676675
    677676    def _create_torrent_thread(self, path, tracker, piece_length, comment, target,
    678                     webseeds, private, created_by, trackers, add_to_session):
     677                               webseeds, private, created_by, trackers, add_to_session):
    679678        import deluge.metafile
    680679        deluge.metafile.make_meta_file(
  • deluge/plugins/Stats/deluge/plugins/stats/core.py

    rb0c3c3 r624f2f  
    3838from twisted.internet.task import LoopingCall
    3939
    40 import deluge
    4140from deluge.plugins.pluginbase import CorePluginBase
    4241from deluge import component
     
    4645DEFAULT_PREFS = {
    4746    "test": "NiNiNi",
    48     "update_interval": 1, #2 seconds.
    49     "length": 150, # 2 seconds * 150 --> 5 minutes.
     47    "update_interval": 1,  # 2 seconds.
     48    "length": 150,  # 2 seconds * 150 --> 5 minutes.
    5049}
    5150
     
    6059log = logging.getLogger(__name__)
    6160
     61
    6262def get_key(config, key):
    6363    try:
     
    6666        return None
    6767
     68
    6869def mean(items):
    6970    try:
    70         return sum(items)/ len(items)
     71        return sum(items) / len(items)
    7172    except Exception:
    7273        return 0
    7374
     75
    7476class Core(CorePluginBase):
    75     totals = {} #class var to catch only updating this once per session in enable.
     77    totals = {}  # class var to catch only updating this once per session in enable.
    7678
    7779    def enable(self):
    7880        log.debug("Stats plugin enabled")
    7981        self.core = component.get("Core")
    80         self.stats ={}
     82        self.stats = {}
    8183        self.count = {}
    8284        self.intervals = [1, 5, 30, 300]
     
    8890            self.last_update[i] = t
    8991            self.count[i] = 0
    90 
    9192
    9293        self.config = configmanager.ConfigManager("stats.conf", DEFAULT_PREFS)
     
    144145                except AttributeError:
    145146                    pass
    146             stats["num_connections"]  = self.core.get_num_connections()
     147            stats["num_connections"] = stats["num_peers"]
    147148            stats.update(self.core.get_config_values(["max_download",
    148149                                                      "max_upload",
     
    170171                if self.count[interval] >= interval:
    171172                    self.last_update[interval] = update_time
    172                     self.count[interval] =  0
     173                    self.count[interval] = 0
    173174                    current_stats = self.stats[interval]
    174175                    for stat, stat_list in self.stats[base].iteritems():
     
    198199        return True
    199200
    200 
    201201    # export:
    202202    @export
  • deluge/ui/console/commands/status.py

    rb0c3c3 r624f2f  
    4040import deluge.component as component
    4141
     42
    4243class Command(BaseCommand):
    4344    """Shows a various status information from the daemon."""
    4445    option_list = BaseCommand.option_list + (
    45             make_option('-r', '--raw', action='store_true', default=False, dest='raw',
    46                         help='Don\'t format upload/download rates in KiB/s (useful for scripts that want to do their own parsing)'),
    47             make_option('-n', '--no-torrents', action='store_false', default=True, dest='show_torrents',
    48                         help='Don\'t show torrent status (this will make the command a bit faster)'),
     46        make_option('-r', '--raw', action='store_true', default=False, dest='raw',
     47                    help='Don\'t format upload/download rates in KiB/s \
     48(useful for scripts that want to do their own parsing)'),
     49        make_option('-n', '--no-torrents', action='store_false', default=True, dest='show_torrents',
     50                    help='Don\'t show torrent status (this will make the command a bit faster)'),
    4951    )
    5052
     53    usage = "Usage: status [-r] [-n]"
    5154
    52     usage = "Usage: status [-r] [-n]"
    5355    def handle(self, *args, **options):
    5456        self.console = component.get("ConsoleUI")
     
    6466        def on_session_status(status):
    6567            self.status = status
    66             if self.status != None and self.connections != None and self.torrents != None:
    67                 self.print_status()
    68 
    69         def on_num_connections(conns):
    70             self.connections = conns
    71             if self.status != None and self.connections != None and self.torrents != None:
     68            if self.status is not None and self.connections is not None and self.torrents is not None:
    7269                self.print_status()
    7370
    7471        def on_torrents_status(status):
    7572            self.torrents = status
    76             if self.status != None and self.connections != None and self.torrents != None:
     73            if self.status is not None and self.connections is not None and self.torrents is not None:
    7774                self.print_status()
    7875
    7976        def on_torrents_status_fail(reason):
    8077            self.torrents = -1
    81             if self.status != None and self.connections != None and self.torrents != None:
     78            if self.status is not None and self.connections is not None and self.torrents is not None:
    8279                self.print_status()
    8380
    8481        deferreds = []
    8582
    86         ds = client.core.get_session_status(["payload_upload_rate","payload_download_rate","dht_nodes"])
     83        ds = client.core.get_session_status(["num_peers", "payload_upload_rate", "payload_download_rate", "dht_nodes"])
    8784        ds.addCallback(on_session_status)
    8885        deferreds.append(ds)
    89 
    90         dc = client.core.get_num_connections()
    91         dc.addCallback(on_num_connections)
    92         deferreds.append(dc)
    9386
    9487        if options["show_torrents"]:
     
    10396        self.console.set_batch_write(True)
    10497        if self.raw:
    105             self.console.write("{!info!}Total upload: %f"%self.status["payload_upload_rate"])
    106             self.console.write("{!info!}Total download: %f"%self.status["payload_download_rate"])
     98            self.console.write("{!info!}Total upload: %f" % self.status["payload_upload_rate"])
     99            self.console.write("{!info!}Total download: %f" % self.status["payload_download_rate"])
    107100        else:
    108             self.console.write("{!info!}Total upload: %s"%deluge.common.fspeed(self.status["payload_upload_rate"]))
    109             self.console.write("{!info!}Total download: %s"%deluge.common.fspeed(self.status["payload_download_rate"]))
    110         self.console.write("{!info!}DHT Nodes: %i"%self.status["dht_nodes"])
    111         self.console.write("{!info!}Total connections: %i"%self.connections)
     101            self.console.write("{!info!}Total upload: %s" % deluge.common.fspeed(self.status["payload_upload_rate"]))
     102            self.console.write("{!info!}Total download: %s" %
     103                               deluge.common.fspeed(self.status["payload_download_rate"]))
     104        self.console.write("{!info!}DHT Nodes: %i" % self.status["dht_nodes"])
     105        self.console.write("{!info!}Total connections: %i" % self.connections)
    112106        if self.torrents == -1:
    113107            self.console.write("{!error!}Error getting torrent info")
    114108        elif self.torrents != -2:
    115             self.console.write("{!info!}Total torrents: %i"%len(self.torrents))
    116             states = ["Downloading","Seeding","Paused","Checking","Error","Queued"]
     109            self.console.write("{!info!}Total torrents: %i" % len(self.torrents))
     110            states = ["Downloading", "Seeding", "Paused", "Checking", "Error", "Queued"]
    117111            state_counts = {}
    118112            for state in states:
     
    122116                state_counts[s["state"]] += 1
    123117            for state in states:
    124                 self.console.write("{!info!} %s: %i"%(state,state_counts[state]))
     118                self.console.write("{!info!} %s: %i" % (state, state_counts[state]))
    125119
    126120        self.console.set_batch_write(False)
  • deluge/ui/console/statusbars.py

    rb0c3c3 r624f2f  
    4040from deluge.ui.client import client
    4141
     42
    4243class StatusBars(component.Component):
    4344    def __init__(self):
     
    5960
    6061    def update(self):
    61         def on_get_num_connections(result):
    62             self.connections = result
    63         client.core.get_num_connections().addCallback(on_get_num_connections)
    64 
    6562        def on_get_session_status(status):
    6663            self.upload = deluge.common.fsize(status["payload_upload_rate"])
    6764            self.download = deluge.common.fsize(status["payload_download_rate"])
     65            self.connections = status["num_peers"]
    6866            if "dht_nodes" in status:
    6967                self.dht = status["dht_nodes"]
     
    7169            self.update_statusbars()
    7270
    73         keys = [
    74             "payload_upload_rate",
    75             "payload_download_rate"]
     71        keys = ["num_peers", "payload_upload_rate", "payload_download_rate"]
    7672
    7773        if self.config["dht"]:
     
    7975
    8076        client.core.get_session_status(keys).addCallback(on_get_session_status)
    81 
    8277
    8378    def update_statusbars(self):
     
    133128            self.bottombar += " U: {!white,blue!}%s{!status!}" % self.upload
    134129
    135 
    136130        if self.config["max_upload_speed"] > -1:
    137131            self.bottombar += " (%s " % self.config["max_upload_speed"] + _("KiB/s") + ")"
  • deluge/ui/gtkui/statusbar.py

    rb0c3c3 r624f2f  
    4646
    4747log = logging.getLogger(__name__)
     48
    4849
    4950class StatusBarItem:
     
    6061
    6162        # Add image from file or stock
    62         if image != None or stock != None:
    63             if image != None:
     63        if image is not None or stock is not None:
     64            if image is not None:
    6465                self.set_image_from_file(image)
    65             if stock != None:
     66            if stock is not None:
    6667                self.set_image_from_stock(stock)
    6768
    6869        # Add text
    69         if text != None:
     70        if text is not None:
    7071            self.set_text(text)
    7172
    72         if callback != None:
     73        if callback is not None:
    7374            self.set_callback(callback)
    7475
     
    113114    def get_text(self):
    114115        return self._label.get_text()
     116
    115117
    116118class StatusBar(component.Component):
     
    188190
    189191        self.diskspace_item = self.add_item(
    190                 stock=gtk.STOCK_HARDDISK,
    191                 callback=self._on_diskspace_item_clicked,
    192                 tooltip=_("Free Disk Space"))
     192            stock=gtk.STOCK_HARDDISK,
     193            callback=self._on_diskspace_item_clicked,
     194            tooltip=_("Free Disk Space"))
    193195
    194196        self.health_item = self.add_item(
    195                 stock=gtk.STOCK_DIALOG_ERROR,
    196                 text=_("No Incoming Connections!"),
    197                 callback=self._on_health_icon_clicked)
     197            stock=gtk.STOCK_DIALOG_ERROR,
     198            text=_("No Incoming Connections!"),
     199            callback=self._on_health_icon_clicked)
    198200
    199201        self.health = False
     
    206208        # Get some config values
    207209        client.core.get_config_values(["max_connections_global", "max_download_speed",
    208                                   "max_upload_speed", "dht"]).addCallback(update_config_values)
     210                                      "max_upload_speed", "dht"]).addCallback(update_config_values)
    209211
    210212    def stop(self):
     
    275277    def send_status_request(self):
    276278        # Sends an async request for data from the core
    277         client.core.get_num_connections().addCallback(self._on_get_num_connections)
    278         keys = ["upload_rate", "download_rate", "payload_upload_rate", "payload_download_rate"]
     279        keys = ["num_peers", "upload_rate", "download_rate", "payload_upload_rate", "payload_download_rate"]
    279280
    280281        if self.dht_status:
     
    298299    def _on_max_connections_global(self, max_connections):
    299300        self.max_connections = max_connections
    300         self.update_connections_label()
    301 
    302     def _on_get_num_connections(self, num_connections):
    303         self.num_connections = num_connections
    304301        self.update_connections_label()
    305302
     
    318315        self.download_protocol_rate = (status["download_rate"] - status["payload_download_rate"]) / 1024
    319316        self.upload_protocol_rate = (status["upload_rate"] - status["payload_upload_rate"]) / 1024
     317        self.num_connections = status["num_peers"]
    320318        self.update_download_label()
    321319        self.update_upload_label()
    322320        self.update_traffic_label()
     321        self.update_connections_label()
    323322
    324323        if "dht_nodes" in status:
     
    403402            value = common.show_other_dialog(
    404403                _("Set Maximum Download Speed"), _("KiB/s"), None, "downloading.svg", self.max_download_speed)
    405             if value == None:
     404            if value is None:
    406405                return
    407406        else:
     
    431430            value = common.show_other_dialog(
    432431                _("Set Maximum Upload Speed"), _("KiB/s"), None, "seeding.svg", self.max_upload_speed)
    433             if value == None:
     432            if value is None:
    434433                return
    435434        else:
     
    458457            value = common.show_other_dialog(
    459458                _("Set Maximum Connections"), "", gtk.STOCK_NETWORK, None, self.max_connections)
    460             if value == None:
     459            if value is None:
    461460                return
    462461        else:
  • deluge/ui/web/json_api.py

    rb0c3c3 r624f2f  
    521521            return d
    522522
    523         def got_connections(connections):
    524             ui_info["stats"]["num_connections"] = connections
    525 
    526523        def got_stats(stats):
     524            ui_info["stats"]["num_connections"] = stats["num_peers"]
    527525            ui_info["stats"]["upload_rate"] = stats["payload_upload_rate"]
    528526            ui_info["stats"]["download_rate"] = stats["payload_download_rate"]
     
    551549
    552550        d3 = client.core.get_session_status([
     551            "num_peers",
    553552            "payload_download_rate",
    554553            "payload_upload_rate",
     
    560559        d3.addCallback(got_stats)
    561560
    562         d4 = client.core.get_num_connections()
    563         d4.addCallback(got_connections)
    564 
    565         d5 = client.core.get_free_space(self.core_config.get("download_location"))
    566         d5.addCallback(got_free_space)
    567 
    568         dl = DeferredList([d1, d2, d3, d4, d5], consumeErrors=True)
     561        d4 = client.core.get_free_space(self.core_config.get("download_location"))
     562        d4.addCallback(got_free_space)
     563
     564        dl = DeferredList([d1, d2, d3, d4], consumeErrors=True)
    569565        dl.addCallback(on_complete)
    570566        return d
Note: See TracChangeset for help on using the changeset viewer.