def display(self, data): """pushes data into our local cache of infos and also gets the length of the longest torrent info string""" if not data: return self.torrents = {'torrents': [], 'maxLength': 0} maxLength = 0 for x in data: (name, status, progress, peers, seeds, seedsmsg, dist, uprate, dnrate, upamt, dnamt, size, t, msg, hash, knownSeeds, knownPeers) = x progress = float(progress.replace("%", "")) progressMsg = "%.0f" % (progress) pathname, filename = os.path.split(name) #TODO: do this better (truncate the name) if len(filename) > 14: filename = filename[:10] + '... ' dist = "%.3f" % (dist * 1000) uprate = Format.bytes_per_second(uprate) dnrate = Format.bytes_per_second(dnrate) upamt = Format.format_bytes(upamt) dnamt = Format.format_bytes(dnamt) s = '%s-> P: (%s)%s | S: (%s)%s | D: %s (%s) | U: %s (%s) | %s%%'%\ (filename, peers, knownPeers, seeds, knownSeeds, dnamt, dnrate, upamt, uprate, progress) if len(s) > maxLength: maxLength = len(s) self.torrents['torrents'].append(s) self.torrents['maxLength'] = maxLength return False
def display(self, data): """pushes data into our local cache of infos and also gets the length of the longest torrent info string""" if not data: return self.torrents = {'torrents':[], 'maxLength': 0} maxLength = 0 for x in data: ( name, status, progress, peers, seeds, seedsmsg, dist, uprate, dnrate, upamt, dnamt, size, t, msg, hash, knownSeeds, knownPeers ) = x progress = float(progress.replace("%", "")) progressMsg = "%.0f" % (progress) pathname, filename = os.path.split(name) #TODO: do this better (truncate the name) if len(filename) > 14: filename = filename[:10] + '... ' dist = "%.3f" % (dist*1000) uprate = Format.bytes_per_second(uprate) dnrate = Format.bytes_per_second(dnrate) upamt = Format.format_bytes(upamt) dnamt = Format.format_bytes(dnamt) s = '%s-> P: (%s)%s | S: (%s)%s | D: %s (%s) | U: %s (%s) | %s%%'%\ (filename, peers, knownPeers, seeds, knownSeeds, dnamt, dnrate, upamt, uprate, progress) if len(s) > maxLength: maxLength = len(s) self.torrents['torrents'].append(s) self.torrents['maxLength'] = maxLength return False
def update(self, globalDownRate, globalUpRate, globalDownAmount, globalUpAmount): if self.btApp.is_ready(): try: nodes = self.btApp.btInstance.dht.get_dht_peers() except: nodes = ("unknown", "disabled") self.dhtText.set_markup('<span>DHT Nodes: %s (%s)</span>' % nodes) globalDownRate = Format.bytes_per_second(globalDownRate) globalDownAmount = Format.format_bytes(globalDownAmount) self.downText.set_markup('<span>U: %s %s</span>' % (globalDownRate, globalDownAmount)) globalUpRate = Format.bytes_per_second(globalUpRate) globalUpAmount = Format.format_bytes(globalUpAmount) self.upText.set_markup('<span>D: %s %s</span>' % (globalUpRate, globalUpAmount)) credits = Bank.get().get_total_asset_value() self.creditText.set_markup('<span>Credits: %s (%s)</span>' % (credits, Format.convert_to_gb(credits)))
def __init__(self, btApp, maggicPadding): gtk.Frame.__init__(self) #bottom row self.btApp = btApp row = gtk.HBox() self.dhtText = gtk.Label('') self.dhtText.set_markup('<span size="large">DHT Nodes: 0 (0)</span>') self.upText = gtk.Label('') initialInfos = (Format.bytes_per_second(0), Format.format_bytes(0)) self.upText.set_markup('<span size="large">D: %s %s</span>' % initialInfos) self.downText = gtk.Label('') self.downText.set_markup('<span size="large">U: %s %s</span>' % initialInfos) self.creditText = gtk.Label('') self.creditText.set_markup('<span size="large">Credits: Unknown</span>') for item in [self.dhtText, self.upText, self.downText]: row.pack_start(item, True, True, 0) row.pack_start(gtk.VSeparator(), False, False, 0) row.pack_start(self.creditText, True, True, 0) self.set_shadow_type(gtk.SHADOW_IN) self.add(row)
def __init__(self, btApp, maggicPadding): gtk.Frame.__init__(self) #bottom row self.btApp = btApp row = gtk.HBox() self.dhtText = gtk.Label('') self.dhtText.set_markup('<span size="large">DHT Nodes: 0 (0)</span>') self.upText = gtk.Label('') initialInfos = (Format.bytes_per_second(0), Format.format_bytes(0)) self.upText.set_markup('<span size="large">D: %s %s</span>' % initialInfos) self.downText = gtk.Label('') self.downText.set_markup('<span size="large">U: %s %s</span>' % initialInfos) self.creditText = gtk.Label('') self.creditText.set_markup( '<span size="large">Credits: Unknown</span>') for item in [self.dhtText, self.upText, self.downText]: row.pack_start(item, True, True, 0) row.pack_start(gtk.VSeparator(), False, False, 0) row.pack_start(self.creditText, True, True, 0) self.set_shadow_type(gtk.SHADOW_IN) self.add(row)
def on_update(self): globalDownRate = 0 globalUpRate = 0 globalDownAmount = 0 globalUpAmount = 0 torrentInfo = None if self.app.is_ready(): torrentInfo = self.app.btInstance.stats(False) if not torrentInfo: #generate it from the pending downloads: torrentInfo = [] for torrentHash, data in self.app.pendingDownloads.iteritems(): name = data[0]['metainfo']['info']['name'] torrentInfo.append([name, "Waiting for Tor...", "0%", 0, 0, "", 0, 0, 0, 0, 0, 0, "0 seconds", "", torrentHash, 0, 0]) #log_msg("update: %s" % (len(self.lastData))) #mark everything as invisible unless it was in this update: visible = {} for ref in self.rows.values(): visible[ref] = False #update each of the active torrents: for torrent in torrentInfo: ( name, status, progress, peers, seeds, seedsmsg, numCopies, dnrate, uprate, dnamt, upamt, size, timeLeft, msg, torrentHash, knownSeeds, knownPeers ) = torrent globalDownRate += dnrate globalUpRate += uprate globalDownAmount += dnamt globalUpAmount += upamt progress = float(progress.replace("%", "")) pathname, filename = os.path.split(name) #status = status+"|"+seedsmsg+"|"+msg progressMsg = "%.0f" % (progress) uprate = Format.bytes_per_second(uprate) dnrate = Format.bytes_per_second(dnrate) upamt = Format.format_bytes(upamt) dnamt = Format.format_bytes(dnamt) # if progress >= 100: # status = "Seeding" try: if self.app.btInstance and self.app.btInstance.downloads.has_key(torrentHash): if not self.app.btInstance.downloads[torrentHash].unpauseflag.isSet(): status = "Paused" if self.app.forcedStatus: status = self.app.forcedStatus except Exception, error: log_ex(error, "Could not find torrent") peers = "%s (%s)" % (peers, knownPeers) seeds = "%s (%s)" % (seeds, knownSeeds) if not self.rows.has_key(torrentHash): rowIter = self.liststore.append([filename, progress, progressMsg, status, peers, seeds, uprate, dnrate, upamt, dnamt, numCopies, torrentHash.encode("hex"), True]) self.rows[torrentHash] = gtk.TreeRowReference(self.liststore, self.liststore.get_string_from_iter(rowIter)) else: rowIter = self.liststore[self.rows[torrentHash].get_path()].iter self.liststore.set_value(rowIter, self.attrIdx["name"], filename) self.liststore.set_value(rowIter, self.attrIdx["progress"], progress) self.liststore.set_value(rowIter, self.attrIdx["progressMsg"], progressMsg) self.liststore.set_value(rowIter, self.attrIdx["status"], status) self.liststore.set_value(rowIter, self.attrIdx["peers"], peers) self.liststore.set_value(rowIter, self.attrIdx["seeds"], seeds) self.liststore.set_value(rowIter, self.attrIdx["rateUp"], uprate) self.liststore.set_value(rowIter, self.attrIdx["rateDown"], dnrate) self.liststore.set_value(rowIter, self.attrIdx["amountUp"], upamt) self.liststore.set_value(rowIter, self.attrIdx["amountDown"], dnamt) self.liststore.set_value(rowIter, self.attrIdx["copies"], numCopies) if not self.liststore.get_value(rowIter, self.attrIdx["visibility"]): self.liststore.set_value(rowIter, self.attrIdx["visibility"], True) visible[self.rows[torrentHash]] = True
def _cell_data_amount(self, column, cell, model, row): value = model.get_value(row, column.valueNum) text = Format.format_bytes(value) cell.set_property("text", text)
def on_update(self): globalDownRate = 0 globalUpRate = 0 globalDownAmount = 0 globalUpAmount = 0 torrentInfo = None if self.app.is_ready(): torrentInfo = self.app.btInstance.stats(False) if not torrentInfo: #generate it from the pending downloads: torrentInfo = [] for torrentHash, data in self.app.pendingDownloads.iteritems(): name = data[0]['metainfo']['info']['name'] torrentInfo.append([ name, "Waiting for Tor...", "0%", 0, 0, "", 0, 0, 0, 0, 0, 0, "0 seconds", "", torrentHash, 0, 0 ]) #log_msg("update: %s" % (len(self.lastData))) #mark everything as invisible unless it was in this update: visible = {} for ref in self.rows.values(): visible[ref] = False #update each of the active torrents: for torrent in torrentInfo: (name, status, progress, peers, seeds, seedsmsg, numCopies, dnrate, uprate, dnamt, upamt, size, timeLeft, msg, torrentHash, knownSeeds, knownPeers) = torrent globalDownRate += dnrate globalUpRate += uprate globalDownAmount += dnamt globalUpAmount += upamt progress = float(progress.replace("%", "")) pathname, filename = os.path.split(name) #status = status+"|"+seedsmsg+"|"+msg progressMsg = "%.0f" % (progress) uprate = Format.bytes_per_second(uprate) dnrate = Format.bytes_per_second(dnrate) upamt = Format.format_bytes(upamt) dnamt = Format.format_bytes(dnamt) # if progress >= 100: # status = "Seeding" try: if self.app.btInstance and self.app.btInstance.downloads.has_key( torrentHash): if not self.app.btInstance.downloads[ torrentHash].unpauseflag.isSet(): status = "Paused" if self.app.forcedStatus: status = self.app.forcedStatus except Exception, error: log_ex(error, "Could not find torrent") peers = "%s (%s)" % (peers, knownPeers) seeds = "%s (%s)" % (seeds, knownSeeds) if not self.rows.has_key(torrentHash): rowIter = self.liststore.append([ filename, progress, progressMsg, status, peers, seeds, uprate, dnrate, upamt, dnamt, numCopies, torrentHash.encode("hex"), True ]) self.rows[torrentHash] = gtk.TreeRowReference( self.liststore, self.liststore.get_string_from_iter(rowIter)) else: rowIter = self.liststore[ self.rows[torrentHash].get_path()].iter self.liststore.set_value(rowIter, self.attrIdx["name"], filename) self.liststore.set_value(rowIter, self.attrIdx["progress"], progress) self.liststore.set_value(rowIter, self.attrIdx["progressMsg"], progressMsg) self.liststore.set_value(rowIter, self.attrIdx["status"], status) self.liststore.set_value(rowIter, self.attrIdx["peers"], peers) self.liststore.set_value(rowIter, self.attrIdx["seeds"], seeds) self.liststore.set_value(rowIter, self.attrIdx["rateUp"], uprate) self.liststore.set_value(rowIter, self.attrIdx["rateDown"], dnrate) self.liststore.set_value(rowIter, self.attrIdx["amountUp"], upamt) self.liststore.set_value(rowIter, self.attrIdx["amountDown"], dnamt) self.liststore.set_value(rowIter, self.attrIdx["copies"], numCopies) if not self.liststore.get_value(rowIter, self.attrIdx["visibility"]): self.liststore.set_value(rowIter, self.attrIdx["visibility"], True) visible[self.rows[torrentHash]] = True