hardware.py 4.4 KB

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