install.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. from demeter import *
  4. model = Demeter.model('manage_admin')
  5. model.id = 1
  6. info = model.select(type='fetchone')
  7. if not info:
  8. model.role_id = 1
  9. model.username = 'admin'
  10. model.mobile = '15810090845'
  11. model.password = '123456'
  12. model.insert()
  13. model = Demeter.model('manage_role')
  14. model.id = 1
  15. info = model.select(type='fetchone')
  16. if not info:
  17. model.name = '管理员'
  18. model.insert()
  19. model = Demeter.model('content')
  20. model.id = 1
  21. info = model.select(type='fetchone')
  22. if not info:
  23. model.name = '农小盒'
  24. model.subname = '农作物生长监测与产品溯源'
  25. model.insert()
  26. model = Demeter.model('farm')
  27. model.id = 1
  28. info = model.select(type='fetchone')
  29. if not info:
  30. model.name = '默认园区'
  31. model.insert()
  32. # 初始化网关,测试用
  33. model = Demeter.model('device_gateway')
  34. model.hardware_id = 10086
  35. info = model.select(type='fetchone')
  36. if not info:
  37. model.farm_id = 1
  38. model.hardware_id = 10086
  39. model.name = '默认网关'
  40. model.insert()
  41. # 初始化设备类型
  42. device_type = ({'name':'温度', 'key':'temprature', 'unit':'℃'},{'name':'湿度', 'key':'humidity','unit':'%RH'})
  43. model = Demeter.model('device_type')
  44. for value in device_type:
  45. model.key = value['key']
  46. info = model.select(type='fetchone')
  47. if not info:
  48. model.key = value['key']
  49. model.name = value['name']
  50. model.exp = '{n}'
  51. model.unit = value['unit']
  52. model.insert()
  53. # 初始化硬件类型
  54. hardware_type = ({'name':'网关','key':'gateway'},{'name':'传感器', 'key':'sensor'},{'name':'控制器', 'key':'control'},{'name':'电源', 'key':'power'},{'name':'摄像机', 'key':'pic'},{'name':'状态器', 'key':'status'})
  55. model = Demeter.model('hardware_type')
  56. for value in hardware_type:
  57. model.key = value['key']
  58. info = model.select(type='fetchone')
  59. if not info:
  60. model.key = value['key']
  61. model.name = value['name']
  62. model.insert()
  63. # 初始化消息类型
  64. msg_type = ({'name':'系统消息', 'key':'system'},{'name':'警告提醒', 'key':'notice'},{'name':'操作提示', 'key':'oper'},{'name':'新闻', 'key':'news'})
  65. model = Demeter.model('msg_type')
  66. for value in msg_type:
  67. model.key = value['key']
  68. info = model.select(type='fetchone')
  69. if not info:
  70. model.key = value['key']
  71. model.name = value['name']
  72. model.insert()
  73. print 'install success!'