def __setstate__(self, state): vars(self).update(state) objid, actid, iobjid = state["object"] obj = puid.resolve_unique_id(objid) act = puid.resolve_action_id(actid, obj) iobj = puid.resolve_unique_id(iobjid) if (not obj or not act) or (iobj is None) != (iobjid is None): raise InvalidDataError("Parts of %s not restored" % str(self)) self.object[:] = [obj, act, iobj]
def parse_kfcom_file(filepath): """Extract the serialized command inside @filepath The file must be executable (comparable to a shell script) >>> parse_kfcom_file(__file__) # doctest: +ELLIPSIS Traceback (most recent call last): ... ExecutionError: ... (not executable) Return commands triple """ fobj = open(filepath, "rb") if not os.access(filepath, os.X_OK): raise ExecutionError(_('No permission to run "%s" (not executable)') % glib.filename_display_basename(filepath)) # strip shebang away data = fobj.read() if data.startswith("#!") and "\n" in data: shebang, data = data.split("\n", 1) try: id_ = conspickle.BasicUnpickler.loads(data) command_object = puid.resolve_unique_id(id_) except pickle.UnpicklingError, err: raise ExecutionError("Could not parse: %s" % unicode(err))
def perform_trigger(cls, target): try: keystr, name, id_ = cls.instance.trigger_table[target] except KeyError: return obj = puid.resolve_unique_id(id_) if obj is None: return return obj.run()
def __setstate__(self, state): vars(self).update(state) objects = [] for id_ in state["object"]: obj = puid.resolve_unique_id(id_) if obj is None: raise InvalidDataError("%s could not be restored!" % (id_, )) objects.append(obj) self.object[:] = objects
def perform_trigger(cls, ctx, target): try: keystr, name, id_ = cls.instance.trigger_table[target] except KeyError: raise OperationError("Trigger '%s' does not exist" % (target, )) obj = puid.resolve_unique_id(id_) if obj is None: return return obj.run(ctx)
def parse_kfcom_file(filepath): """Extract the serialized command inside @filepath The file must be executable (comparable to a shell script) >>> parse_kfcom_file(__file__) # doctest: +ELLIPSIS Traceback (most recent call last): ... ExecutionError: ... (not executable) Return commands triple """ fobj = open(filepath, "rb") if not os.access(filepath, os.X_OK): raise ExecutionError( _('No permission to run "%s" (not executable)') % GLib.filename_display_basename(filepath)) # strip shebang away data = fobj.read() if data.startswith(b"#!") and b"\n" in data: shebang, data = data.split(b"\n", 1) try: id_ = conspickle.BasicUnpickler.loads(data) command_object = puid.resolve_unique_id(id_) except pickle.UnpicklingError as err: raise ExecutionError("Could not parse: %s" % str(err)) except Exception: raise ExecutionError('"%s" is not a saved command' % os.path.basename(filepath)) if command_object is None: raise ExecutionError( _('Command in "%s" is not available') % GLib.filename_display_basename(filepath)) try: return tuple(command_object.object) except (AttributeError, TypeError): raise ExecutionError('"%s" is not a saved command' % os.path.basename(filepath)) finally: GLib.idle_add(update_icon, command_object, filepath)
def parse_kfcom_file(filepath): """Extract the serialized command inside @filepath The file must be executable (comparable to a shell script) >>> parse_kfcom_file(__file__) # doctest: +ELLIPSIS Traceback (most recent call last): ... ExecutionError: ... (not executable) Return commands triple """ fobj = open(filepath, "rb") if not os.access(filepath, os.X_OK): raise ExecutionError(_('No permission to run "%s" (not executable)') % GLib.filename_display_basename(filepath)) # strip shebang away data = fobj.read() if data.startswith(b"#!") and b"\n" in data: shebang, data = data.split(b"\n", 1) try: id_ = conspickle.BasicUnpickler.loads(data) command_object = puid.resolve_unique_id(id_) except pickle.UnpicklingError as err: raise ExecutionError("Could not parse: %s" % str(err)) except Exception: raise ExecutionError('"%s" is not a saved command' % os.path.basename(filepath)) if command_object is None: raise ExecutionError(_('Command in "%s" is not available') % GLib.filename_display_basename(filepath)) try: return tuple(command_object.object) except (AttributeError, TypeError): raise ExecutionError('"%s" is not a saved command' % os.path.basename(filepath)) finally: GLib.idle_add(update_icon, command_object, filepath)
def _lookup_item(self, id_): itm = puid.resolve_unique_id(id_, excluding=self) if itm is None: return None return itm