def update_total_size(self, bytes_removed): """Callback to update the total size cleaned""" context_id = self.status_bar.get_context_id('size') text = FileUtilities.bytes_to_human(bytes_removed) if bytes_removed == 0: text = "" self.status_bar.push(context_id, text)
def update_item_size(self, option, option_id, bytes_removed): """Update size in tree control""" model = self.view.get_model() text = FileUtilities.bytes_to_human(bytes_removed) if bytes_removed == 0: text = "" treepath = Gtk.TreePath(0) try: __iter = model.get_iter(treepath) except ValueError as e: logger.warning( 'ValueError in get_iter() when updating file size for tree path=%s' % treepath) return while __iter: if model[__iter][2] == option: if option_id == -1: model[__iter][3] = text else: child = model.iter_children(__iter) while child: if model[child][2] == option_id: model[child][3] = text child = model.iter_next(child) __iter = model.iter_next(__iter)
def update_total_size(self, bytes_removed): """Callback to update the total size cleaned""" context_id = self.status_bar.get_context_id('size') text = FileUtilities.bytes_to_human(bytes_removed) if 0 == bytes_removed: text = "" self.status_bar.push(context_id, text)
def execute(self, cmd, operation_option): """Execute or preview the command""" ret = None try: for ret in cmd.execute(self.really_delete): if True == ret or isinstance(ret, tuple): # Temporarily pass control to the GTK idle loop, # allow user to abort, and # display progress (if applicable). yield ret if self.is_aborted: return except SystemExit: pass except Exception as e: # 2 = does not exist # 13 = permission denied from errno import ENOENT, EACCES if isinstance(e, OSError) and e.errno in (ENOENT, EACCES): # For access denied, do not show traceback exc_message = str(e).decode(FSE) logger.error('%s: %s', exc_message, cmd) else: # For other errors, show the traceback. msg = _('Error: {operation_option}: {command}') if isinstance(msg, str) and isinstance(operation_option, unicode): # if _ haven't found proper translation in locale dir it returns str msg = msg.decode(FSE) data = {'command': cmd, 'operation_option': operation_option} logger.error(msg.format(**data), exc_info=True) self.total_errors += 1 else: if ret is None: return if isinstance(ret['size'], (int, long)): size = FileUtilities.bytes_to_human(ret['size']) self.size += ret['size'] self.total_bytes += ret['size'] else: size = "?B" if ret['path']: path = ret['path'] else: path = u'' if isinstance(path, str): path = path.decode('utf8', 'replace') # for invalid encoding line = u"%s %s %s\n" % (ret['label'], size, path) self.total_deleted += ret['n_deleted'] self.total_special += ret['n_special'] if ret['label']: # the label may be a hidden operation # (e.g., win.shell.change.notify) self.ui.append_text(line)
def execute(self, cmd, operation_option): """Execute or preview the command""" ret = None try: for ret in cmd.execute(self.really_delete): if True == ret or isinstance(ret, tuple): # Temporarily pass control to the GTK idle loop, # allow user to abort, and # display progress (if applicable). yield ret except SystemExit: pass except Exception as e: # 2 = does not exist # 13 = permission denied from errno import ENOENT, EACCES if isinstance(e, OSError) and e.errno in (ENOENT, EACCES): # For access denied, do not show traceback exc_message = str(e).decode(FSE) logger.error('%s: %s', exc_message, cmd) else: # For other errors, show the traceback. msg = _('Error: {operation_option}: {command}') data = {'command': cmd, 'operation_option': operation_option} logger.error(msg.format(**data), exc_info=True) self.total_errors += 1 else: if ret is None: return if isinstance(ret['size'], (int, long)): size = FileUtilities.bytes_to_human(ret['size']) self.size += ret['size'] self.total_bytes += ret['size'] else: size = "?B" if ret['path']: path = ret['path'] else: path = '' path = path.decode('utf8', 'replace') # for invalid encoding line = u"%s %s %s\n" % (ret['label'], size, path) self.total_deleted += ret['n_deleted'] self.total_special += ret['n_special'] if ret['label']: # the label may be a hidden operation # (e.g., win.shell.change.notify) self.ui.append_text(line)
def fill_memory_linux(): """Fill unallocated memory""" report_free() allocbytes = int(physical_free() * 0.4) if allocbytes < 1024: return bytes_str = FileUtilities.bytes_to_human(allocbytes) logger.info('allocating and wiping %s (%d B) of memory', bytes_str, allocbytes) try: buf = '\x00' * allocbytes except MemoryError: pass else: fill_memory_linux() logger.debug('freeing %s of memory" % bytes_str') del buf report_free()
def fill_memory_linux(): report_free() allocbytes = int(physical_free() * 0.4) if allocbytes < 1024: return bytes_str = FileUtilities.bytes_to_human(allocbytes) logger.info('allocating and wiping %s (%d B) of memory', bytes_str, allocbytes) try: buf = '\x00' * allocbytes except MemoryError: pass else: fill_memory_linux() logger.debug('freeing %s of memory" % bytes_str') del buf report_free()
def execute(self, cmd): """Execute or preview the command""" ret = None try: for ret in cmd.execute(self.really_delete): if True == ret or isinstance(ret, tuple): # Temporarily pass control to the GTK idle loop, # allow user to abort, and # display progress (if applicable). yield ret except SystemExit: pass except Exception as e: # 2 = does not exist # 13 = permission denied from errno import ENOENT, EACCES if isinstance(e, OSError) and e.errno in (ENOENT, EACCES): # For access denied, do not show traceback logger.error('%s: %s', e, cmd) else: # For other errors, show the traceback. logger.error('Error in execution of %s', cmd, exc_info=True) self.total_errors += 1 else: if ret is None: return if isinstance(ret['size'], (int, long)): size = FileUtilities.bytes_to_human(ret['size']) self.size += ret['size'] self.total_bytes += ret['size'] else: size = "?B" if ret['path']: path = ret['path'] else: path = '' path = path.decode('utf8', 'replace') # for invalid encoding line = u"%s %s %s\n" % (ret['label'], size, path) self.total_deleted += ret['n_deleted'] self.total_special += ret['n_special'] if ret['label']: # the label may be a hidden operation # (e.g., win.shell.change.notify) self.ui.append_text(line)
def fill_memory_linux(): """Fill unallocated memory""" report_free() allocbytes = int(physical_free() * 0.4) if allocbytes < 1024: return bytes_str = FileUtilities.bytes_to_human(allocbytes) # TRANSLATORS: The variable is a quantity like 5kB logger.info(_("Allocating and wiping %s of memory."), bytes_str) try: buf = '\x00' * allocbytes except MemoryError: pass else: fill_memory_linux() # TRANSLATORS: The variable is a quantity like 5kB logger.debug(_("Freeing %s of memory."), bytes_str) del buf report_free()
def update_item_size(self, option, option_id, bytes_removed): """Update size in tree control""" model = self.view.get_model() text = FileUtilities.bytes_to_human(bytes_removed) if 0 == bytes_removed: text = "" __iter = model.get_iter_root() while __iter: if model[__iter][2] == option: if option_id == -1: model[__iter][3] = text else: child = model.iter_children(__iter) while child: if model[child][2] == option_id: model[child][3] = text child = model.iter_next(child) __iter = model.iter_next(__iter)
def run(self): """Perform the main cleaning process which has these phases 1. General cleaning 2. Deep scan 3. Memory 4. Free disk space""" self.deepscans = {} # prioritize self.delayed_ops = [] for operation in self.operations: delayables = ['free_disk_space', 'memory'] for delayable in delayables: if operation not in ('system', '_gui'): continue if delayable in self.operations[operation]: i = self.operations[operation].index(delayable) del self.operations[operation][i] priority = 99 if 'free_disk_space' == delayable: priority = 100 new_op = (priority, {operation: [delayable]}) self.delayed_ops.append(new_op) # standard operations #표준작업 import warnings with warnings.catch_warnings(record=True) as ws: # This warning system allows general warnings. Duplicate will # be removed, and the warnings will show near the end of # the log. warnings.simplefilter('once') for dummy in self.run_operations(self.operations): # yield to GTK+ idle loop yield True for w in ws: logger.warning(w.message) # run deep scan #deepscan수행 if self.deepscans: for dummy in self.run_deep_scan(): yield dummy # delayed operations #지연된 작업 수행 for op in sorted(self.delayed_ops): operation = op[1].keys()[0] for option_id in op[1].values()[0]: for ret in self.run_delayed_op(operation, option_id): # yield to GTK+ idle loop yield True # print final stats #최종상태 bytes_delete = FileUtilities.bytes_to_human(self.total_bytes) if self.really_delete: # TRANSLATORS: This refers to disk space that was # really recovered (in other words, not a preview) line = _("Disk space recovered: %s") % bytes_delete else: # TRANSLATORS: This refers to a preview (no real # changes were made yet) line = _("Disk space to be recovered: %s") % bytes_delete self.ui.append_text("\n%s" % line) if self.really_delete: # TRANSLATORS: This refers to the number of files really # deleted (in other words, not a preview). line = _("Files deleted: %d") % self.total_deleted else: # TRANSLATORS: This refers to the number of files that # would be deleted (in other words, simply a preview). line = _("Files to be deleted: %d") % self.total_deleted self.ui.append_text("\n%s" % line) if self.total_special > 0: line = _("Special operations: %d") % self.total_special self.ui.append_text("\n%s" % line) if self.total_errors > 0: line = _("Errors: %d") % self.total_errors self.ui.append_text("\n%s" % line, 'error') if self.really_delete: self.ui.update_total_size(self.total_bytes) self.ui.worker_done(self, self.really_delete) yield False
def report_free(): bytes_free = physical_free() bytes_str = FileUtilities.bytes_to_human(bytes_free) logger.debug('physical free: %s (%d B)', bytes_str, bytes_free)
def report_free(): """Report free memory""" bytes_free = physical_free() bytes_str = FileUtilities.bytes_to_human(bytes_free) # TRANSLATORS: The variable is a quantity like 5kB logger.debug(_("Physical free memory is %s."), bytes_str)
def report_free(): """Report free memory""" bytes_free = physical_free() bytes_str = FileUtilities.bytes_to_human(bytes_free) logger.debug('physical free: %s (%d B)', bytes_str, bytes_free)
def run(self): """Perform the main cleaning process which has these phases 1. General cleaning 2. Deep scan 3. Memory 4. Free disk space""" self.deepscans = {} # prioritize self.delayed_ops = [] for operation in self.operations: delayables = ['free_disk_space', 'memory'] for delayable in delayables: if operation not in ('system', '_gui'): continue if delayable in self.operations[operation]: i = self.operations[operation].index(delayable) del self.operations[operation][i] priority = 99 if 'free_disk_space' == delayable: priority = 100 new_op = (priority, {operation: [delayable]}) self.delayed_ops.append(new_op) # standard operations import warnings with warnings.catch_warnings(record=True) as ws: # This warning system allows general warnings. Duplicate will # be removed, and the warnings will show near the end of # the log. warnings.simplefilter('once') for dummy in self.run_operations(self.operations): # yield to GTK+ idle loop yield True for w in ws: logger.warning(w.message) # run deep scan if self.deepscans: for dummy in self.run_deep_scan(): yield dummy # delayed operations for op in sorted(self.delayed_ops): operation = op[1].keys()[0] for option_id in op[1].values()[0]: for ret in self.run_delayed_op(operation, option_id): # yield to GTK+ idle loop yield True # print final stats bytes_delete = FileUtilities.bytes_to_human(self.total_bytes) if self.really_delete: # TRANSLATORS: This refers to disk space that was # really recovered (in other words, not a preview) line = _("Disk space recovered: %s") % bytes_delete else: # TRANSLATORS: This refers to a preview (no real # changes were made yet) line = _("Disk space to be recovered: %s") % bytes_delete self.ui.append_text("\n%s" % line) if self.really_delete: # TRANSLATORS: This refers to the number of files really # deleted (in other words, not a preview). line = _("Files deleted: %d") % self.total_deleted else: # TRANSLATORS: This refers to the number of files that # would be deleted (in other words, simply a preview). line = _("Files to be deleted: %d") % self.total_deleted self.ui.append_text("\n%s" % line) if self.total_special > 0: line = _("Special operations: %d") % self.total_special self.ui.append_text("\n%s" % line) if self.total_errors > 0: line = _("Errors: %d") % self.total_errors self.ui.append_text("\n%s" % line, 'error') if self.really_delete: self.ui.update_total_size(self.total_bytes) self.ui.worker_done(self, self.really_delete) yield False
def report_free(): """Report free memory""" bytes_free = physical_free() bytes_str = FileUtilities.bytes_to_human(bytes_free) logger.debug(_("Physical free memory is %s (%d B)."), bytes_str, bytes_free)