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


Python DB.run_states方法代码示例

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


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

示例1: OverviewPanel

# 需要导入模块: from lib.db import DB [as 别名]
# 或者: from lib.db.DB import run_states [as 别名]
class OverviewPanel(gui.OverviewPanel):
    '''
    classdocs
    '''


    def __init__(self, parent):
        '''
        Constructor
        '''
        log.info("***OverviewPanel.init")
        
        gui.OverviewPanel.__init__(self, parent)
        self.imgStatus.SetBitmap(wx.Bitmap(os.path.join(const.PixmapDir, "status-ok.png")))
        self.db = DB()
        self.config = Config.get_config()

        self.update_data()
        self.image = wx.Bitmap(os.path.join(const.PixmapDir, "overview.png"))
        self.title = "Overview"
        
        self.timer = wx.Timer(self)
        self.Bind(wx.EVT_TIMER, self.update_data, self.timer)
        #    Update the display every 30 seconds
        self.timer.Start(30000)
        log.trace("Done OverviewPanel.init")



    def update_data(self, event=None):
        '''
        Main update routine. Called by the refresh button and by the timer.
        @param event:
        '''

        self.update_status()
        self.update_details()
        self.update_stores()
        self.Fit()

    def update_status(self):
        '''
        Update the status display. Uses a heuristic to decide if we are in an error
        or warning state.
        '''
        status, messages = self.calculate_status()
        if status == const.SystemStateError:
            self.imgStatus.SetBitmap(
                                     wx.Bitmap(os.path.join(const.PixmapDir, "status-fail.png"), 
                                               wx.BITMAP_TYPE_PNG)
                                     )
            self.lblStatus.SetLabel(_("Error"))
        elif status == const.SystemStateWarn:
            self.imgStatus.SetBitmap(
                                     wx.Bitmap(os.path.join(const.PixmapDir, "status-warn.png"), 
                                               wx.BITMAP_TYPE_PNG)
                                     )
            self.lblStatus.SetLabel(_("Warning"))
        else:
            self.imgStatus.SetBitmap(
                                     wx.Bitmap(os.path.join(const.PixmapDir, "status-ok.png"), 
                                               wx.BITMAP_TYPE_PNG)
                                     )
            self.lblStatus.SetLabel(_("Healthy"))

        self.lblMessages.SetLabel("\n".join(messages))


    def calculate_status(self):
        '''
        The heuristic for warning and errors states.
        Choose the *worst* condition and return that.

        The Heuristic is:
        #    backup should be hourly, and its been 1 day since last successful run, OR
        #    backup should be daily, at its been 5 days since last successful run. OR
        #    backup should be weekly and its been 2 weeks since last successful run
        '''
        messages = []
        state = const.SystemStateOK

        #    Check for any active backups in an error status.
        runs = self.db.run_states()
        for backup in self.config.backups.itervalues():
            if backup.name in runs and backup.active:
                run = runs[backup.name]
                #    It HAS run and its active:
                if run.status == const.StatusFailed:
                    messages.append(_("Backup %s last run failed") % backup.name)
                    state = max(state, const.SystemStateError)

        #    For each backup, check if its been tool long since last run.
        for backup in self.config.backups.itervalues():
            #    For each backup
            if backup.active:
                #    Look at only active backups
                if not backup.name in runs:
                    messages.append(_("Backup %s marked active but has never run") % backup.name)
                    state = max(state, const.SystemStateWarn)
                else:
#.........这里部分代码省略.........
开发者ID:,项目名称:,代码行数:103,代码来源:


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