def __init__(self, parent): super(AutoRemove, self).__init__(parent) self.cache = apt.Cache() self.cache.open() self.main_dlg.set_title('Διαγραφή ορφανών πακέτων...') self.main_dlg_lbl_title.set_markup( '<b><big>Βρέθηκαν τα παρακάτω ορφανά πακέτα στο σύστημα\n</big></b>' ) self.main_dlg_img_lbl.set_from_icon_name('applications-other', Gtk.IconSize.SMALL_TOOLBAR) self.main_dlg_img_lbl.set_pixel_size(-1) if not self.find(): self.clear_cache() dialogs.InfoDialog('Δεν υπάρχουν ορφανά πακέτα για διαγραφή.', 'Ειδοποίηση').showup() return if len(self.pkgs) == 1: self.main_dlg_lbl_space.set_markup( '%s πακέτο βρέθηκε, %sB χώρου στο δίσκο θα ελευθερωθούν.' \ %(str(len(self.pkgs)), apt_pkg.size_to_str(sum(pkg.size for pkg in self.pkgs)))) else: self.main_dlg_lbl_space.set_markup( '%s πακέτα βρέθηκαν, %sB χώρου στο δίσκο θα ελευθερωθούν.' \ %(str(len(self.pkgs)), apt_pkg.size_to_str(sum(pkg.size for pkg in self.pkgs)))) self.populate_treeview() self.main_dlg.show_all()
def __init__(self, parent): super(Purge, self).__init__(parent) self.cache = apt.Cache() self.cache.open() self.main_dlg.set_title('Αφαίρεση παλιών πυρήνων...') self.main_dlg_lbl_title.set_markup( '<b><big>Βρέθηκαν οι παρακάτω παλιοί πυρήνες στο σύστημα\n\n</big></b>' \ 'Μπορείτε να επιλέξετε αυτούς που επιθυμείτε να αφαιρεθούν.') self.main_dlg_img_lbl.set_from_icon_name('applications-other', Gtk.IconSize.SMALL_TOOLBAR) self.main_dlg_img_lbl.set_pixel_size(-1) if not self.find(): self.clear_cache() dialogs.InfoDialog('Δεν βρέθηκαν παλιοί πυρήνες για διαγραφή.', 'Ειδοποίηση').showup() return if len(self.pkgs) == 1: self.main_dlg_lbl_space.set_text( '%d πακέτο έχει επιλέγει, %sB χώρου στο δίσκο θα ελευθερωθούν.' \ %(len(self.pkgs), apt_pkg.size_to_str(sum(pkg.size for pkg in self.pkgs)))) else: self.main_dlg_lbl_space.set_text( '%d πακέτα έχουν επιλέγει, %sB χώρου στο δίσκο θα ελευθερωθούν.' \ %(len(self.pkgs), apt_pkg.size_to_str(sum(pkg.size for pkg in self.pkgs)))) self.populate_treeview() self.main_dlg.show_all()
def populate_treeview(self): """AptDeamon Callbacks.""" tview_pkgs = [] for ppkg in self.pkgs: if ppkg.name.startswith('linux-image'): tview_pkgs.append(ppkg) desc = '<b>%s</b>\n<small>%s (%s)</small>' % ( ppkg.name, ppkg.desc, ppkg.sum) size = '%sB' % apt_pkg.size_to_str(ppkg.size) piter = self.main_dlg_tstore.append(None, [ppkg, None, desc, size, \ Gtk.IconSize.LARGE_TOOLBAR, None, None, False]) for cpkg in ppkg.childs: tview_pkgs.append(cpkg) desc = '<b>%s</b>\n<small>%s (%s)</small>' % ( cpkg.name, cpkg.desc, cpkg.sum) size = '%sB' % apt_pkg.size_to_str(cpkg.size) self.main_dlg_tstore.append(piter, [cpkg, None, desc, size, \ Gtk.IconSize.SMALL_TOOLBAR, None, None, False]) for ppkg in self.pkgs: if ppkg not in tview_pkgs: desc = '<b>%s</b>\n<small>%s (%s)</small>' % ( ppkg.name, ppkg.desc, ppkg.sum) size = '%sB' % apt_pkg.size_to_str(ppkg.size) piter = self.main_dlg_tstore.append(None, [ppkg, None, desc, size, \ Gtk.IconSize.LARGE_TOOLBAR, None, None, False])
def on_main_dlg_pkg_toggle_toggled(self, widget, path): """Callbacks.""" self.main_dlg_tstore[path][5] = not self.main_dlg_tstore[path][5] if not self.main_dlg_tstore[path][5]: self.pkgs.remove(self.main_dlg_tstore[path][0]) for iter in self.main_dlg_tstore[path].iterchildren(): self.pkgs.remove(iter[0]) iter[5] = False else: self.pkgs.append(self.main_dlg_tstore[path][0]) for iter in self.main_dlg_tstore[path].iterchildren(): self.pkgs.append(iter[0]) iter[5] = True if len(self.pkgs) != 0: self.main_dlg.set_response_sensitive(Gtk.ResponseType.OK, True) if len(self.pkgs) == 1: self.main_dlg_lbl_space.set_text( '%d πακέτο έχει επιλέγει, %sB χώρου στο δίσκο θα ελευθερωθούν.' \ %(len(self.pkgs), apt_pkg.size_to_str(sum(pkg.size for pkg in self.pkgs)))) else: self.main_dlg_lbl_space.set_text( '%d πακέτα έχουν επιλέγει, %sB χώρου στο δίσκο θα ελευθερωθούν.' \ %(len(self.pkgs), apt_pkg.size_to_str(sum(pkg.size for pkg in self.pkgs)))) else: self.main_dlg.set_response_sensitive(Gtk.ResponseType.OK, False) self.main_dlg_lbl_space.set_text( 'Δεν έχετε επιλέξει κάποιο πυρήνα προς αφαίρεση.')
def pulse(self, owner): """Periodically invoked while the Acquire process is underway. Return False if the user asked to cancel the whole Acquire process.""" base.AcquireProgress.pulse(self, owner) percent = (((self.current_bytes + self.current_items) * 100.0) / float(self.total_bytes + self.total_items)) shown = False tval = '%i%%' % percent end = "" if self.current_cps: eta = long(float(self.total_bytes - self.current_bytes) / self.current_cps) end = " %sB/s %s" % (apt_pkg.size_to_str(self.current_cps), apt_pkg.time_to_str(eta)) for worker in owner.workers: val = '' if not worker.current_item: if worker.status: val = ' [%s]' % worker.status if len(tval) + len(val) + len(end) >= self._width: break tval += val shown = True continue shown = True if worker.current_item.owner.id: val += " [%i %s" % (worker.current_item.owner.id, worker.current_item.shortdesc) else: val += ' [%s' % worker.current_item.description if worker.current_item.owner.mode: val += ' %s' % worker.current_item.owner.mode val += ' %sB' % apt_pkg.size_to_str(worker.current_size) # Add the total size and percent if worker.total_size and not worker.current_item.owner.complete: val += "/%sB %i%%" % (apt_pkg.size_to_str(worker.total_size), worker.current_size*100.0/worker.total_size) val += ']' if len(tval) + len(val) + len(end) >= self._width: # Display as many items as screen width break else: tval += val if not shown: tval += _(" [Working]") if self.current_cps: tval += (self._width - len(end) - len(tval)) * ' ' + end self._write(tval, False) return True
def pulse(self, owner): print "pulse: CPS: %s/s; Bytes: %s/%s; Item: %s/%s" % ( apt_pkg.size_to_str( self.current_cps), apt_pkg.size_to_str(self.current_bytes), apt_pkg.size_to_str( self.total_bytes), self.current_items, self.total_items) return True
def _print_update_summary(cache, pkgs): delete_names = [] install_names = [] upgrade_names = [] # TODO marked_downgrade, marked_keep, marked_reinstall for pkg in pkgs: if pkg.marked_delete: delete_names.append(pkg.name) elif pkg.marked_install: install_names.append(pkg.name) elif pkg.marked_upgrade: upgrade_names.append(pkg.name) pprint_names('The following packages will be REMOVED:', delete_names) pprint_names('The following NEW packages will be installed:', install_names) pprint_names('The following packages will be upgraded:', upgrade_names) print(('{0} upgraded, {1} newly installed, {2} to remove and' ' {3} not upgraded')\ .format(len(upgrade_names), len(install_names), len(delete_names), cache.keep_count)) print('Need to get {0}B of archives.'\ .format(apt_pkg.size_to_str(cache.required_download))) if cache.required_space < 0: print('After this operation, {0}B of disk space will be freed.'\ .format(apt_pkg.size_to_str(-cache.required_space))) else: print(('After this operation, {0}B of additional disk space will' ' be used.').format(apt_pkg.size_to_str(cache.required_space)))
def _on_download_changed(self, transaction, uri, status, desc, full_size, downloaded, message): if full_size == 0: progress = -1 else: progress = int(downloaded * 100 / full_size) if status == DOWNLOAD_DONE: progress = 100 if progress > 100: progress = 100 description = "" if status == DOWNLOAD_FETCHING: description += (_("Downloaded %sB of %sB") % (apt_pkg.size_to_str(downloaded), apt_pkg.size_to_str(full_size))) elif status == DOWNLOAD_DONE: if full_size != 0: description += _("Downloaded %sB") % apt_pkg.size_to_str( full_size) else: description += _("Downloaded") else: description += get_download_status_from_enum(status) self.EmitDownloadPercentChild(uri, "cs-packages", desc[:], progress, description)
def pulse(self, owner): print("pulse: CPS: %s/s; Bytes: %s/%s; Item: %s/%s" % ( apt_pkg.size_to_str(self.current_cps), apt_pkg.size_to_str(self.current_bytes), apt_pkg.size_to_str(self.total_bytes), self.current_items, self.total_items)) return True
def _get_transaction_summary(self, trans): #Create a message and the dependencies to be show. infoConf = {"title": "", "description": "", "dependencies": {}} for index, msg in enumerate([ _("Install"), _("Reinstall"), _("Remove"), _("Purge"), _("Upgrade"), _("Downgrade"), _("Skip upgrade") ]): if trans.dependencies[index]: listPiter = infoConf["dependencies"]["%s" % msg] = [] for pkg in trans.dependencies[index]: for object in self.map_package(pkg): listPiter.append(str(object)) # If there is only one type of changes (e.g. only installs) expand the # tree #FIXME: adapt the title and message accordingly #FIXME: Should we have different modes? Only show dependencies, only # initial packages or both? msg = _("Please take a look at the list of changes below.") title = "" if len(infoConf["dependencies"].keys()) == 1: if trans.dependencies[PKGS_INSTALL]: title = _("Additional software has to be installed") elif trans.dependencies[PKGS_REINSTALL]: title = _("Additional software has to be re-installed") elif trans.dependencies[PKGS_REMOVE]: title = _("Additional software has to be removed") elif trans.dependencies[PKGS_PURGE]: title = _("Additional software has to be purged") elif trans.dependencies[PKGS_UPGRADE]: title = _("Additional software has to be upgraded") elif trans.dependencies[PKGS_DOWNGRADE]: title = _("Additional software has to be downgraded") elif trans.dependencies[PKGS_KEEP]: title = _("Updates will be skipped") else: title = _("Additional changes are required") if trans.download: msg += "\n" msg += (_("%sB will be downloaded in total.") % apt_pkg.size_to_str(trans.download)) if trans.space < 0: msg += "\n" msg += (_("%sB of disk space will be freed.") % apt_pkg.size_to_str(trans.space)) elif trans.space > 0: msg += "\n" msg += (_("%sB more disk space will be used.") % apt_pkg.size_to_str(trans.space)) infoConf["title"] = title infoConf["description"] = msg return infoConf
def _get_transaction_summary(self, trans): #Create a message and the dependencies to be show. infoConf = { "title": "", "description": "", "dependencies": {} } for index, msg in enumerate([_("Install"), _("Reinstall"), _("Remove"), _("Purge"), _("Upgrade"), _("Downgrade"), _("Skip upgrade")]): if trans.dependencies[index]: listPiter = infoConf["dependencies"]["%s" % msg] = [] for pkg in trans.dependencies[index]: for object in self.map_package(pkg): listPiter.append(str(object)) # If there is only one type of changes (e.g. only installs) expand the # tree #FIXME: adapt the title and message accordingly #FIXME: Should we have different modes? Only show dependencies, only # initial packages or both? msg = _("Please take a look at the list of changes below.") title = "" if len(infoConf["dependencies"].keys()) == 1: if trans.dependencies[PKGS_INSTALL]: title = _("Additional software has to be installed") elif trans.dependencies[PKGS_REINSTALL]: title = _("Additional software has to be re-installed") elif trans.dependencies[PKGS_REMOVE]: title = _("Additional software has to be removed") elif trans.dependencies[PKGS_PURGE]: title = _("Additional software has to be purged") elif trans.dependencies[PKGS_UPGRADE]: title = _("Additional software has to be upgraded") elif trans.dependencies[PKGS_DOWNGRADE]: title = _("Additional software has to be downgraded") elif trans.dependencies[PKGS_KEEP]: title = _("Updates will be skipped") else: title = _("Additional changes are required") if trans.download: msg += "\n" msg += (_("%sB will be downloaded in total.") % apt_pkg.size_to_str(trans.download)) if trans.space < 0: msg += "\n" msg += (_("%sB of disk space will be freed.") % apt_pkg.size_to_str(trans.space)) elif trans.space > 0: msg += "\n" msg += (_("%sB more disk space will be used.") % apt_pkg.size_to_str(trans.space)) infoConf["title"] = title infoConf["description"] = msg return infoConf
def stop(self): """Invoked when the Acquire process stops running.""" base.AcquireProgress.stop(self) # Trick for getting a translation from apt self._write((_("Fetched %sB in %s (%sB/s)\n") % ( apt_pkg.size_to_str(self.fetched_bytes), apt_pkg.time_to_str(self.elapsed_time), apt_pkg.size_to_str(self.current_cps))).rstrip("\n")) # Delete the signal again. import signal signal.signal(signal.SIGWINCH, self._signal)
def commit(self): print 'APT COMMIT INSTALL %d DELETE %d GET %sB REQ %sB' % \ (self.cache.install_count, self.cache.delete_count, apt_pkg.size_to_str(self.cache.required_download), apt_pkg.size_to_str(self.cache.required_space)) mounted = self.chroot.mountvirtfs() try: self.cache.commit(fetch_progress=self._progress) except apt.cache.FetchFailedException, e: raise AptLibError('apt failed to fetch required archives')
def _on_download_changed(self, transaction, uri, status, desc, full_size, downloaded, message): """Callback for a changed download progress.""" try: progress = int(downloaded * 100 / full_size) except ZeroDivisionError: progress = -1 if status == DOWNLOAD_DONE: progress = 100 if progress > 100: progress = 100 text = desc[:] text += "\n<small>" #TRANSLATORS: %s is the full size in Bytes, e.g. 198M if status == DOWNLOAD_FETCHING: text += (_("Downloaded %sB of %sB") % (apt_pkg.size_to_str(downloaded), apt_pkg.size_to_str(full_size))) elif status == DOWNLOAD_DONE: if full_size != 0: text += _("Downloaded %sB") % apt_pkg.size_to_str(full_size) else: text += _("Downloaded") else: text += get_download_status_from_enum(status) text += "</small>" model = self.get_model() if not model: return try: iter = self._download_map[uri] except KeyError: # we we haven't seen the uri yet, add it now iter = model.append((text, progress, uri)) self._download_map[uri] = iter # and update the adj if needed adj = self.get_vadjustment() # this may be None (LP: #1024590) if adj: is_scrolled_down = ( adj.get_value() + adj.get_page_size() == adj.get_upper()) if is_scrolled_down: # If the treeview was scrolled to the end, do this again # after appending a new item self.scroll_to_cell( model.get_path(iter), None, False, False, False) else: model.set_value(iter, self.COL_TEXT, text) model.set_value(iter, self.COL_PROGRESS, progress)
def _on_download_changed(self, transaction, uri, status, desc, full_size, downloaded, message): """Callback for a changed download progress.""" try: progress = int(downloaded * 100 / full_size) except ZeroDivisionError: progress = -1 if status == DOWNLOAD_DONE: progress = 100 if progress > 100: progress = 100 text = desc[:] text += "\n<small>" #TRANSLATORS: %s is the full size in Bytes, e.g. 198M if status == DOWNLOAD_FETCHING: text += (_("Downloaded %sB of %sB") % (apt_pkg.size_to_str(downloaded), apt_pkg.size_to_str(full_size))) elif status == DOWNLOAD_DONE: if full_size != 0: text += _("Downloaded %sB") % apt_pkg.size_to_str(full_size) else: text += _("Downloaded") else: text += get_download_status_from_enum(status) text += "</small>" model = self.get_model() if not model: return try: iter = self._download_map[uri] except KeyError: # we we haven't seen the uri yet, add it now iter = model.append((text, progress, uri)) self._download_map[uri] = iter # and update the adj if needed adj = self.get_vadjustment() # this may be None (LP: #1024590) if adj: is_scrolled_down = (adj.get_value() + adj.get_page_size() == adj.get_upper()) if is_scrolled_down: # If the treeview was scrolled to the end, do this again # after appending a new item self.scroll_to_cell(model.get_path(iter), None, False, False, False) else: model.set_value(iter, self.COL_TEXT, text) model.set_value(iter, self.COL_PROGRESS, progress)
def _on_progress_details(self, transaction, items_done, items_total, bytes_done, bytes_total, speed, eta): """Callback for the ProgressDetails signal of the transaction.""" if bytes_total and speed: self._progress_details = ( _("Downloaded %sB of %sB at %sB/s") % (apt_pkg.size_to_str(bytes_done), apt_pkg.size_to_str(bytes_total), apt_pkg.size_to_str(speed))) elif bytes_total: self._progress_details = (_("Downloaded %sB of %sB") % (apt_pkg.size_to_str(bytes_done), apt_pkg.size_to_str(bytes_total))) else: self._progress_details = "" self._update_progress()
def GetUpdateInfos(self): """ Returns useful update informations. """ if self.cache_operation_lock.locked(): return "0B", "0B" self.cache_operation_lock.acquire() required_download, required_space = updates.get_update_infos() self.cache_operation_lock.release() return size_to_str(required_download) + "B", size_to_str(required_space) + "B"
def _on_progress_details_changed(self, transaction, items_done, items_total, bytes_done, bytes_total, speed, eta): """Update the progress bar text according to the latest progress details""" if items_total == 0 and bytes_total == 0: self.EmitTarget(" ") else: if speed != 0: self.EmitTarget(_("Downloaded %sB of %sB at %sB/s") % (apt_pkg.size_to_str(bytes_done), apt_pkg.size_to_str(bytes_total), apt_pkg.size_to_str(speed))) else: self.EmitTarget(_("Downloaded %sB of %sB") % (apt_pkg.size_to_str(bytes_done), apt_pkg.size_to_str(bytes_total)))
def _on_progress_details(self, transaction, items_done, items_total, bytes_done, bytes_total, speed, eta): """Callback for the ProgressDetails signal of the transaction.""" if bytes_total and speed: self._progress_details = (_("Downloaded %sB of %sB at %sB/s") % (apt_pkg.size_to_str(bytes_done), apt_pkg.size_to_str(bytes_total), apt_pkg.size_to_str(speed))) elif bytes_total: self._progress_details = (_("Downloaded %sB of %sB") % (apt_pkg.size_to_str(bytes_done), apt_pkg.size_to_str(bytes_total))) else: self._progress_details = "" self._update_progress()
def _report_hook(self, bytes_so_far, chunk_size, total_size): downloaded = bytes_so_far * chunk_size prefix = " " + apt_pkg.size_to_str(downloaded) + "B" printProgressBar(downloaded, total_size, prefix=prefix, suffix=self.get_busy_anim())
def get_changes(self, callback, finish_callback=None): """ Returns the changes one-by-one by firing the callback. """ for pkg in self.cache: reason = self.get_reason(pkg) if reason == None and not pkg.id in self.now_kept: continue if pkg.candidate == None: # What?! continue # Save the id, may be used later if not pkg.id in self.id_with_packages: self.id_with_packages[pkg.id] = (pkg, reason) callback( pkg.id, # id pkg.name, # name pkg.candidate.version, # version reason if reason else self.id_with_packages[pkg.id][1], # reason not pkg.id in self.now_kept, # status size_to_str(pkg.candidate.size) + "B" # size (FIXME: should use size_to_str outside) ) if finish_callback: finish_callback()
def GetUpdateInfos(self): """ Returns useful update informations. """ if self.cache_operation_lock.locked(): return "0B", "0B" self.cache_operation_lock.acquire() required_download, required_space = updates.get_update_infos() self.cache_operation_lock.release() return size_to_str(required_download) + "B", size_to_str( required_space) + "B"
def pulse(self, owner): """ we don't have a mainloop in this application, we just call processEvents here and elsewhere""" # FIXME: move the status_str and progress_str into python-apt # (python-apt need i18n first for this) AcquireProgress.pulse(self, owner) self.progress.setValue(self.percent) current_item = self.current_items + 1 if current_item > self.total_items: current_item = self.total_items if self.current_cps > 0: current_cps = apt_pkg.size_to_str(self.current_cps) if isinstance(current_cps, bytes): current_cps = current_cps.decode(locale.getpreferredencoding()) self.status.setText( _("Fetching file %li of %li at %sB/s") % (current_item, self.total_items, current_cps)) self.parent.window_main.progress_text.setText( "<i>" + _("About %s remaining") % FuzzyTimeToStr(self.eta) + "</i>") else: self.status.setText( _("Fetching file %li of %li") % (current_item, self.total_items)) self.parent.window_main.progress_text.setText(" ") QApplication.processEvents() return True
def fetch(self, item): apt.progress.base.AcquireProgress.fetch(self, item) line = 'APT GET ' + item.description if item.owner.filesize: line += ' [%sB]' % apt_pkg.size_to_str(item.owner.filesize) if self._quiet is False: print line
def pulse(self, owner): super(GtkAcquireProgressAdapter, self).pulse(owner) # only update if there is a noticable change if abs(self.percent - self.progress.get_fraction() * 100.0) > 0.1: self.progress.set_fraction(self.percent / 100.0) currentItem = self.current_items + 1 if currentItem > self.total_items: currentItem = self.total_items if self.current_cps > 0: current_cps = apt_pkg.size_to_str(self.current_cps) if isinstance(current_cps, bytes): current_cps = current_cps.decode( locale.getpreferredencoding()) self.status.set_text( _("Fetching file %li of %li at %sB/s") % (currentItem, self.total_items, current_cps)) self.progress.set_text( _("About %s remaining") % FuzzyTimeToStr(self.eta)) else: self.status.set_text( _("Fetching file %li of %li") % (currentItem, self.total_items)) self.progress.set_text(" ") while Gtk.events_pending(): Gtk.main_iteration() return (not self.canceled)
def ims_hit(self, item): """Called when an item is update (e.g. not modified on the server).""" base.AcquireProgress.ims_hit(self, item) line = _('Hit ') + item.description if item.owner.filesize: line += ' [%sB]' % apt_pkg.size_to_str(item.owner.filesize) self._write(line)
def update_status(self, uri, descr, shortDescr, status): FetchProgress.update_status(self, uri, descr, shortDescr, status) #logging.debug("Fetch: updateStatus %s %s" % (uri, status)) if status == apt_pkg.STAT_DONE: print "fetched %s (%.2f/100) at %sb/s" % ( uri, self.percent, apt_pkg.size_to_str(int(self.current_cps))) if sys.stdout.isatty(): sys.stdout.flush()
def _on_progress_details_changed(self, transaction, items_done, items_total, bytes_done, bytes_total, speed, eta): """Update the progress bar text according to the latest progress details""" if items_total == 0 and bytes_total == 0: self.EmitTarget(" ") else: if speed != 0: self.EmitTarget( _("Downloaded %sB of %sB at %sB/s") % (apt_pkg.size_to_str(bytes_done), apt_pkg.size_to_str(bytes_total), apt_pkg.size_to_str(speed))) else: self.EmitTarget( _("Downloaded %sB of %sB") % (apt_pkg.size_to_str(bytes_done), apt_pkg.size_to_str(bytes_total)))
def fetch(self, item): if item.owner.complete: return item.owner.id = self._id self._id += 1 line = "Get:" + str(item.owner.id) + " " + item.description if item.owner.filesize: line += (" [%sB]" % size_to_str(item.owner.filesize)) self.write(line)
def fetch(self, item): if item.owner.complete: return item.owner.id = self._id self._id += 1 line = "Get:" + str(item.owner.id) + " " + item.description if item.owner.filesize: line += " [%sB]" % size_to_str(item.owner.filesize) self.write(line)
def on_more_info(self, widget, status): '''Get more info on the selection''' self.ui.toolbar.back.set_sensitive(True) self.candidate = self.depcache.get_candidate_ver( self.cache[self.pkg_selected[0]]) if self.cache[self.pkg_selected[0]].current_state == \ apt_pkg.CURSTATE_INSTALLED: inst = True else: inst = False self.setup_infos( self.pkg_selected[0], self.ui.pages, self.pkg_selected[2], "\n".join([ self.pkg_selected[1].split("\n")[0].decode("UTF-8"), threadingops.getshortdesc(self.pkg_selected[0]).decode("UTF-8") ]), threadingops.getdesc(self.pkg_selected[0]).replace("\n ", "\n"), (apt_pkg.size_to_str(self.candidate.size), apt_pkg.size_to_str(self.candidate.installed_size)), self.candidate.ver_str, self.ui.pages.get_current_page(), inst)
def CurrentDownloadRate(self): """ Returns the current download rate, or an empty string. """ if not self.refreshing and not self.downloading: return "" return size_to_str(updates.cache_acquire_progress.current_cps if self. refreshing else updates.packages_acquire_progress. current_cps) + "B/s"
def _on_download_changed(self, transaction, uri, status, desc, full_size, downloaded, message): """Callback for a changed download progress.""" try: progress = downloaded * 100 / full_size except ZeroDivisionError: progress = -1 if status == DOWNLOAD_DONE: progress = 100 if progress > 100: progress = 100 text = desc[:] text += "\n<small>" #TRANSLATORS: %s is the full size in Bytes, e.g. 198M if status == DOWNLOAD_FETCHING: text += _("Downloaded %sB of %sB") % \ (apt_pkg.size_to_str(downloaded), apt_pkg.size_to_str(full_size)) elif status == DOWNLOAD_DONE: if full_size != 0: text += _("Downloaded %sB") % apt_pkg.size_to_str(full_size) else: text += _("Downloaded") else: text += get_download_status_from_enum(status) text += "</small>" model = self.get_model() try: iter = self._download_map[uri] except KeyError: adj = self.get_vadjustment() is_scrolled_down = adj.value + adj.page_size == adj.upper iter = model.append((text, progress, uri)) self._download_map[uri] = iter if is_scrolled_down: # If the treeview was scrolled to the end, do this again # after appending a new item self.scroll_to_cell(model.get_path(iter)) else: model.set(iter, self.COL_TEXT, text) model.set(iter, self.COL_PROGRESS, progress)
def fetch(self, item): """Called when some of the item's data is fetched.""" base.AcquireProgress.fetch(self, item) # It's complete already (e.g. Hit) if item.owner.complete: return item.owner.id = self._id self._id += 1 line = _("Get:") + "%s %s" % (item.owner.id, item.description) if item.owner.filesize: line += (" [%sB]" % apt_pkg.size_to_str(item.owner.filesize)) self._write(line)
def CurrentDownloadRate(self): """ Returns the current download rate, or an empty string. """ if not self.refreshing and not self.downloading: return "" return size_to_str( updates.cache_acquire_progress.current_cps if self.refreshing else updates.packages_acquire_progress.current_cps ) + "B/s"
def _on_download_changed(self, transaction, uri, status, desc, full_size, downloaded, message): if full_size == 0: progress = -1 else: progress = int(downloaded * 100 / full_size) if status == DOWNLOAD_DONE: progress = 100 if progress > 100: progress = 100 description = "" if status == DOWNLOAD_FETCHING: description += (_("Downloaded %sB of %sB") % (apt_pkg.size_to_str(downloaded), apt_pkg.size_to_str(full_size))) elif status == DOWNLOAD_DONE: if full_size != 0: description += _("Downloaded %sB") % apt_pkg.size_to_str(full_size) else: description += _("Downloaded") else: description += get_download_status_from_enum(status) self.EmitDownloadPercentChild(uri, "cs-packages", desc[:], progress, description)
def refresh_app_basket(self): '''Refresh the apps basket''' self.ui.search_pkg.set_sensitive(False) self.ui.apps_basket.model.clear() self.total_download = 0 self.total_install = 0 self.depends = [] for items in sorted(self.marked_as_install): self.get_pkg_depends(items) self.info = self.depcache.get_candidate_ver(self.cache[items]) self.total_download += self.info.size self.total_install += self.info.installed_size self.ui.apps_basket.model.append([ items.capitalize(), apt_pkg.size_to_str(self.info.size), apt_pkg.size_to_str(self.info.installed_size), self.info.ver_str]) for item in sorted(self.depends): item = item.encode('ascii', 'ignore') if not self.cache[item].current_state == \ apt_pkg.CURSTATE_INSTALLED: if not self.value_in_model( item, self.ui.apps_basket.model): self.info = self.depcache.get_candidate_ver( self.cache[item]) if self.info is None: self.ui.apps_basket.model.append([ " " * 4 + item + _(" (requested by ") + items + ")", _("unknown"), _("unknown"), _("unknown")]) else: self.total_download += self.info.size self.total_install += self.info.installed_size self.ui.apps_basket.model.append([ " " * 4 + item + _(" (requested by ") + items + ")", apt_pkg.size_to_str(self.info.size), apt_pkg.size_to_str(self.info.installed_size), self.info.ver_str]) if len(self.ui.apps_basket.model) == 0: self.ui.riepilogue_label.set_text(_( "Put some apps in the basket to install them")) self.ui.install_pkgs.set_sensitive(False) self.ui.remove_mai_button.set_sensitive(False) self.ui.basket_radio.label.set_text(_("Apps Basket")) else: self.ui.riepilogue_label.set_text("%s %s, %s %s, %s %s" % (len( self.marked_as_install), _("package marked"), apt_pkg.size_to_str(self.total_download), _("to download"), apt_pkg.size_to_str(self.total_install), _("to install"))) self.ui.install_pkgs.set_sensitive(True) self.ui.remove_mai_button.set_sensitive(True) self.ui.basket_radio.label.set_text(_("Apps Basket") + " (%s)" % len(self.marked_as_install)) self.on_selected_available(self.ui.apps_all) self.ui.categorie_icon.set_from_icon_name("applications-other", Gtk.IconSize.LARGE_TOOLBAR) self.ui.categorie_label.set_text(_("Apps Basket")) self.ui.pkgs_count.set_text("%s " % len(self.ui.apps_basket.model) + _("packages")) self.ui.statusbox.combo.set_visible(False)
def pulse(self): apt.progress.FetchProgress.pulse(self) if self.currentCPS > 0: info = self.frontend.get_string('apt_progress_cps') info = info.replace('${SPEED}', apt_pkg.size_to_str(self.currentCPS)) else: info = self.frontend.get_string('apt_progress') info = info.replace('${INDEX}', str(self.currentItems)) info = info.replace('${TOTAL}', str(self.totalItems)) self.frontend.debconf_progress_info(info) self.frontend.debconf_progress_set(self.percent) self.frontend.refresh() return True
def pulse(self): apt.progress.FetchProgress.pulse(self) if self.currentCPS > 0: info = self.frontend.get_string('apt_progress_cps') info = info.replace( '${SPEED}', apt_pkg.size_to_str(self.currentCPS)) else: info = self.frontend.get_string('apt_progress') info = info.replace('${INDEX}', str(self.currentItems)) info = info.replace('${TOTAL}', str(self.totalItems)) self.frontend.debconf_progress_info(info) self.frontend.debconf_progress_set(self.percent) self.frontend.refresh() return True
def stop(self): apt.progress.base.AcquireProgress.stop(self) duration = datetime.datetime.utcnow() - self._time if self.total_items == 0: return line = 'APT GOT %s items' % self.total_items if duration.seconds >= 60: line += ' in %dm:%02ds' % divmod(duration.seconds, 60) else: line += ' in %d.%ds' % (duration.seconds, duration.microseconds) line += ' [%sB]' % apt_pkg.size_to_str(self.total_bytes) print line
def pulse(self, owner): super(GDebiGtk.FetchProgressAdapter, self).pulse(owner) at_item = min(self.current_items + 1, self.total_items) if self.current_cps > 0: self.progress.set_text( _("File %s of %s at %sB/s") % (at_item, self.total_items, apt_pkg.size_to_str(self.current_cps))) else: self.progress.set_text( _("File %s of %s") % (at_item, self.total_items)) self.progress.set_fraction(self.current_bytes / self.total_bytes) while Gtk.events_pending(): Gtk.main_iteration() return True
def pulse(self): """Called periodically to update the user interface. Return True to continue or False to cancel. """ FetchProgress.pulse(self) if self.currentCPS > 0: s = "[%2.f%%] %sB/s %s" % ( self.percent, apt_pkg.size_to_str(int( self.currentCPS)), apt_pkg.time_to_str(int(self.eta))) else: s = "%2.f%% [Working]" % (self.percent) print "\r%s" % (s), sys.stdout.flush() return True
def __init__(self, parent): super(Clean, self).__init__(parent) self.main_dlg.set_title('Καθαρισμός μνήμης πακέτων...') self.main_dlg_lbl_title.set_markup( '<b><big>Βρέθηκαν τα παρακάτω αρχεία στην μνήμη\n</big></b>') self.main_dlg_img_lbl.set_from_icon_name('package-x-generic', Gtk.IconSize.SMALL_TOOLBAR) self.main_dlg_img_lbl.set_pixel_size(-1) if not self.find(): dialogs.InfoDialog( 'Δεν υπάρχουν αρχεία στην μνήμη πακέτων για διαγραφή.', 'Ειδοποίηση').showup() return if len(self.pkgs) == 1: self.main_dlg_lbl_space.set_markup( '%s αρχείο βρέθηκε, %sB χώρου στο δίσκο θα ελευθερωθούν.' \ %(str(len(self.pkgs)), apt_pkg.size_to_str(sum(pkg.size for pkg in self.pkgs)))) else: self.main_dlg_lbl_space.set_markup( '%s αρχεία βρέθηκαν, %sB χώρου στο δίσκο θα ελευθερωθούν.' \ %(str(len(self.pkgs)), apt_pkg.size_to_str(sum(pkg.size for pkg in self.pkgs)))) self.populate_treeview() self.main_dlg.show_all()
def on_more_info(self, widget, status): '''Get more info on the selection''' self.ui.toolbar.back.set_sensitive(True) self.candidate = self.depcache.get_candidate_ver( self.cache[self.pkg_selected[0]]) if self.cache[self.pkg_selected[0]].current_state == \ apt_pkg.CURSTATE_INSTALLED: inst = True else: inst = False self.setup_infos( self.pkg_selected[0], self.ui.pages, self.pkg_selected[2], "\n".join([self.pkg_selected[1].split("\n")[0].decode("UTF-8"), threadingops.getshortdesc( self.pkg_selected[0]).decode("UTF-8")]), threadingops.getdesc(self.pkg_selected[0]).replace("\n ", "\n"), (apt_pkg.size_to_str(self.candidate.size), apt_pkg.size_to_str(self.candidate.installed_size)), self.candidate.ver_str, self.ui.pages.get_current_page(), inst )
def pulse(self): """Called periodically to update the user interface. Return True to continue or False to cancel. """ FetchProgress.pulse(self) if self.currentCPS > 0: s = "[%2.f%%] %sB/s %s" % (self.percent, apt_pkg.size_to_str(int(self.currentCPS)), apt_pkg.time_to_str(int(self.eta))) else: s = "%2.f%% [Working]" % (self.percent) print "\r%s" % (s), sys.stdout.flush() return True
def pulse(self, owner): super(KDEFetchProgressAdapter, self).pulse(owner) at_item = min(self.current_items + 1, self.total_items) if self.current_cps > 0: self.label.setText( _("Downloading additional package files...") + _("File %s of %s at %sB/s" % (at_item, self.total_items, apt_pkg.size_to_str(self.current_cps)))) else: self.label.setText( _("Downloading additional package files...") + _("File %s of %s" % (at_item, self.total_items))) self.progress.setValue(100 * self.current_bytes / self.total_bytes) KApplication.kApplication().processEvents() return True
def pulse(self, owner): apt.progress.base.AcquireProgress.pulse(self, owner) if self.current_cps > 0: info = self.frontend.get_string('apt_progress_cps') info = info.replace( '${SPEED}', apt_pkg.size_to_str(self.current_cps)) else: info = self.frontend.get_string('apt_progress') info = info.replace('${INDEX}', str(self.current_items)) info = info.replace('${TOTAL}', str(self.total_items)) self.frontend.debconf_progress_info(info) self.frontend.debconf_progress_set( ((self.current_bytes + self.current_items) * 100.0) / float(self.total_bytes + self.total_items)) self.frontend.refresh() return True
def pulse(self, owner): """Periodically invoked while the Acquire process is underway. Return False if the user asked to cancel the whole Acquire process.""" apt.progress.base.AcquireProgress.pulse(self, owner) self.percent = (((self.current_bytes + self.current_items) * 100.0) / float(self.total_bytes + self.total_items)) end = "" if self.current_cps: eta = long(float(self.total_bytes - self.current_bytes) / self.current_cps) end = " %sB/s %s" % (apt_pkg.size_to_str(self.current_cps), apt_pkg.time_to_str(eta)) global_event.emit("update-list-update", self.percent, self.status_message, end) return True
def pulse(self, owner): apt.progress.base.AcquireProgress.pulse(self, owner) if self.current_cps > 0: info = self.frontend.get_string('apt_progress_cps') current_cps = apt_pkg.size_to_str(self.current_cps) if isinstance(current_cps, bytes): current_cps = current_cps.decode() info = info.replace('${SPEED}', current_cps) else: info = self.frontend.get_string('apt_progress') info = info.replace('${INDEX}', str(self.current_items)) info = info.replace('${TOTAL}', str(self.total_items)) self.frontend.debconf_progress_info(info) self.frontend.debconf_progress_set( ((self.current_bytes + self.current_items) * 100.0) / float(self.total_bytes + self.total_items)) self.frontend.refresh() return True
def pulse(self, owner): apt.progress.base.AcquireProgress.pulse(self, owner) self.progress.setValue((self.current_bytes + self.current_items) / float(self.total_bytes + self.total_items)) current_item = self.current_items + 1 if current_item > self.total_items: current_item = self.total_items label_text = _("Downloading additional package files...") if self.current_cps > 0: label_text += _("File %s of %s at %sB/s") % ( self.current_items, self.total_items, apt_pkg.size_to_str(self.current_cps)) else: label_text += _("File %s of %s") % (self.current_items, self.total_items) self.label.setText(label_text) KApplication.kApplication().processEvents() return True
def pulse(self): old.FetchProgress.pulse(self) current_item = self.currentItems + 1 if current_item > self.totalItems: current_item = self.totalItems if self.current_cps > 0: text = (_("Downloading file %(current)li of %(total)li with " "%(speed)s/s") % \ {"current": current_item, "total": self.totalItems, "speed": apt_pkg.size_to_str(self.currentCPS)}) else: text = (_("Downloading file %(current)li of %(total)li") % \ {"current": current_item, "total": self.totalItems}) self.emit("status-changed", text, self.percent) while self._context.pending(): self._context.iteration() return self._continue
def pulse(self, owner): apt.progress.base.AcquireProgress.pulse(self, owner) self.dialog.installationProgress.setValue( (self.current_bytes + self.current_items) / float(self.total_bytes + self.total_items) * 100) current_item = self.current_items + 1 if current_item > self.total_items: current_item = self.total_items label_text = _("Downloading additional package files...") if self.current_cps > 0: label_text += _("File %s of %s at %sB/s") % ( self.current_items, self.total_items, apt_pkg.size_to_str(self.current_cps)) else: label_text += _("File %s of %s") % ( self.current_items, self.total_items) self.dialog.installingLabel.setText(label_text) QApplication.processEvents() return self._continue
def pulse(self, owner): current_item = self.current_items + 1 if current_item > self.total_items: current_item = self.total_items if self.current_cps > 0: text = (_("Downloading file %(current)li of %(total)li with " "%(speed)s/s") % {"current": current_item, "total": self.total_items, "speed": apt_pkg.size_to_str(self.current_cps)}) else: text = (_("Downloading file %(current)li of %(total)li") % {"current": current_item, "total": self.total_items}) self.status_label.setText(text) percent = (((self.current_bytes + self.current_items) * 100.0) / float(self.total_bytes + self.total_items)) self.pbar.setValue(int(percent)) QtGui.qApp.processEvents() return True
def pulse(self, owner): """ we don't have a mainloop in this application, we just call processEvents here and elsewhere""" # FIXME: move the status_str and progress_str into python-apt # (python-apt need i18n first for this) AcquireProgress.pulse(self, owner) self.progress.setValue(self.percent) current_item = self.current_items + 1 if current_item > self.total_items: current_item = self.total_items if self.current_cps > 0: current_cps = apt_pkg.size_to_str(self.current_cps) if isinstance(current_cps, bytes): current_cps = current_cps.decode(locale.getpreferredencoding()) self.status.setText(_("Fetching file %li of %li at %sB/s") % (current_item, self.total_items, current_cps)) self.parent.window_main.progress_text.setText("<i>" + _("About %s remaining") % FuzzyTimeToStr(self.eta) + "</i>") else: self.status.setText(_("Fetching file %li of %li") % (current_item, self.total_items)) self.parent.window_main.progress_text.setText(" ") QApplication.processEvents() return True
def pulse(self, owner): base.AcquireProgress.pulse(self, owner) current_item = self.current_items + 1 if current_item > self.total_items: current_item = self.total_items if self.current_cps > 0: text = (_("Downloading file %(current)li of %(total)li with " "%(speed)s/s") % \ {"current": current_item, "total": self.total_items, "speed": apt_pkg.size_to_str(self.current_cps)}) else: text = (_("Downloading file %(current)li of %(total)li") % \ {"current": current_item, "total": self.total_items}) percent = (((self.current_bytes + self.current_items) * 100.0) / float(self.total_bytes + self.total_items)) self.emit("status-changed", text, percent) while self._context.pending(): self._context.iteration() return self._continue