hardware.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. """
  4. demeter web page
  5. name:hardware.py 硬件相关页面
  6. author:rabin
  7. """
  8. from __load__ import *
  9. class hardware_path(Load):
  10. @Web.auth
  11. @Web.setting
  12. def get(self):
  13. self.common(
  14. name = u'硬件设备'
  15. ,path = '/hardware/hardware'
  16. ,width = '600'
  17. ,height = '600'
  18. ,add = False
  19. ,edit = False
  20. ,search = (('farm_id-select-','hardware_type-select-','hardware_id-input-mlike'), (u'选择农场',u'硬件类型', u'硬件id'))
  21. ,thead = (u'所属农场', u'硬件类型', u'硬件id',u'网关名',u'设备名', u'接入时间')
  22. ,tbody = ('farm','type', 'hardware_id', 'gateway', 'device', 'cdate')
  23. ,state = False
  24. )
  25. self.data['common']['search_farm_id-select-'] = Demeter.config['setting']['farmList']
  26. self.data['common']['search_hardware_type-select-'] = self.service('common').list('hardware_type')
  27. self.commonList('hardware')
  28. if self.data['list']:
  29. for key, value in enumerate(self.data['list']):
  30. farm = self.service('common').one('farm', id=value['farm_id'])
  31. self.data['list'][key]['farm'] = farm['name']
  32. htype = self.service('common').one('hardware_type', id=value['hardware_type'])
  33. self.data['list'][key]['type'] = htype['name']
  34. gateway = self.service('common').one('device_gateway', id=value['gateway_id'])
  35. self.data['list'][key]['gateway'] = '无效'
  36. if gateway:
  37. self.data['list'][key]['gateway'] = gateway['name']
  38. self.data['list'][key]['device'] = '无效'
  39. if value['device_id']:
  40. device = self.service('common').one('device_info', id=value['device_id'])
  41. if device:
  42. self.data['list'][key]['device'] = device['name']
  43. self.commonView('list')
  44. class hardware_update_path(Load):
  45. @Web.auth
  46. @Web.setting
  47. def get(self):
  48. self.common(
  49. path = '/hardware/hardware'
  50. ,label = (u'硬件类型',u'硬件id')
  51. ,update = ('hardware_type-select-required','hardware_id-input-required')
  52. ,update_hardware_type = self.service('common').list('hardware_type')
  53. )
  54. self.commonOne('hardware')
  55. self.commonView('update')
  56. @Web.auth
  57. @Web.setting
  58. def post(self):
  59. self.commonUpdate('hardware')
  60. @Web.auth
  61. @Web.setting
  62. def delete(self):
  63. self.commonDelete('hardware')
  64. class type_path(Load):
  65. @Web.auth
  66. @Web.setting
  67. def get(self):
  68. self.common(
  69. name = u'硬件类型'
  70. ,path = '/hardware/type'
  71. ,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':''})
  72. ,width = '600'
  73. ,height = '300'
  74. ,search = (('name-input-mlike',), (u'类型名称',))
  75. ,thead = (u'类型ID',u'类型名称',u'类型key', u'更新时间')
  76. ,tbody = ('id', 'name', 'key', 'cdate')
  77. ,state = False
  78. )
  79. self.commonList('hardware_type')
  80. self.commonView('list')
  81. class type_update_path(Load):
  82. @Web.auth
  83. @Web.setting
  84. def get(self):
  85. self.common(
  86. path = '/hardware/type'
  87. ,label = (u'类型名称', u'类型key')
  88. ,update = ('name-input-required', 'key-input-required')
  89. )
  90. self.commonOne('hardware_type')
  91. self.commonView('update')
  92. @Web.auth
  93. @Web.setting
  94. def post(self):
  95. self.commonUpdate('hardware_type')
  96. @Web.auth
  97. @Web.setting
  98. def delete(self):
  99. self.commonDelete('hardware_type')
  100. class restart_cron_path(Load):
  101. @Web.auth
  102. @Web.setting
  103. def post(self):
  104. Shell.popen("ps -ef | grep cron.py | grep -v grep |awk '{print $1}'|xargs kill -9")
  105. Shell.popen('/usr/local/demeter/cron.py >/dev/null &')
  106. class restart_sub_path(Load):
  107. @Web.auth
  108. @Web.setting
  109. def post(self):
  110. Shell.popen("ps -ef | grep sub.py | grep -v grep |awk '{print $1}'|xargs kill -9")
  111. class restart_admin_path(Load):
  112. @Web.auth
  113. @Web.setting
  114. def post(self):
  115. Shell.popen("ps -ef | grep admin.py | grep -v grep |awk '{print $1}'|xargs kill -9")
  116. class restart_front_path(Load):
  117. @Web.auth
  118. @Web.setting
  119. def post(self):
  120. Shell.popen("ps -ef | grep front.py | grep -v grep |awk '{print $1}'|xargs kill -9")
  121. class restart_web_path(Load):
  122. @Web.auth
  123. @Web.setting
  124. def post(self):
  125. Shell.popen("ps -ef | grep web.py | grep -v grep |awk '{print $1}'|xargs kill -9")