main.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. """
  4. dever-manage tools
  5. name:install.py
  6. author:rabin
  7. chmod +x install
  8. ./install
  9. 基础指令:
  10. use、set、env、up、shell
  11. dm up 更新代码
  12. dm use docker 使用docker工具包
  13. dm set shemic/aliyun/hub 使用哪个仓库为主
  14. dm shell hadoop.memory 直接调用src/shell下的脚本
  15. dm run web 运行web容器组
  16. dm run web-php 运行web容器组下的php容器
  17. dm run web-nginx 运行web容器组下的nginx容器
  18. dm build dev/php 根据dm set定义的主仓库,进行构建镜像
  19. dm rm web 删除web容器组
  20. dm rm 删除所有异常状态的容器
  21. dm show 显示所有容器
  22. dm showi 显示所有镜像
  23. dm rmi 删除所有未使用的镜像
  24. 后续实现:
  25. dm use php 使用php工具包
  26. dm install redis 安装redis
  27. dm install laravel 安装laravel类库
  28. dm remove redis 删除redis
  29. dm use dever 使用dever框架工具包
  30. dm install manage 安装后台
  31. dm create myapp 初始化一个项目
  32. dm install passport 安装官方passport
  33. """
  34. from core import *
  35. class Main(object):
  36. use = 'docker'
  37. def __new__(cls, *args, **kwargs):
  38. print 'error'
  39. sys.exit()
  40. def __init__(self):
  41. pass
  42. @classmethod
  43. def init(self):
  44. Core.path = File.path().replace('/src/', '/')
  45. Args.init()
  46. method = ('use', 'set', 'val', 'up', 'commit', 'path', 'shell')
  47. if Args.action in method:
  48. self.handle()
  49. else:
  50. use = Env.use()
  51. if not use:
  52. use = Env.use(self.use)
  53. cls = Core.getClass(use)
  54. cls.init()
  55. @classmethod
  56. def handle(self):
  57. method = Core.getMethod(Main_Action, Args.action)
  58. method()
  59. class Main_Action(object):
  60. @staticmethod
  61. def use():
  62. if not Args.name:
  63. print 'dm name is not exists!'
  64. sys.exit()
  65. Env.use(Args.name)
  66. @staticmethod
  67. def set():
  68. if not Args.name:
  69. print 'dm name is not exists!'
  70. sys.exit()
  71. Env.store(Args.name)
  72. @staticmethod
  73. def val():
  74. if not Args.name:
  75. print 'dm name is not exists!'
  76. sys.exit()
  77. if not Args.param:
  78. print 'dm param is not exists!'
  79. sys.exit()
  80. Env.val(Args.name, Args.param)
  81. @staticmethod
  82. def up():
  83. print 'loading...'
  84. Core.shell('git.pull ' + Core.path)
  85. print 'dm update success!'
  86. @staticmethod
  87. def commit():
  88. print Core.shell('git.push ' + Core.path)
  89. @staticmethod
  90. def path():
  91. print Core.path
  92. @staticmethod
  93. def shell():
  94. print Core.shell(Args.name)
  95. Main.init()