当前位置: 首页>>代码示例>>Python>>正文


Python Job.dbus_object_path方法代码示例

本文整理汇总了Python中job.Job.dbus_object_path方法的典型用法代码示例。如果您正苦于以下问题:Python Job.dbus_object_path方法的具体用法?Python Job.dbus_object_path怎么用?Python Job.dbus_object_path使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在job.Job的用法示例。


在下文中一共展示了Job.dbus_object_path方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Move

# 需要导入模块: from job import Job [as 别名]
# 或者: from job.Job import dbus_object_path [as 别名]
        def Move(self, pv_src_obj, pv_source_range, pv_dest_obj,
                 pv_dest_range, move_options):
            pv_dest = None
            pv_src = cfg.om.get_by_path(pv_src_obj)
            if pv_src:
                if pv_dest_obj != '/':
                    pv_dest_t = cfg.om.get_by_path(pv_dest_obj)
                    if not pv_dest_t:
                        raise dbus.exceptions.DBusException(
                            interface_name, 'pv_dest_obj (%s) not found' %
                            pv_src_obj)
                    pv_dest = pv_dest_t.lvm_id

                rc, out, err = cmdhandler.pv_move_lv(
                    move_options,
                    self.lvm_id,
                    pv_src.lvm_id,
                    pv_source_range,
                    pv_dest,
                    pv_dest_range)

                if rc == 0:
                    # Create job object for monitoring
                    job_obj = Job(self.lvm_id, None)
                    cfg.om.register_object(job_obj)
                    cfg.kick_q.put("wake up!")
                    return job_obj.dbus_object_path()
                else:
                    raise dbus.exceptions.DBusException(
                        interface_name,
                        'Exit code %s, stderr = %s' % (str(rc), err))
            else:
                raise dbus.exceptions.DBusException(
                    interface_name, 'pv_src_obj (%s) not found' % pv_src_obj)
开发者ID:vpodzime,项目名称:lvm-dubstep,代码行数:36,代码来源:lv.py

示例2: RequestEntry

# 需要导入模块: from job import Job [as 别名]
# 或者: from job.Job import dbus_object_path [as 别名]
class RequestEntry(object):
    def __init__(self, tmo, method, arguments, cb, cb_error,
                 return_tuple=True):
        self.tmo = tmo
        self.method = method
        self.arguments = arguments
        self.cb = cb
        self.cb_error = cb_error

        self.timer_id = -1
        self.lock = threading.RLock()
        self.done = False
        self._result = None
        self._job = False
        self._rc = 0
        self._rc_error = None
        self._return_tuple = return_tuple

        if self.tmo == -1:
            # Client is willing to block forever
            pass
        elif tmo == 0:
            self._return_job()
        else:
            self.timer_id = gobject.timeout_add_seconds(
                tmo, RequestEntry._request_timeout, self)

    @staticmethod
    def _request_timeout(r):
        """
        Method which gets called when the timer runs out!
        :param r:  RequestEntry which timed out
        :return: Nothing
        """
        r.timer_expired()

    def _return_job(self):
        self._job = Job(None, self)
        cfg.om.register_object(self._job, True)
        if self._return_tuple:
            self.cb(('/', self._job.dbus_object_path()))
        else:
            self.cb(self._job.dbus_object_path())

    def run_cmd(self):
        try:
            result = self.method(*self.arguments)
            self.register_result(result)
        except dbus.DBusException as de:
            # Use the request entry to return the result as the client may
            # have gotten a job by the time we hit an error
            self.register_error(-1, de)

    def is_done(self):
        with self.lock:
            rc = self.done
        return rc

    def get_errors(self):
        with self.lock:
            return (self._rc, self._rc_error)

    def result(self):
        with self.lock:
            if self.done:
                return self._result
            return '/'

    def _reg_ending(self, result, error_rc=0, error=None):
        with self.lock:
            self.done = True
            if self.timer_id != -1:
                # Try to prevent the timer from firing
                gobject.source_remove(self.timer_id)

            self._result = result
            self._rc = error_rc
            self._rc_error = error

            if not self._job:
                # We finished and there is no job, so return result or error
                # now!
                # Note: If we don't have a valid cb or cbe, this indicates a
                # request that doesn't need a response as we already returned
                # one before the request was processed.
                if error_rc == 0:
                    if self.cb:
                        if self._return_tuple:
                            self.cb((result, '/'))
                        else:
                            self.cb(result)
                else:
                    if self.cb_error:
                        self.cb_error(self._rc_error)
            else:
                # We have a job and it's complete, indicate that it's done.
                # TODO: We need to signal the job is done too.
                self._job.Complete = True
                self._job = None

#.........这里部分代码省略.........
开发者ID:vpodzime,项目名称:lvm-dubstep,代码行数:103,代码来源:request.py


注:本文中的job.Job.dbus_object_path方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。