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


Python component.get函数代码示例

本文整理汇总了Python中mirror.component.get函数的典型用法代码示例。如果您正苦于以下问题:Python get函数的具体用法?Python get怎么用?Python get使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: enable

    def enable(self):
        plugin_manager = component.get("PluginManager")
        config = plugin_manager.config

        try:
            self.status_file = config[_plugin_name]["status_file"]
        except:
            self.status_file = Plugin.DEFAULT_STATUS_FILE
            log.info(("Didn't set `status_file` in plugin.ini in `%s` section"
                      ", use default one: %s"), _plugin_name, self.status_file)

        self.enabled = True
        status_dir   = os.path.dirname(self.status_file)
        if not os.path.exists(status_dir):
            try:
                os.makedirs(status_dir)
            except:
                self.enabled = False
                log.warning("Create directory failed: %s", status_dir)

        event_manager  = component.get("EventManager")
        event_manager.register_event_handler("TaskEnqueueEvent",
                                             self.__on_task_enqueue)
        event_manager.register_event_handler("TaskStartEvent",
                                             self.__on_task_start)
        event_manager.register_event_handler("TaskStopEvent",
                                             self.__on_task_stop)
开发者ID:GarrisonBaird,项目名称:mirror,代码行数:27,代码来源:plugin.py

示例2: run_task

    def run_task(self, taskinfo, stage = 1):
        if taskinfo.name not in self.tasks:
            return
        task = self.tasks[taskinfo.name]
        # for tasks that is still running when next schedule time
        # is reached (but has no timeout set), we just need to
        # reappend it.
        if task.running and task.timeout <= 0:
            taskinfo.time  = task.get_schedule_time(since = time.time())
            self.reappend_task(task, taskinfo)
        if task.running and ( not task.twostage ):
            log.info("Task: %s is still running and no timeout set, skipped", taskinfo.name)
            return

        event_manager = component.get("EventManager")
        event_manager.emit(mirror.event.PreTaskStartEvent(taskinfo.name))
        task.run(stage)
        if taskinfo in self.queue:
            self.queue.remove(taskinfo)
        log.info("Task: %s begin to run with pid %d", taskinfo.name, task.pid)
        event_manager.emit(mirror.event.TaskStartEvent(taskinfo.name, task.pid))

        if task.timeout <= 0:
            self.append_task(taskinfo.name, task, time.time())
        else:
            self.append_timeout_task(taskinfo.name, task,
                                     task.start_time + task.timeout)
开发者ID:yyxfei,项目名称:mirror,代码行数:27,代码来源:scheduler.py

示例3: __on_task_stop

    def __on_task_stop(self, taskname, pid, exitcode):
        if not self.enabled:
            return

        scheduler = component.get("Scheduler")
        task = scheduler.tasks.get(taskname, None)
        if not task:
            return
        status = { "status": self.STATUS_FINISHED }
        if task.cmdname == "rsync":
            status["message"] = _rsync_error[exitcode]
        else:
            status["message"] = "Task finished"

        status["exitcode"] = exitcode
        status["date"] = time.strftime(self.DATE_FORMAT)

        taskinfo = scheduler.queue.find(taskname)
        if taskinfo:
            status["schedule"] = time.strftime(self.DATE_FORMAT,
                                      time.localtime(taskinfo.time))
        else:
            status["schedule"] = "Unknown"

        self.__set_task_status(taskname, status)
开发者ID:GarrisonBaird,项目名称:mirror,代码行数:25,代码来源:plugin.py

示例4: __set_task_status

    def __set_task_status(self, taskname, status, overwrite = True):
        scheduler = component.get("Scheduler")
        task = scheduler.tasks.get(taskname)
        if task.isinternal:
            return

        try:
            fp = open(self.status_file, "r+" if os.path.exists(self.status_file) else "w+")
        except:
            log.warning("Open file failed: %s", self.status_file)
            return
        task_status = fp.read().rstrip("\r\n")
        if task_status:
            task_status = json.loads(task_status)
        else:
            task_status = {}
        if overwrite:
            task_status[taskname] = status
        else:
            if taskname in task_status:
                task_status[taskname]["schedule"] = status["schedule"]
            else:
                status["status"] = self.STATUS_INITIAL
                task_status[taskname] = status
        if len(task_status) > 1:
            task_status = odict(sorted(task_status.iteritems()))
        fp.seek(0)
        try:
            fp.write(json.dumps(task_status))
        except Exception, e:
            log.exception(e)
            fp.truncate(0)
开发者ID:bobgao,项目名称:mirror,代码行数:32,代码来源:plugin.py

示例5: start

 def start(self):
     event_manager = component.get("EventManager")
     event_manager.emit(mirror.event.MirrorStartEvent())
     while (True):
         self.sleep()
         if not self.roused_by_child:
             log.info("I am waking up...")
         self.schedule()
开发者ID:yyxfei,项目名称:mirror,代码行数:8,代码来源:scheduler.py

示例6: __on_task_enqueue

    def __on_task_enqueue(self, taskname):
        if not self.enabled:
            return

        scheduler = component.get("Scheduler")
        taskinfo  = scheduler.queue.find(taskname)
        status    = { "schedule": time.strftime(self.DATE_FORMAT,
                                       time.localtime(taskinfo.time)) }
        self.__set_task_status(taskname, status, overwrite = False)
开发者ID:GarrisonBaird,项目名称:mirror,代码行数:9,代码来源:plugin.py

示例7: run_system_task

 def run_system_task(self, taskinfo):
     event_manager = component.get("EventManager")
     event_manager.emit(mirror.event.RunSystemTaskEvent(taskinfo))
     # after we run the system task, we need to update the queue
     # or else the sleeptime will be invalid
     if taskinfo in self.queue:
         self.queue.remove(taskinfo)
     task = self.tasks[taskinfo.name]
     self.append_task(taskinfo.name, task, time.time())
开发者ID:yyxfei,项目名称:mirror,代码行数:9,代码来源:scheduler.py

示例8: sigchld_handler

def sigchld_handler(signo, frame):
    try:
        pid, status = os.waitpid(-1, os.WNOHANG)
    except OSError as e:
        log.error("Error occured when waitpid(), %s.", e)
        return
    scheduler = component.get("Scheduler")
    if scheduler is None:
        return
    scheduler.stop_task_with_pid(pid, status)
开发者ID:GarrisonBaird,项目名称:mirror,代码行数:10,代码来源:handler.py

示例9: reappend_task

    def reappend_task(self, task, taskinfo):
        """
        Remove a taskinfo from queue and put it in again,
        to keep the queue in order.

        """
        if taskinfo not in self.queue:
            return
        self.queue.remove(taskinfo)
        self.queue.put(taskinfo)
        event_manager = component.get("EventManager")
        event_manager.emit(mirror.event.TaskEnqueueEvent(taskinfo.name))
开发者ID:yyxfei,项目名称:mirror,代码行数:12,代码来源:scheduler.py

示例10: __set_task_status

    def __set_task_status(self, taskname, status, overwrite = True):
        scheduler = component.get("Scheduler")
        task = scheduler.tasks.get(taskname)
        # We do not export internal task's status
        if task.isinternal:
            return

        # Add info about upstream
        if task.__class__.__name__ == "Task":
            status['upstream'] = task.upstream[0] + '::' + task.rsyncdir + '/'

        # Read old status file content
        try:
            fp = open(self.status_file, "r+" if os.path.exists(self.status_file) else "w+")
        except:
            log.warning("Open file failed: %s", self.status_file)
            return
        task_status = fp.read().rstrip("\r\n")
        if task_status:
            try:
                task_status = json.loads(task_status)
            except Exception as e:
                log.warning("Parse json file(%s) failed: %s", self.status_file, e)
                task_status = {}
            else:
                # Remove tasks that already been removed from config file
                for taskname in list(task_status):
                    if taskname not in scheduler.config:
                        task_status.pop(taskname)
        else:
            task_status = {}

        if overwrite:
            task_status[taskname] = status
        else:
            if taskname in task_status:
                task_status[taskname]["schedule"] = status["schedule"]
            else:
                status["status"] = self.STATUS_INITIAL
                task_status[taskname] = status

        if len(task_status) > 1:
            task_status = odict(sorted(task_status.items()))
        fp.seek(0)
        try:
            fp.write(json.dumps(task_status, indent = 2))
        except Exception as e:
            log.exception(e)
            fp.truncate(0)
        else:
            fp.truncate()
        fp.close()
开发者ID:ideal,项目名称:mirror,代码行数:52,代码来源:plugin.py

示例11: shutdown_handler

def shutdown_handler(signo, frame):
    import mirror.configmanager

    pidfile = mirror.configmanager.get_config_dir("mirrord.pid")
    if os.path.isfile(pidfile):
        os.remove(pidfile)
    log.info("Got signal %s, exiting...", signals[signo])

    import sys

    scheduler = component.get("Scheduler")
    if scheduler is None:
        sys.exit(0)

    # We will waitpid() in stop_all_tasks(),
    # so unregister sigchld_handler here.
    signal.signal(signal.SIGCHLD, signal.SIG_DFL)
    scheduler.stop_all_tasks()

    if hasattr(scheduler, "buspid"):
        os.kill(scheduler.buspid, signal.SIGTERM)
        pid, status = os.waitpid(scheduler.buspid, 0)
        log.info("Killed mirror dbus with pid: %d", pid)

    event_manager = component.get("EventManager")
    while event_manager.plugin_thread and len(event_manager.plugin_thread.event_queue) > 0:
        time.sleep(0.1)
    component.deregister(event_manager)
    component.deregister(component.get("PluginManager"))

    # Deregister the scheduler,
    # this will call scheduler's stop().
    # But scheduler's start() is called
    # directly, not by component's start().
    component.deregister(scheduler)

    log.info("Bye bye... :)")
    sys.exit(0)
开发者ID:GarrisonBaird,项目名称:mirror,代码行数:38,代码来源:handler.py

示例12: append_timeout_task

    def append_timeout_task(self, taskname, task, time):
        """
        A timeout checking task is added after a task begins to run.

        """
        if not task.running:
            return
        if not task.enabled:
            return
        taskinfo = TaskInfo(taskname, TIMEOUT_TASK,
                            time, task.priority)
        if taskinfo in self.queue:
            return
        self.queue.put(taskinfo)
        event_manager = component.get("EventManager")
        event_manager.emit(mirror.event.TaskEnqueueEvent(taskname))
开发者ID:yyxfei,项目名称:mirror,代码行数:16,代码来源:scheduler.py

示例13: task_post_process

    def task_post_process(self, task):
        """
        Check whether a task needs post process, e.g. two stage tasks.

        """
        event_manager = component.get("EventManager")
        if not task.twostage:
            event_manager.emit(mirror.event.TaskStopEvent(task.name, task.pid, task.code))
            task.set_stop_flag()
            return
        if task.stage == 1:
            log.info("Task: %s scheduled to second stage", task.name)
            self.run_task(TaskInfo(task.name, REGULAR_TASK, 0, task.priority), stage = 2)
        else:
            event_manager.emit(mirror.event.TaskStopEvent(task.name, task.pid, task.code))
            task.set_stop_flag()
            task.stage = 1
开发者ID:hznoob,项目名称:mirror,代码行数:17,代码来源:scheduler.py

示例14: __on_mirror_start

    def __on_mirror_start(self):
        """
        NOTE: However currently SystemTask is run in plugin thread,
        and the Scheduler sleeps before SystemTask is appended into
        the queue, so SystemTask will only begin to take effect on
        next sleep loop.
        However for most system tasks, this is acceptable.

        """
        self.scheduler = component.get("Scheduler")

        self.scheduler.tasks[logcleantask._name] = self.logclean_task
        self.scheduler.active_tasks += 1
        log.info("Task: %s added", logcleantask._name)

        self.scheduler.tasks[taskcleantask._name] = self.taskclean_task
        self.scheduler.active_tasks += 1
        log.info("Task: %s added", taskcleantask._name)
开发者ID:ideal,项目名称:mirror,代码行数:18,代码来源:systemtask.py

示例15: run

    def run(self):
        scheduler = component.get("Scheduler")

        curtime   = time.time()
        for taskname, task in scheduler.tasks.items():
            try:
                # internal tasks have no `running`
                if not hasattr(task, "running"):
                    continue
                if not task.running:
                    continue
                # SIGCHLD will trigger in main thread
                if curtime - task.start_time > self.TASK_TIMEOUT:
                    os.kill(task.pid, signal.SIGTERM)
                    log.info("Killed task: %s, whose life exceeds %d days",
                             taskname, self.timeout_days)
            except Exception as e:
                log.exception(e)
开发者ID:ideal,项目名称:mirror,代码行数:18,代码来源:taskcleantask.py


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