123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- """
- demeter web page
- name:hardware.py 硬件相关页面
- author:rabin
- """
- from __load__ import *
- class hardware_path(Load):
- @Web.auth
- @Web.setting
- def get(self):
- self.common(
- name = u'硬件设备'
- ,path = '/hardware/hardware'
- ,width = '600'
- ,height = '600'
- ,add = False
- ,edit = False
- ,search = (('farm_id-select-','hardware_type-select-','hardware_id-input-mlike'), (u'选择农场',u'硬件类型', u'硬件id'))
- ,thead = (u'所属农场', u'硬件类型', u'硬件id',u'网关名',u'设备名', u'接入时间')
- ,tbody = ('farm','type', 'hardware_id', 'gateway', 'device', 'cdate')
- ,state = False
- )
- self.data['common']['search_farm_id-select-'] = Demeter.config['setting']['farmList']
- self.data['common']['search_hardware_type-select-'] = self.service('common').list('hardware_type')
- self.commonList('hardware')
- if self.data['list']:
- for key, value in enumerate(self.data['list']):
- farm = self.service('common').one('farm', id=value['farm_id'])
- self.data['list'][key]['farm'] = farm['name']
- htype = self.service('common').one('hardware_type', id=value['hardware_type'])
- self.data['list'][key]['type'] = htype['name']
- gateway = self.service('common').one('device_gateway', id=value['gateway_id'])
- self.data['list'][key]['gateway'] = '无效'
- if gateway:
- self.data['list'][key]['gateway'] = gateway['name']
- self.data['list'][key]['device'] = '无效'
- if value['device_id']:
- device = self.service('common').one('device_info', id=value['device_id'])
- if device:
- self.data['list'][key]['device'] = device['name']
-
- self.commonView('list')
- class hardware_update_path(Load):
- @Web.auth
- @Web.setting
- def get(self):
- self.common(
- path = '/hardware/hardware'
- ,label = (u'硬件类型',u'硬件id')
- ,update = ('hardware_type-select-required','hardware_id-input-required')
- ,update_hardware_type = self.service('common').list('hardware_type')
- )
- self.commonOne('hardware')
- self.commonView('update')
- @Web.auth
- @Web.setting
- def post(self):
- self.commonUpdate('hardware')
- @Web.auth
- @Web.setting
- def delete(self):
- self.commonDelete('hardware')
- class type_path(Load):
- @Web.auth
- @Web.setting
- def get(self):
- self.common(
- name = u'硬件类型'
- ,path = '/hardware/type'
- ,button = ({'name':'重启守护进程','link':'/hardware/restart_cron','ajax':True,'icon':''},{'name':'重启mqtt订阅服务','link':'/hardware/restart_sub','ajax':True,'icon':''},{'name':'重启园区服务','link':'/hardware/restart_front','ajax':True,'icon':''},{'name':'重启后台服务','link':'/hardware/restart_admin','ajax':True,'icon':''},{'name':'重启网站服务','link':'/hardware/restart_web','ajax':True,'icon':''})
- ,width = '600'
- ,height = '300'
- ,search = (('name-input-mlike',), (u'类型名称',))
- ,thead = (u'类型ID',u'类型名称',u'类型key', u'更新时间')
- ,tbody = ('id', 'name', 'key', 'cdate')
- ,state = False
- )
- self.commonList('hardware_type')
- self.commonView('list')
- class type_update_path(Load):
- @Web.auth
- @Web.setting
- def get(self):
- self.common(
- path = '/hardware/type'
- ,label = (u'类型名称', u'类型key')
- ,update = ('name-input-required', 'key-input-required')
- )
- self.commonOne('hardware_type')
- self.commonView('update')
- @Web.auth
- @Web.setting
- def post(self):
- self.commonUpdate('hardware_type')
- @Web.auth
- @Web.setting
- def delete(self):
- self.commonDelete('hardware_type')
- class restart_cron_path(Load):
- @Web.auth
- @Web.setting
- def post(self):
- Shell.popen("ps -ef | grep cron.py | grep -v grep |awk '{print $1}'|xargs kill -9")
- Shell.popen('/usr/local/demeter/cron.py >/dev/null &')
- class restart_sub_path(Load):
- @Web.auth
- @Web.setting
- def post(self):
- Shell.popen("ps -ef | grep sub.py | grep -v grep |awk '{print $1}'|xargs kill -9")
- class restart_admin_path(Load):
- @Web.auth
- @Web.setting
- def post(self):
- Shell.popen("ps -ef | grep admin.py | grep -v grep |awk '{print $1}'|xargs kill -9")
- class restart_front_path(Load):
- @Web.auth
- @Web.setting
- def post(self):
- Shell.popen("ps -ef | grep front.py | grep -v grep |awk '{print $1}'|xargs kill -9")
- class restart_web_path(Load):
- @Web.auth
- @Web.setting
- def post(self):
- Shell.popen("ps -ef | grep web.py | grep -v grep |awk '{print $1}'|xargs kill -9")
|