main.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. from core import *
  4. class Main(object):
  5. use = 'docker'
  6. def __new__(cls, *args, **kwargs):
  7. print('error')
  8. sys.exit()
  9. def __init__(self):
  10. pass
  11. @classmethod
  12. def init(self, use = 'docker'):
  13. Core.path = File.path().replace('src/', '')
  14. Args.init()
  15. method = ('use', 'set', 'val', 'up', 'commit', 'path', 'shell', 'master', 'ip')
  16. if Args.action in method:
  17. self.handle()
  18. else:
  19. """
  20. use = Env.use()
  21. if not use:
  22. use = Env.use(self.use)
  23. """
  24. cls = Core.getClass(use, 'tool.')
  25. cls.init()
  26. @classmethod
  27. def handle(self):
  28. method = Core.getMethod(Main_Action, Args.action)
  29. method()
  30. class Main_Action(object):
  31. @staticmethod
  32. def use():
  33. if not Args.name:
  34. print('dm name is not exists!')
  35. sys.exit()
  36. Env.use(Args.name)
  37. @staticmethod
  38. def set():
  39. if not Args.name:
  40. print('dm name is not exists!')
  41. sys.exit()
  42. Env.store(Args.name)
  43. @staticmethod
  44. def val():
  45. if not Args.name:
  46. print('dm name is not exists!')
  47. sys.exit()
  48. if not Args.param:
  49. print('dm param is not exists!')
  50. sys.exit()
  51. Env.val(Args.name, Args.param)
  52. @staticmethod
  53. def up():
  54. print('loading...')
  55. Core.shell('git.pull ' + Core.path)
  56. print('dm update success!')
  57. @staticmethod
  58. def commit():
  59. print(Core.shell('git.push ' + Core.path))
  60. @staticmethod
  61. def path():
  62. print(Core.path)
  63. @staticmethod
  64. def shell():
  65. print(Core.shell(Args.name))
  66. @staticmethod
  67. def master():
  68. print(Core.path + 'src/shell/dm')
  69. @staticmethod
  70. def ip():
  71. if not Args.name:
  72. ifname = 'eth0'
  73. else:
  74. ifname = Args.name
  75. print(Core.ip(ifname))
  76. #Main.init()