本文整理汇总了Python中stoqlib.lib.webservice.WebService.status方法的典型用法代码示例。如果您正苦于以下问题:Python WebService.status方法的具体用法?Python WebService.status怎么用?Python WebService.status使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stoqlib.lib.webservice.WebService
的用法示例。
在下文中一共展示了WebService.status方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _BackupStatus
# 需要导入模块: from stoqlib.lib.webservice import WebService [as 别名]
# 或者: from stoqlib.lib.webservice.WebService import status [as 别名]
class _BackupStatus(ResourceStatus):
name = "backup"
label = _("Backup")
priority = 98
def __init__(self):
ResourceStatus.__init__(self)
self._webservice = WebService()
self._server = ServerProxy()
def refresh(self):
if not api.sysparam.get_bool("ONLINE_SERVICES"):
self.status = ResourceStatus.STATUS_NA
self.reason = _("Backup service not running because " '"Online Services" is disabled')
self.reason_long = _('Enable the parameter "Online Services" ' 'on the "Admin" app to solve this issue')
return
try:
key = self._server.call("get_backup_key")
except ServerError:
pass
else:
if not key:
self.status = self.STATUS_WARNING
self.reason = _("Backup key not configured")
self.reason_long = _('Click on "Configure" button to ' "configure the backup key")
return
request = self._webservice.status()
try:
response = request.get_response()
except Exception as e:
self.status = self.STATUS_WARNING
self.reason = _("Could not communicate with Stoq.link")
self.reason_long = str(e)
return
if response.status_code != 200:
self.status = self.STATUS_WARNING
self.reason = _("Could not communicate with Stoq.link")
self.reason_long = None
return
data = response.json()
if data["latest_backup_date"]:
backup_date = dateutil.parser.parse(data["latest_backup_date"])
delta = datetime.datetime.today() - backup_date
if delta.days > 3:
self.status = self.STATUS_WARNING
self.reason = _("Backup is late. Last backup date is %s") % (backup_date.strftime("%x"))
self.reason_long = _("Check your Stoq Server logs to see if " "there's any problem with it")
else:
self.status = self.STATUS_OK
self.reason = _("Backup is up-to-date. Last backup date is %s") % (backup_date.strftime("%x"))
self.reason_long = None
else:
self.status = self.STATUS_WARNING
self.reason = _("There's no backup data yet")
self.reason_long = None
def get_actions(self):
if self.status != ResourceStatus.STATUS_NA:
yield ResourceStatusAction(self, "backup-now", _("Backup now"), self._on_backup_now, threaded=True)
yield ResourceStatusAction(self, "configure", _("Configure"), self._on_configure, threaded=False)
def _on_configure(self):
key = self._server.call("get_backup_key")
with api.new_store() as store:
rv = run_dialog(BackupSettingsEditor, None, store, Settable(key=key))
if rv:
key = self._server.call("set_backup_key", rv.key)
def _on_backup_now(self):
self._server.call("backup_database")