def refresh_device_list(self): treeview_backups_model = self.xml.get_widget( 'treeview_backups').get_model() treeview_backups_model.clear() writable_devices = backup.get_writable_devices() for uuid in writable_devices: path = backup.get_mount_point_for_uuid(uuid) if backup.get_device_type(uuid) == 'gvfs': icon = self.main_window.render_icon(gtk.STOCK_NETWORK, gtk.ICON_SIZE_DIALOG) elif backup.get_device_type(uuid) == 'local': icon = self.main_window.render_icon(gtk.STOCK_HARDDISK, gtk.ICON_SIZE_DIALOG) else: icon = self.main_window.render_icon(gtk.STOCK_DIALOG_QUESTION, gtk.ICON_SIZE_DIALOG) free_space = util.humanize_bytes(backup.get_free_space(uuid)) s = "<b>Drive:</b> %s\n<b>Mount Point:</b> %s\n<b>Free Space:</b> %s" % ( util.pango_escape(uuid), util.pango_escape(path), util.pango_escape(free_space)) treeview_backups_model.append( (icon, s, backup.is_dev_present(uuid), uuid)) if not writable_devices: icon = self.main_window.render_icon(gtk.STOCK_INFO, gtk.ICON_SIZE_DIALOG) s = 'In order to create a backup, Flyback needs a hard drive\nother than the one your computer boots from.\n(preferably external and removable) Please plug one\ninto a free USB or eSATA port...' treeview_backups_model.append((icon, s, False, None)) self.xml.get_widget('button_new').set_sensitive(False) else: self.xml.get_widget('button_new').set_sensitive(True)
def refresh_device_list(self): treeview_backups_model = self.xml.get_widget('treeview_backups').get_model() treeview_backups_model.clear() known_backups = backup.get_known_backups() for t in known_backups: uuid = t['uuid'] paths = backup.get_dev_paths_for_uuid(t['uuid']) drive_name = 'UUID: '+ t['uuid'] for path in paths: if 'disk/by-id' in path: drive_name = path[path.index('disk/by-id')+11:] free_space = util.humanize_bytes(backup.get_free_space(t['uuid'])) drive_name = backup.get_mount_point_for_uuid(t['uuid']) + ' (%s free)' % free_space s = "<b>Drive:</b> %s\n<b>Source:</b> <i>%s</i>:%s\n" % (util.pango_escape(drive_name), util.pango_escape(t['host']), util.pango_escape(t['path']), ) if backup.is_dev_present(t['uuid']) and backup.get_hostname()==t['host']: s += "<b>Status:</b> Drive is ready for backups" else: if backup.is_dev_present(t['uuid']) and backup.get_hostname()!=t['host']: s += "<b>Status:</b> Backup available for export only (was created on another computer)" else: s += "<b>Status:</b> Drive is unavailable (please attach)" if backup.get_device_type(uuid)=='gvfs': icon = self.main_window.render_icon(gtk.STOCK_NETWORK, gtk.ICON_SIZE_DIALOG) elif backup.get_device_type(uuid)=='local': icon = self.main_window.render_icon(gtk.STOCK_HARDDISK, gtk.ICON_SIZE_DIALOG) else: icon = self.main_window.render_icon(gtk.STOCK_DIALOG_QUESTION, gtk.ICON_SIZE_DIALOG) treeview_backups_model.append( (icon, s, backup.is_dev_present(t['uuid']), t['uuid'], t['host'], t['path']) ) if known_backups: treeview_backups_model.append( (self.main_window.render_icon(gtk.STOCK_ADD, gtk.ICON_SIZE_DIALOG), 'Double-click here to create a new backup...', True, None, None, None) ) else: treeview_backups_model.append( (self.main_window.render_icon(gtk.STOCK_ADD, gtk.ICON_SIZE_DIALOG), 'No existing backups found.\nDouble-click here to create a new backup...', True, None, None, None) )
def list_post(page): perpage = 10 offset = (page - 1) * perpage output = '<ul>' posts = db.select( 'posts', what='id, title, content, datetime(created) as created, user_id', where='parent = 0', offset=offset, limit=perpage, order='id DESC') postcount = db.query( "SELECT COUNT(*) AS count FROM posts WHERE parent = 0")[0] pages = postcount.count / perpage if postcount.count % perpage > 0: pages += 1 for i in posts: user = db.select('users', what='username', where="id = $i.user_id", vars=locals())[0] output += '<li><a href="/view/' + str( i.id ) + '">' + i.title + '</a> - <b>' + user.username + '</b> (' + util.humanize_bytes( len(i.content)) + ') ' + i.created + ' (' + str(count_comment( i.id)) + ')</li>' output += list_comment(i.id) output += '</ul>' return output, pages
def refresh_device_list(self): treeview_backups_model = self.xml.get_widget("treeview_backups").get_model() treeview_backups_model.clear() known_backups = backup.get_known_backups() for t in known_backups: uuid = t["uuid"] paths = backup.get_dev_paths_for_uuid(t["uuid"]) drive_name = "UUID: " + t["uuid"] for path in paths: if "disk/by-id" in path: drive_name = path[path.index("disk/by-id") + 11 :] free_space = util.humanize_bytes(backup.get_free_space(t["uuid"])) drive_name = backup.get_mount_point_for_uuid(t["uuid"]) + " (%s free)" % free_space s = "<b>Drive:</b> %s\n<b>Source:</b> <i>%s</i>:%s\n" % ( util.pango_escape(drive_name), util.pango_escape(t["host"]), util.pango_escape(t["path"]), ) if backup.is_dev_present(t["uuid"]) and backup.get_hostname() == t["host"]: s += "<b>Status:</b> Drive is ready for backups" else: if backup.is_dev_present(t["uuid"]) and backup.get_hostname() != t["host"]: s += "<b>Status:</b> Backup available for export only (was created on another computer)" else: s += "<b>Status:</b> Drive is unavailable (please attach)" if backup.get_device_type(uuid) == "gvfs": icon = self.main_window.render_icon(gtk.STOCK_NETWORK, gtk.ICON_SIZE_DIALOG) elif backup.get_device_type(uuid) == "local": icon = self.main_window.render_icon(gtk.STOCK_HARDDISK, gtk.ICON_SIZE_DIALOG) else: icon = self.main_window.render_icon(gtk.STOCK_DIALOG_QUESTION, gtk.ICON_SIZE_DIALOG) treeview_backups_model.append((icon, s, backup.is_dev_present(t["uuid"]), t["uuid"], t["host"], t["path"])) if known_backups: treeview_backups_model.append( ( self.main_window.render_icon(gtk.STOCK_ADD, gtk.ICON_SIZE_DIALOG), "Double-click here to create a new backup...", True, None, None, None, ) ) else: treeview_backups_model.append( ( self.main_window.render_icon(gtk.STOCK_ADD, gtk.ICON_SIZE_DIALOG), "No existing backups found.\nDouble-click here to create a new backup...", True, None, None, None, ) )
def refresh_device_list(self): treeview_backups_model = self.xml.get_widget('treeview_backups').get_model() treeview_backups_model.clear() writable_devices = backup.get_writable_devices() for uuid in writable_devices: path = backup.get_mount_point_for_uuid(uuid) if backup.get_device_type(uuid)=='gvfs': icon = self.main_window.render_icon(gtk.STOCK_NETWORK, gtk.ICON_SIZE_DIALOG) elif backup.get_device_type(uuid)=='local': icon = self.main_window.render_icon(gtk.STOCK_HARDDISK, gtk.ICON_SIZE_DIALOG) else: icon = self.main_window.render_icon(gtk.STOCK_DIALOG_QUESTION, gtk.ICON_SIZE_DIALOG) free_space = util.humanize_bytes(backup.get_free_space(uuid)) s = "<b>Drive:</b> %s\n<b>Mount Point:</b> %s\n<b>Free Space:</b> %s" % (util.pango_escape(uuid), util.pango_escape(path), util.pango_escape(free_space)) treeview_backups_model.append( (icon, s, backup.is_dev_present(uuid), uuid) ) if not writable_devices: icon = self.main_window.render_icon(gtk.STOCK_INFO, gtk.ICON_SIZE_DIALOG) s = 'In order to create a backup, Flyback needs a hard drive\nother than the one your computer boots from.\n(preferably external and removable) Please plug one\ninto a free USB or eSATA port...' treeview_backups_model.append( (icon, s, False, None) ) self.xml.get_widget('button_new').set_sensitive(False) else: self.xml.get_widget('button_new').set_sensitive(True)
def list_comment(parent): comments = db.select( 'posts', what='id, title, content, datetime(created) as created, user_id', where='parent = $parent', order='id DESC', vars=locals()) if not comments: return '' output = '<ul>' for i in comments: user = db.select('users', what='username', where="id = $i.user_id", vars=locals())[0] output += '<li><a href="/view/' + str( i.id ) + '">' + i.title + '</a> - <b>' + user.username + '</b> (' + util.humanize_bytes( len(i.content)) + ') ' + i.created + ' (' + str(count_comment( i.id)) + ')</li>' + list_comment(i.id) output += '</ul>' return output
from . import cli from .master import current as master parser = cli.parser( description="process status" ) term = blessings.Terminal() max_pid = term.width - 70 table_generator = collections.OrderedDict([ # user_time + system_time ("time", lambda x: x.cpu_time), # mem_rss ("rss", lambda x: util.humanize_bytes(x.rss)), # cpus_limit ("cpu", lambda x: x.cpu_limit), # mem_rss / mem_limit ("%mem", lambda x: "{:.2f}".format((x.rss / (x.mem_limit * 1.0)) * 100)), # executor.name ("command", lambda x: x.command), ("user", lambda x: x.user), # slave_pid:task_id ("pid", lambda x: str(x).split('@')[-1][:max_pid]), ]) def main(): cfg, args = cli.init(parser)
def minimum_viable_sector_size_for_hybrids(self, performance_requirements): f = lambda r, n : r *(1/n) scaled = zigzag.scaled_for_new_hash(hybrid_hash(pedersen, blake2s, f(r,10))) return [(f(r, 10), humanize_bytes(scaled.minimum_viable_sector_size(performance_requirements))) for r in range(0, 11)]