install.py 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. from demeter.core import *
  4. def manage():
  5. model = Demeter.model('manage_admin')
  6. model.id = 1
  7. info = model.select(type='fetchone')
  8. if not info:
  9. model.role_id = 1
  10. model.username = 'admin'
  11. model.mobile = '15810090845'
  12. model.password = '123456'
  13. model.insert()
  14. model = Demeter.model('manage_role')
  15. model.id = 1
  16. info = model.select(type='fetchone')
  17. if not info:
  18. model.name = '管理员'
  19. model.insert()
  20. def web():
  21. model = Demeter.model('web_set')
  22. model.id = 1
  23. info = model.select(type='fetchone')
  24. if not info:
  25. model.name = '新农宝盒智慧云平台'
  26. model.keywords = '新农宝盒,智慧云平台,智能硬件,大数据,农业,农业互联网'
  27. model.description = '新农宝盒智慧云平台'
  28. model.icp = '京ICP备12045252号-2'
  29. model.tel = '18701029660'
  30. model.passtel = '18701029660'
  31. model.mobile = ''
  32. model.buy = ''
  33. model.insert()
  34. model = Demeter.model('web_article_category')
  35. data = ('站点介绍', '焦点图', '系统优势')
  36. for value in data:
  37. model.name = value
  38. info = model.select(type='fetchone')
  39. if not info:
  40. model.name = value
  41. model.insert()
  42. model = Demeter.model('web_article')
  43. data = ('合作伙伴', '免责声明', '联系我们', '帮助文档', '团队介绍')
  44. for value in data:
  45. model.name = value
  46. info = model.select(type='fetchone')
  47. if not info:
  48. model.category_id = 1
  49. model.name = value
  50. if model.name == '帮助文档':
  51. model.link = '/help'
  52. model.insert()
  53. model = Demeter.model('web_menu')
  54. data = (
  55. {'name':'新农宝盒首页','link':'/main'}
  56. ,{'name':'灌溉商城','link':'http://www.guangaishangcheng.com/'}
  57. ,{'name':'帮助中心','link':'/help'}
  58. )
  59. for value in data:
  60. model.link = value['link']
  61. info = model.select(type='fetchone')
  62. if not info:
  63. model.name = value['name']
  64. model.link = value['link']
  65. model.insert()
  66. def farm():
  67. farm_id = 1
  68. model = Demeter.model('farm')
  69. model.id = farm_id
  70. info = model.select(type='fetchone')
  71. if not info:
  72. model.name = '默认园区'
  73. model.insert()
  74. # 初始化网关,测试用
  75. hardware_id = 10086
  76. model = Demeter.model('device_gateway')
  77. model.hardware_id = hardware_id
  78. info = model.select(type='fetchone')
  79. if not info:
  80. model.farm_id = farm_id
  81. model.hardware_id = hardware_id
  82. model.name = '默认网关'
  83. id = model.insert()
  84. Demeter.service('device').upGatewayStatus(farm_id, id, hardware_id)
  85. def device():
  86. # 以下类型只能新增,不能随意更改或删除
  87. # 初始化设备类型
  88. device_type = (
  89. {'name':'温度', 'key':'temprature', 'unit':'℃'}
  90. ,{'name':'湿度', 'key':'humidity','unit':'%RH'}
  91. ,{'name':'光照', 'key':'light','unit':'LUX'}
  92. ,{'name':'二氧化碳', 'key':'co2','unit':'PPM'}
  93. ,{'name':'风速', 'key':'speed','unit':'km/h'}
  94. ,{'name':'风向', 'key':'direction','unit':''}
  95. ,{'name':'PM2.5', 'key':'pm2.5','unit':'μg/m3'}
  96. ,{'name':'电源', 'key':'power','unit':'V'}
  97. ,{'name':'阀门', 'key':'valve','unit':''}
  98. ,{'name':'放风机', 'key':'blower','unit':''}
  99. ,{'name':'卷帘机', 'key':'curtain','unit':''}
  100. )
  101. model = Demeter.model('device_type')
  102. for value in device_type:
  103. model.key = value['key']
  104. info = model.select(type='fetchone')
  105. if not info:
  106. model.key = value['key']
  107. model.name = value['name']
  108. #model.exp = '{n}'
  109. model.unit = value['unit']
  110. model.insert()
  111. # 初始化硬件类型 1/1/2/3/4/5/6
  112. hardware_type = (
  113. {'name':'网关', 'key':'gateway'}
  114. ,{'name':'传感器', 'key':'sensor'}
  115. ,{'name':'控制器', 'key':'control'}
  116. ,{'name':'电源', 'key':'power'}
  117. ,{'name':'状态', 'key':'status'}
  118. ,{'name':'摄像头', 'key':'pic'}
  119. ,{'name':'摄像机', 'key':'camera'}
  120. )
  121. model = Demeter.model('hardware_type')
  122. for value in hardware_type:
  123. model.key = value['key']
  124. info = model.select(type='fetchone')
  125. if not info:
  126. model.key = value['key']
  127. model.name = value['name']
  128. model.insert()
  129. # 初始化消息类型
  130. msg_type = (
  131. {'name':'系统消息', 'key':'system'}
  132. ,{'name':'警告提醒', 'key':'notice'}
  133. ,{'name':'操作提示', 'key':'oper'}
  134. ,{'name':'新闻', 'key':'news'}
  135. )
  136. model = Demeter.model('msg_type')
  137. for value in msg_type:
  138. model.key = value['key']
  139. info = model.select(type='fetchone')
  140. if not info:
  141. model.key = value['key']
  142. model.name = value['name']
  143. model.insert()
  144. # 初始化错误码类型
  145. notice_type = (
  146. {'name':'设备离线', 'key':'offline'}
  147. ,{'name':'请求超时', 'key':'timeout'}
  148. )
  149. model = Demeter.model('notice_type')
  150. for value in notice_type:
  151. model.key = value['key']
  152. info = model.select(type='fetchone')
  153. if not info:
  154. model.key = value['key']
  155. model.name = value['name']
  156. model.insert()
  157. manage()
  158. web()
  159. farm()
  160. device()
  161. print 'install success!'