def reset(self): rows = [] for j, bw in enumerate(self.bws): cols = [] for i in range(5): data = bw.at(i) text = { 0: lambda x: x.strftime('%H:%M %d/%m/%y'), 1: lambda x: str(x), }.get(i, lambda x: '%.2f %s' % smart_bytes(x))(data) cols.append( urwid.AttrWrap(urwid.Text(text, align='right'), 'data %d' % (j % 2, ))) rows.append(urwid.Columns(cols, 1, min_width=12)) self.tbody.body = urwid.SimpleListWalker(rows) self.start.set_text( ('date', self.settings.start.strftime(' %d %B %Y '))) self.total['Uptime'].set_text(str(self.totaldata['uptime'])) self.total['Received'].set_text( '%.2f %s' % smart_bytes(self.totaldata['received'])) self.total['Transmitted'].set_text( '%.2f %s' % smart_bytes(self.totaldata['transmitted'])) self.total['Total'].set_text('%.2f %s' % smart_bytes(self.totaldata['total'])) self.status.set_text( ('banner', datetime.datetime.now().strftime(' %d %B, %Y - %H:%M:%S ')))
def install_deps(): import apt if not os.environ['USER'] == 'root': print 'ERROR: This program requires root access.' print 'Use `sudo python %s`' % sys.argv[0] raise SystemExit(1) def check_version(pkg, ver): return [v for v in pkg.versions if v >= ver] acq_progress = apt.progress.text.AcquireProgress() inst_progress = apt.progress.base.InstallProgress() cache = apt.Cache(apt.progress.text.OpProgress()) qtgui = 'python-pyside.qtgui' sqlobj = 'python-sqlobject' urwid = 'python-urwid' version = {qtgui: '1.0.3', sqlobj: '0.7', urwid: '0.9'} is_installed = {} for p in (qtgui, sqlobj, urwid): is_installed[p] = cache[p].is_installed and \ check_version(cache[p], version[p]) if not is_installed[qtgui]: print "It requires ", version print 'Do you want to install it from PPA? (Y/n)', if raw_input() == 'n': print 'ERROR: Could not install it. Quitting...' raise SystemExit(1) command = 'add-apt-repository ppa:pyside'.split() try: subprocess.check_call(command) cache.update(acq_progress) cache.open() cache.commit(acq_progress, inst_progress) if not check_version(cache[qtgui], version[qtgui]): print 'ERROR: Could not find required pyside package.' print 'You might try changing to main repository server.' raise SystemExit(1) except Exception as e: print 'ERROR: Could not add PPA repository. Quitting...' print e raise SystemExit(1) cache[qtgui].mark_install() if not is_installed[sqlobj]: cache[sqlobj].mark_install() if not is_installed[urwid]: cache[urwid].mark_install() if cache.install_count > 0: print "Need to download %.2f %s." \ % smart_bytes(cache.required_download) print "Do you want to continue? (Y/n)", if raw_input() == 'n': raise SystemExit(1) cache.commit(acq_progress, inst_progress)
def reset(self): rows = [] for j, bw in enumerate(self.bws): cols = [] for i in range(5): data = bw.at(i) text = { 0: lambda x: x.strftime('%H:%M %d/%m/%y'), 1: lambda x: str(x), }.get(i, lambda x: '%.2f %s' % smart_bytes(x))(data) cols.append(urwid.AttrWrap(urwid.Text(text, align='right'), 'data %d' % (j%2,))) rows.append(urwid.Columns(cols, 1, min_width=12)) self.tbody.body = urwid.SimpleListWalker(rows) self.start.set_text(('date', self.settings.start.strftime(' %d %B %Y '))) self.total['Uptime'].set_text(str(self.totaldata['uptime'])) self.total['Received'].set_text('%.2f %s' % smart_bytes(self.totaldata['received'])) self.total['Transmitted'].set_text('%.2f %s' % smart_bytes(self.totaldata['transmitted'])) self.total['Total'].set_text('%.2f %s' % smart_bytes(self.totaldata['total'])) self.status.set_text(('banner', datetime.datetime.now().strftime(' %d %B, %Y - %H:%M:%S ')))
def smart_bytes(bytes_): sb = smart_bytes(bytes_) return "%s %s" % (QLocale().toString(sb[0]), sb[1])