def show_lock_owner(pid, logger): """Output information about another process that is holding the yum lock. :param pid: the process id number of the process holding the yum lock :param logger: the logger to output the information to :return: a dictionary containing information about the process. This is the same as the dictionary returned by :func:`get_process_info`. """ ps = get_process_info(pid) if not ps: return None # This yumBackend isn't very friendly, so... msg = _(' The application with PID %d is: %s') if ps['name'] == 'yumBackend.py': nmsg = msg % (pid, 'PackageKit') else: nmsg = msg % (pid, ps['name']) logger.critical("%s", nmsg) logger.critical( _(" Memory : %5s RSS (%5sB VSZ)") % (format_number( int(ps['vmrss']) * 1024), format_number(int(ps['vmsize']) * 1024))) ago = seconds_to_ui_time(int(time.time()) - ps['start_time']) logger.critical( _(" Started: %s - %s ago") % (time.ctime(ps['start_time']), ago)) logger.critical(_(" State : %s") % ps['state']) return ps
def show_lock_owner(pid, logger): """Output information about another process that is holding the yum lock. :param pid: the process id number of the process holding the yum lock :param logger: the logger to output the information to :return: a dictionary containing information about the process. This is the same as the dictionary returned by :func:`get_process_info`. """ ps = get_process_info(pid) if not ps: return None # This yumBackend isn't very friendly, so... msg = _(' The application with PID %d is: %s') if ps['name'] == 'yumBackend.py': nmsg = msg % (pid, 'PackageKit') else: nmsg = msg % (pid, ps['name']) logger.critical("%s", nmsg) logger.critical(_(" Memory : %5s RSS (%5sB VSZ)") % (format_number(int(ps['vmrss']) * 1024), format_number(int(ps['vmsize']) * 1024))) ago = seconds_to_ui_time(int(time.time()) - ps['start_time']) logger.critical(_(" Started: %s - %s ago") % (time.ctime(ps['start_time']), ago)) logger.critical(_(" State : %s") % ps['state']) return ps
def summarize(self): if not self.upgrade_target: msg = [ _("No upgrade in progress.") ] elif not self.upgrade_ready: msg = [ _("Upgrade to %s in progress.") % self.upgrade_target, _("Use 'fedup2 resume' to resume downloading."), _("Use 'fedup2 cancel' to cancel the upgrade."), ] localdata = self.get_size_local() if localdata: total = int(self.size_total) pct = 100.0*localdata/total msg[0] = _("Download of %s is %.1f%% complete (%s/%s)") % ( self.upgrade_target, pct, format_number(localdata), format_number(total) ) else: msg = [ _("Ready for upgrade to %s.") % self.upgrade_target, _("Use 'fedup2 reboot' to start the upgrade."), _("Use 'fedup2 refresh' to check for new updates."), _("Use 'fedup2 cancel' to cancel the upgrade."), ] return "\n".join(msg)
def end(self, payload, status, err_msg): start = now = time() text = unicode(payload) size = int(payload.download_size) if self.multi_download_id is not None: text = self.multi_download_id # update state if status == dnf.callback.STATUS_MIRROR: pass elif status == dnf.callback.STATUS_DRPM: self.done_drpm += 1 elif text in self.state: if self.multi_download_id is not None: start, done = self.state[text] size = 0 else: start, done = self.state.pop(text) size -= done if unicode(payload) in self.active: self.active.remove(unicode(payload)) self.done_files += 1 self.done_size += size elif status == dnf.callback.STATUS_ALREADY_EXISTS: self.done_files += 1 self.done_size += size text = unicode(payload) if status: # the error message, no trimming if status is dnf.callback.STATUS_DRPM and self.total_drpm > 1: msg = '[%s %d/%d] %s: ' % (self.STATUS_2_STR[status], self.done_drpm, self.total_drpm, text) else: msg = '[%s] %s: ' % (self.STATUS_2_STR[status], text) left = _term_width() - len(msg) - 1 msg = '%s%-*s\n' % (msg, left, err_msg) else: if self.total_files > 1: text = '(%d/%d): %s' % (self.done_files, self.total_files, text) # average rate, file size, download time tm = max(now - start, 0.001) msg = ' %5sB/s | %5sB %9s \n' % (format_number( float(done) / tm), format_number(done), format_time(tm)) left = _term_width() - len(msg) msg = '%-*.*s%s' % (left, left, text, msg) self.message(msg) # now there's a blank line. fill it if possible. if self.active: self._update(now)
def _update(self, now): if self.last_time: delta_time = now - self.last_time delta_size = self.done_size - self.last_size if delta_time > 0 and delta_size > 0: # update the average rate rate = delta_size / delta_time if self.rate is not None: weight = min(delta_time/self.rate_average, 1) rate = rate*weight + self.rate*(1 - weight) self.rate = rate self.last_time = now self.last_size = self.done_size if not self.isatty: return # pick one of the active downloads text = self.active[int(now/self.tick_period) % len(self.active)] if self.total_files > 1: n = '%d' % (self.done_files + 1) if len(self.active) > 1: n += '-%d' % (self.done_files + len(self.active)) text = '(%s/%d): %s' % (n, self.total_files, text) # average rate, total done size, estimated remaining time if self.rate and self.total_size: time_eta = format_time((self.total_size - self.done_size) / self.rate) else: time_eta = '--:--' msg = ' %5sB/s | %5sB %9s ETA\r' % ( format_number(self.rate) if self.rate else '--- ', format_number(self.done_size), time_eta) left = _term_width() - len(msg) bl = (left - 7)//2 if bl > 8: # use part of the remaining space for progress bar if self.total_size: pct = self.done_size * 100 // self.total_size n, p = divmod(self.done_size * bl * 2 // self.total_size, 2) bar = '=' * n + '-' * p msg = '%3d%% [%-*s]%s' % (pct, bl, bar, msg) left -= bl + 7 else: n = self.unknown_progres - 3 p = 3 n = 0 if n < 0 else n bar = ' ' * n + '=' * p msg = '%3s%% [%-*s]%s' % ('???', bl, bar, msg) left -= bl + 7 self.unknown_progres = self.unknown_progres + 3 if self.unknown_progres + 3 < bl \ else 0 self.message('%-*.*s%s' % (left, left, text, msg))
def _update(self, now): if self.last_time: delta_time = now - self.last_time delta_size = self.done_size - self.last_size if delta_time > 0 and delta_size > 0: # update the average rate rate = delta_size / delta_time if self.rate is not None: weight = min(delta_time / self.rate_average, 1) rate = rate * weight + self.rate * (1 - weight) self.rate = rate self.last_time = now self.last_size = self.done_size if not self.isatty: return # pick one of the active downloads text = self.active[int(now / self.tick_period) % len(self.active)] if self.total_files > 1: n = '%d' % (self.done_files + 1) if len(self.active) > 1: n += '-%d' % (self.done_files + len(self.active)) text = '(%s/%d): %s' % (n, self.total_files, text) # average rate, total done size, estimated remaining time if self.rate and self.total_size: time_eta = format_time( (self.total_size - self.done_size) / self.rate) else: time_eta = '--:--' msg = ' %5sB/s | %5sB %9s ETA\r' % (format_number( self.rate) if self.rate else '--- ', format_number( self.done_size), time_eta) left = _term_width() - len(msg) bl = (left - 7) // 2 if bl > 8: # use part of the remaining space for progress bar if self.total_size: pct = self.done_size * 100 // self.total_size n, p = divmod(self.done_size * bl * 2 // self.total_size, 2) bar = '=' * n + '-' * p msg = '%3d%% [%-*s]%s' % (pct, bl, bar, msg) left -= bl + 7 else: n = self.unknown_progres - 3 p = 3 n = 0 if n < 0 else n bar = ' ' * n + '=' * p msg = '%3s%% [%-*s]%s' % ('???', bl, bar, msg) left -= bl + 7 self.unknown_progres = self.unknown_progres + 3 if self.unknown_progres + 3 < bl \ else 0 self.message('%-*.*s%s' % (left, left, text, msg))
def test_format_number(self): self.assertEqual(format_number(None), '0.0 ') self.assertEqual(format_number(-1), '-1 ') self.assertEqual(format_number(1.0), '1.0 ') self.assertEqual(format_number(999.0), '999 ') self.assertEqual(format_number(1000.0), '1.0 k') self.assertEqual(format_number(1 << 20), '1.0 M') self.assertEqual(format_number(1 << 30), '1.0 G') self.assertEqual(format_number(1e6, SI=1), '1.0 M') self.assertEqual(format_number(1e9, SI=1), '1.0 G')
def test_format_number(self): self.assertEquals(format_number(None), "0.0 ") self.assertEquals(format_number(-1), "-1 ") self.assertEquals(format_number(1.0), "1.0 ") self.assertEquals(format_number(999.0), "999 ") self.assertEquals(format_number(1000.0), "1.0 k") self.assertEquals(format_number(1 << 20), "1.0 M") self.assertEquals(format_number(1 << 30), "1.0 G") self.assertEquals(format_number(1e6, SI=1), "1.0 M") self.assertEquals(format_number(1e9, SI=1), "1.0 G")
def end(self, payload, status, err_msg): start = now = time() text = unicode(payload) size = int(payload.download_size) done = 0 # update state if status == dnf.callback.STATUS_MIRROR: pass elif status == dnf.callback.STATUS_DRPM: self.done_drpm += 1 elif text in self.state: start, done = self.state.pop(text) self.active.remove(text) size -= done self.done_files += 1 self.done_size += size elif status == dnf.callback.STATUS_ALREADY_EXISTS: self.done_files += 1 self.done_size += size if status: # the error message, no trimming if status is dnf.callback.STATUS_DRPM and self.total_drpm > 1: msg = '[%s %d/%d] %s: ' % (self.STATUS_2_STR[status], self.done_drpm, self.total_drpm, text) else: msg = '[%s] %s: ' % (self.STATUS_2_STR[status], text) left = _term_width() - len(msg) - 1 msg = '%s%-*s\n' % (msg, left, err_msg) else: if self.total_files > 1: text = '(%d/%d): %s' % (self.done_files, self.total_files, text) # average rate, file size, download time tm = max(now - start, 0.001) msg = ' %5sB/s | %5sB %9s \n' % ( format_number(float(done) / tm), format_number(done), format_time(tm)) left = _term_width() - len(msg) msg = '%-*.*s%s' % (left, left, text, msg) self.message(msg) # now there's a blank line. fill it if possible. if self.active: self._update(now)
def end(self, text, size, err, status='FAILED'): """Display a message that file has finished downloading text -- the file id size -- the file size. None => not a file. err -- None if ok, error message otherwise status -- Download status (relevant when err != None) """ start = now = time() if size is not None: # update state if text in self.state: start, done = self.state.pop(text) self.active.remove(text) size -= done self.done_files += 1 self.done_size += size if err: # the error message, no trimming msg = '[%s] %s: ' % (status, text) left = _term_width() - len(msg) - 1 msg = '%s%-*s\n' % (msg, left, err) else: if self.total_files > 1: text = '(%d/%d): %s' % (self.done_files, self.total_files, text) # average rate, file size, download time tm = max(now - start, 0.001) msg = ' %5sB/s | %5sB %9s \n' % ( format_number(float(done) / tm), format_number(done), format_time(tm)) left = _term_width() - len(msg) msg = '%-*.*s%s' % (left, left, text, msg) self.fo.write(msg) self.fo.flush() # now there's a blank line. fill it if possible. if self.active: self._update(now)
def _update(self, now): if self.last_time: delta_time = now - self.last_time delta_size = self.done_size - self.last_size if delta_time > 0 and delta_size > 0: # update the average rate rate = delta_size / delta_time if self.rate is not None: weight = min(delta_time/self.rate_average, 1) rate = rate*weight + self.rate*(1 - weight) self.rate = rate self.last_time = now self.last_size = self.done_size # pick one of the active downloads text = self.active[int(now/self.tick_period) % len(self.active)] if self.total_files > 1: n = '%d' % (self.done_files + 1) if len(self.active) > 1: n += '-%d' % (self.done_files + len(self.active)) text = '(%s/%d): %s' % (n, self.total_files, text) # average rate, total done size, estimated remaining time msg = ' %5sB/s | %5sB %9s ETA\r' % ( format_number(self.rate) if self.rate else '--- ', format_number(self.done_size), format_time((self.total_size - self.done_size) / self.rate) if self.rate else '--:--') left = _term_width() - len(msg) bl = (left - 7)//2 # the progressbar is way too big when installing in parallel indent = int(bl / 2) if _term_width() <= 120 else 0 if (bl - indent) > 8: # use part of the remaining space for progress bar pct = self.done_size*100 // self.total_size n, p = divmod(self.done_size*(bl - indent)*2 // self.total_size, 2) bar = '='*n + '-'*p msg = '%3d%% [%-*s]%s' % (pct, bl - indent, bar, msg) left -= bl + 7 self.fo.write('%-*.*s%s' % (left + indent, left + indent, text, msg)) self.fo.flush()
def end(self, payload, status, err_msg): start = now = time() text = str(payload) size = int(payload.download_size) # update state if status in (dnf.callback.STATUS_MIRROR, dnf.callback.STATUS_DRPM): pass elif text in self.state: start, done = self.state.pop(text) self.active.remove(text) size -= done self.done_files += 1 self.done_size += size elif status == dnf.callback.STATUS_ALREADY_EXISTS: self.done_files += 1 self.done_size += size if status: # the error message, no trimming msg = '[%s] %s: ' % (self.STATUS_2_STR[status], text) left = _term_width() - len(msg) - 1 msg = '%s%-*s\n' % (msg, left, err_msg) else: if self.total_files > 1: text = '(%d/%d): %s' % (self.done_files, self.total_files, text) # average rate, file size, download time tm = max(now - start, 0.001) msg = ' %5sB/s | %5sB %9s \n' % (format_number( float(done) / tm), format_number(done), format_time(tm)) left = _term_width() - len(msg) msg = '%-*.*s%s' % (left, left, text, msg) self.fo.write(msg) self.fo.flush() # now there's a blank line. fill it if possible. if self.active: self._update(now)
def show_lock_owner(pid): """Output information about process holding a lock.""" ps = get_process_info(pid) if not ps: msg = _('Unable to find information about the locking process (PID %d)') logger.critical(msg, pid) return msg = _(' The application with PID %d is: %s') % (pid, ps['name']) logger.critical("%s", msg) logger.critical(_(" Memory : %5s RSS (%5sB VSZ)"), format_number(int(ps['vmrss']) * 1024), format_number(int(ps['vmsize']) * 1024)) ago = seconds_to_ui_time(int(time.time()) - ps['start_time']) logger.critical(_(' Started: %s - %s ago'), time.ctime(ps['start_time']), ago) logger.critical(_(' State : %s'), ps['state']) return
def _update(self, now): if self.last_time: delta_time = now - self.last_time delta_size = self.done_size - self.last_size if delta_time > 0 and delta_size > 0: # update the average rate rate = delta_size / delta_time if self.rate is not None: weight = min(delta_time / self.rate_average, 1) rate = rate * weight + self.rate * (1 - weight) self.rate = rate self.last_time = now self.last_size = self.done_size # pick one of the active downloads text = self.active[int(now / self.tick_period) % len(self.active)] if self.total_files > 1: n = "%d" % (self.done_files + 1) if len(self.active) > 1: n += "-%d" % (self.done_files + len(self.active)) text = "(%s/%d): %s" % (n, self.total_files, text) # average rate, total done size, estimated remaining time msg = " %5sB/s | %5sB %9s ETA\r" % ( format_number(self.rate) if self.rate else "--- ", format_number(self.done_size), format_time((self.total_size - self.done_size) / self.rate) if self.rate else "--:--", ) left = _term_width() - len(msg) bl = (left - 7) // 2 if bl > 8: # use part of the remaining space for progress bar pct = self.done_size * 100 // self.total_size n, p = divmod(self.done_size * bl * 2 // self.total_size, 2) bar = "=" * n + "-" * p msg = "%3d%% [%-*s]%s" % (pct, bl, bar, msg) left -= bl + 7 self.fo.write("%-*.*s%s" % (left, left, text, msg)) self.fo.flush()
def format_size(y, pos): from dnf.cli.format import format_number return format_number(y, SI=1)