コード例 #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
ファイル: execfile.py プロジェクト: jchtt/kupfer-adds
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
ファイル: triggers.py プロジェクト: spiritedflow/kupfer
	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
ファイル: triggers.py プロジェクト: jchtt/kupfer-adds
 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