Changeset 624f2f
- Timestamp:
- 01/17/2014 12:21:08 PM (12 years ago)
- 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)
- Location:
- deluge
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
deluge/core/core.py
rb0c3c3 r624f2f 70 70 log = logging.getLogger(__name__) 71 71 72 72 73 class Core(component.Component): 73 74 def __init__(self, listen_interface=None): … … 90 91 # Set the user agent 91 92 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 } 95 97 # Increase the alert queue size so that alerts don't get lost 96 98 self.settings.alert_queue_size = 10000 … … 265 267 """ 266 268 log.info("Attempting to add url %s", url) 269 267 270 def on_download_success(filename): 268 271 # We got the file, so add it to the session … … 381 384 # Add in a couple ratios 382 385 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"]) 384 388 except ZeroDivisionError: 385 389 cache["write_hit_ratio"] = 0.0 … … 454 458 def get_torrent_status(self, torrent_id, keys, diff=False): 455 459 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) 457 462 458 463 @export … … 462 467 """ 463 468 torrent_ids = self.filtermanager.filter_torrent_ids(filter_dict) 464 status_dict = {}.fromkeys(torrent_ids)465 469 d = self.torrentmanager.torrents_status_update(torrent_ids, keys, diff=diff) 466 470 … … 476 480 477 481 @export 478 def get_filter_tree(self 482 def get_filter_tree(self, show_zero_hits=True, hide_cat=None): 479 483 """ 480 484 returns {field: [(value,count)] } … … 519 523 520 524 @export 521 def get_num_connections(self):522 """Returns the current number of connections"""523 return self.session.num_connections()524 525 @export526 525 def get_available_plugins(self): 527 526 """Returns a list of plugins available in the core""" … … 659 658 @export 660 659 def create_torrent(self, path, tracker, piece_length, comment, target, 661 660 webseeds, private, created_by, trackers, add_to_session): 662 661 663 662 log.debug("creating torrent..") 664 663 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() 676 675 677 676 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): 679 678 import deluge.metafile 680 679 deluge.metafile.make_meta_file( -
deluge/plugins/Stats/deluge/plugins/stats/core.py
rb0c3c3 r624f2f 38 38 from twisted.internet.task import LoopingCall 39 39 40 import deluge41 40 from deluge.plugins.pluginbase import CorePluginBase 42 41 from deluge import component … … 46 45 DEFAULT_PREFS = { 47 46 "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. 50 49 } 51 50 … … 60 59 log = logging.getLogger(__name__) 61 60 61 62 62 def get_key(config, key): 63 63 try: … … 66 66 return None 67 67 68 68 69 def mean(items): 69 70 try: 70 return sum(items) / len(items)71 return sum(items) / len(items) 71 72 except Exception: 72 73 return 0 73 74 75 74 76 class 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. 76 78 77 79 def enable(self): 78 80 log.debug("Stats plugin enabled") 79 81 self.core = component.get("Core") 80 self.stats = {}82 self.stats = {} 81 83 self.count = {} 82 84 self.intervals = [1, 5, 30, 300] … … 88 90 self.last_update[i] = t 89 91 self.count[i] = 0 90 91 92 92 93 self.config = configmanager.ConfigManager("stats.conf", DEFAULT_PREFS) … … 144 145 except AttributeError: 145 146 pass 146 stats["num_connections"] = self.core.get_num_connections()147 stats["num_connections"] = stats["num_peers"] 147 148 stats.update(self.core.get_config_values(["max_download", 148 149 "max_upload", … … 170 171 if self.count[interval] >= interval: 171 172 self.last_update[interval] = update_time 172 self.count[interval] = 173 self.count[interval] = 0 173 174 current_stats = self.stats[interval] 174 175 for stat, stat_list in self.stats[base].iteritems(): … … 198 199 return True 199 200 200 201 201 # export: 202 202 @export -
deluge/ui/console/commands/status.py
rb0c3c3 r624f2f 40 40 import deluge.component as component 41 41 42 42 43 class Command(BaseCommand): 43 44 """Shows a various status information from the daemon.""" 44 45 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)'), 49 51 ) 50 52 53 usage = "Usage: status [-r] [-n]" 51 54 52 usage = "Usage: status [-r] [-n]"53 55 def handle(self, *args, **options): 54 56 self.console = component.get("ConsoleUI") … … 64 66 def on_session_status(status): 65 67 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: 72 69 self.print_status() 73 70 74 71 def on_torrents_status(status): 75 72 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: 77 74 self.print_status() 78 75 79 76 def on_torrents_status_fail(reason): 80 77 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: 82 79 self.print_status() 83 80 84 81 deferreds = [] 85 82 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"]) 87 84 ds.addCallback(on_session_status) 88 85 deferreds.append(ds) 89 90 dc = client.core.get_num_connections()91 dc.addCallback(on_num_connections)92 deferreds.append(dc)93 86 94 87 if options["show_torrents"]: … … 103 96 self.console.set_batch_write(True) 104 97 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"]) 107 100 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) 112 106 if self.torrents == -1: 113 107 self.console.write("{!error!}Error getting torrent info") 114 108 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"] 117 111 state_counts = {} 118 112 for state in states: … … 122 116 state_counts[s["state"]] += 1 123 117 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])) 125 119 126 120 self.console.set_batch_write(False) -
deluge/ui/console/statusbars.py
rb0c3c3 r624f2f 40 40 from deluge.ui.client import client 41 41 42 42 43 class StatusBars(component.Component): 43 44 def __init__(self): … … 59 60 60 61 def update(self): 61 def on_get_num_connections(result):62 self.connections = result63 client.core.get_num_connections().addCallback(on_get_num_connections)64 65 62 def on_get_session_status(status): 66 63 self.upload = deluge.common.fsize(status["payload_upload_rate"]) 67 64 self.download = deluge.common.fsize(status["payload_download_rate"]) 65 self.connections = status["num_peers"] 68 66 if "dht_nodes" in status: 69 67 self.dht = status["dht_nodes"] … … 71 69 self.update_statusbars() 72 70 73 keys = [ 74 "payload_upload_rate", 75 "payload_download_rate"] 71 keys = ["num_peers", "payload_upload_rate", "payload_download_rate"] 76 72 77 73 if self.config["dht"]: … … 79 75 80 76 client.core.get_session_status(keys).addCallback(on_get_session_status) 81 82 77 83 78 def update_statusbars(self): … … 133 128 self.bottombar += " U: {!white,blue!}%s{!status!}" % self.upload 134 129 135 136 130 if self.config["max_upload_speed"] > -1: 137 131 self.bottombar += " (%s " % self.config["max_upload_speed"] + _("KiB/s") + ")" -
deluge/ui/gtkui/statusbar.py
rb0c3c3 r624f2f 46 46 47 47 log = logging.getLogger(__name__) 48 48 49 49 50 class StatusBarItem: … … 60 61 61 62 # 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: 64 65 self.set_image_from_file(image) 65 if stock !=None:66 if stock is not None: 66 67 self.set_image_from_stock(stock) 67 68 68 69 # Add text 69 if text !=None:70 if text is not None: 70 71 self.set_text(text) 71 72 72 if callback !=None:73 if callback is not None: 73 74 self.set_callback(callback) 74 75 … … 113 114 def get_text(self): 114 115 return self._label.get_text() 116 115 117 116 118 class StatusBar(component.Component): … … 188 190 189 191 self.diskspace_item = self.add_item( 190 191 192 192 stock=gtk.STOCK_HARDDISK, 193 callback=self._on_diskspace_item_clicked, 194 tooltip=_("Free Disk Space")) 193 195 194 196 self.health_item = self.add_item( 195 196 197 197 stock=gtk.STOCK_DIALOG_ERROR, 198 text=_("No Incoming Connections!"), 199 callback=self._on_health_icon_clicked) 198 200 199 201 self.health = False … … 206 208 # Get some config values 207 209 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) 209 211 210 212 def stop(self): … … 275 277 def send_status_request(self): 276 278 # 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"] 279 280 280 281 if self.dht_status: … … 298 299 def _on_max_connections_global(self, max_connections): 299 300 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_connections304 301 self.update_connections_label() 305 302 … … 318 315 self.download_protocol_rate = (status["download_rate"] - status["payload_download_rate"]) / 1024 319 316 self.upload_protocol_rate = (status["upload_rate"] - status["payload_upload_rate"]) / 1024 317 self.num_connections = status["num_peers"] 320 318 self.update_download_label() 321 319 self.update_upload_label() 322 320 self.update_traffic_label() 321 self.update_connections_label() 323 322 324 323 if "dht_nodes" in status: … … 403 402 value = common.show_other_dialog( 404 403 _("Set Maximum Download Speed"), _("KiB/s"), None, "downloading.svg", self.max_download_speed) 405 if value ==None:404 if value is None: 406 405 return 407 406 else: … … 431 430 value = common.show_other_dialog( 432 431 _("Set Maximum Upload Speed"), _("KiB/s"), None, "seeding.svg", self.max_upload_speed) 433 if value ==None:432 if value is None: 434 433 return 435 434 else: … … 458 457 value = common.show_other_dialog( 459 458 _("Set Maximum Connections"), "", gtk.STOCK_NETWORK, None, self.max_connections) 460 if value ==None:459 if value is None: 461 460 return 462 461 else: -
deluge/ui/web/json_api.py
rb0c3c3 r624f2f 521 521 return d 522 522 523 def got_connections(connections):524 ui_info["stats"]["num_connections"] = connections525 526 523 def got_stats(stats): 524 ui_info["stats"]["num_connections"] = stats["num_peers"] 527 525 ui_info["stats"]["upload_rate"] = stats["payload_upload_rate"] 528 526 ui_info["stats"]["download_rate"] = stats["payload_download_rate"] … … 551 549 552 550 d3 = client.core.get_session_status([ 551 "num_peers", 553 552 "payload_download_rate", 554 553 "payload_upload_rate", … … 560 559 d3.addCallback(got_stats) 561 560 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) 569 565 dl.addCallback(on_complete) 570 566 return d
Note:
See TracChangeset
for help on using the changeset viewer.