hardware.py 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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':'重启园区服务','link':'/hardware/restart_front','ajax':True,'icon':''},{'name':'重启后台服务','link':'/hardware/restart_admin','ajax':True,'icon':''},{'name':'重启网站服务','link':'/hardware/restart_web','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. )
  78. self.list('hardware_type')
  79. self.show('list')
  80. class type_update_path(Load):
  81. @Web.auth
  82. @Web.setting
  83. def get(self):
  84. self.set(
  85. path = '/hardware/type'
  86. ,label = (u'类型名称', u'类型key')
  87. ,update = ('name-input-required', 'key-input-required')
  88. )
  89. self.one('hardware_type')
  90. self.show('update')
  91. @Web.auth
  92. @Web.setting
  93. def post(self):
  94. self.update('hardware_type')
  95. @Web.auth
  96. @Web.setting
  97. def delete(self):
  98. self.drop('hardware_type')
  99. class restart_cron_path(Load):
  100. @Web.auth
  101. @Web.setting
  102. def post(self):
  103. Shell.popen("ps -ef | grep cron.py | grep -v grep |awk '{print $1}'|xargs kill -9")
  104. Shell.popen('/usr/local/demeter/cron.py >/dev/null &')
  105. class restart_sub_path(Load):
  106. @Web.auth
  107. @Web.setting
  108. def post(self):
  109. Shell.popen("ps -ef | grep sub.py | grep -v grep |awk '{print $1}'|xargs kill -9")
  110. class restart_admin_path(Load):
  111. @Web.auth
  112. @Web.setting
  113. def post(self):
  114. Shell.popen("ps -ef | grep admin.py | grep -v grep |awk '{print $1}'|xargs kill -9")
  115. class restart_front_path(Load):
  116. @Web.auth
  117. @Web.setting
  118. def post(self):
  119. Shell.popen("ps -ef | grep front.py | grep -v grep |awk '{print $1}'|xargs kill -9")
  120. class restart_web_path(Load):
  121. @Web.auth
  122. @Web.setting
  123. def post(self):
  124. Shell.popen("ps -ef | grep web.py | grep -v grep |awk '{print $1}'|xargs kill -9")