예제 #1
0
 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]
예제 #2
0
파일: compose.py 프로젝트: engla/kupfer
 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]
예제 #3
0
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))
예제 #4
0
	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()
예제 #5
0
파일: compose.py 프로젝트: engla/kupfer
 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
예제 #6
0
 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
예제 #7
0
 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)
예제 #8
0
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)
예제 #9
0
파일: execfile.py 프로젝트: engla/kupfer
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)
예제 #10
0
파일: favorites.py 프로젝트: chmouel/kupfer
	def _lookup_item(self, id_):
		itm = puid.resolve_unique_id(id_, excluding=self)
		if itm is None:
			return None
		return itm
예제 #11
0
파일: favorites.py 프로젝트: guns/kupfer
 def _lookup_item(self, id_):
     itm = puid.resolve_unique_id(id_, excluding=self)
     if itm is None:
         return None
     return itm