This commit is contained in:
chendelin1982 2021-11-01 19:23:17 +08:00
parent cbeaad59bc
commit b1063250c7
5 changed files with 74 additions and 15 deletions

Binary file not shown.

Binary file not shown.

View file

@ -104,6 +104,40 @@ class Create:
pass pass
class Manage(model.DockerComposeOp): class Status:
pass
'''The status operation of project, e.g Start | Stop | Restart | Erase'''
def __init__(self, project_name: str, project_path: Optional[str] = None):
self.project_name = project_name
self.project_path = project_path
self.dockerop = model.DockerOp()
projectdict = self.dockerop.getProject()
if self.project_path == None:
try:
self.project_path = projectdict[self.project_name]
self.dockercomposeop = model.DockerComposeOp(self.project_path)
except:
print("No this application!")
sys.exit(0)
def stopApp(self):
pass
def upApp(self):
pass
def startApp(self):
pass
def retartApp(self):
pass
def eraseApp(self):
self.dockercomposeop.down()
def upApp(self):
self.dockercomposeop.up(self.project_path)

View file

@ -115,7 +115,7 @@ class SecurityOp:
class DockerComposeOp: class DockerComposeOp:
'''Docker Compose operation''' '''Docker Compose operation'''
def __int__(self, path: Optional[str] = ""): def __init__(self, path: Optional[str] = ''):
self.cmd_up = "docker-compose up -d" self.cmd_up = "docker-compose up -d"
self.cmd_stop = "docker-compose stop" self.cmd_stop = "docker-compose stop"
@ -125,22 +125,22 @@ class DockerComposeOp:
try: try:
os.chdir(self.path) os.chdir(self.path)
except: except:
print("No found project directory") print("Not found project directory")
sys.exit(0) sys.exit(0)
def up(self): def up(self):
'''docker-compose up''' '''docker-compose up'''
try: try:
os.system(cmd_up) os.system(self.cmd_up)
except: except:
print("Create failed") print("Create failed")
os.system(cmd_up) os.system(self.cmd_up)
sys.exit(0) sys.exit(0)
def stop(self): def stop(self):
'''docker-compose stop''' '''docker-compose stop'''
try: try:
os.system(cmd_stop) os.system(self.cmd_stop)
except: except:
print("Stop failed, suggest try it again") print("Stop failed, suggest try it again")
sys.exit(0) sys.exit(0)
@ -148,7 +148,7 @@ class DockerComposeOp:
def down(self): def down(self):
'''docker-compose down''' '''docker-compose down'''
try: try:
os.system(cmd_down) os.system(self.cmd_down)
except: except:
print("Down failed, suggest try it again") print("Down failed, suggest try it again")
sys.exit(0) sys.exit(0)

View file

@ -22,16 +22,41 @@ def create(app_name: str, project_name: Optional[str] = None):
create.setEnv() create.setEnv()
create.upRepo() create.upRepo()
create.printResult() create.printResult()
@app.command()
def start(app_name: str, project_name: Optional[str] = None):
'''start one application'''
pass
@app.command() @app.command()
def update(name: str): def up(path: str):
'''up one deleted application'''
status = controller.Status("application", path)
status.startApp()
@app.command()
def start(project_name: str):
'''start one stopped application'''
status = controller.Status(project_name)
status.startApp()
@app.command()
def stop(project_name: str):
'''start one running application'''
status = controller.Status(project_name)
status.stopApp()
@app.command()
def restart(project_name: str):
'''Restart one application'''
status = controller.Status(project_name)
status.retartApp()
@app.command()
def erase(project_name: str):
'''erase or delete an application'''
status = controller.Status(project_name)
status.eraseApp()
@app.command()
def update(project_name: str):
'''update the local lists cache''' '''update the local lists cache'''
typer.echo(f"Hello {name}") typer.echo(f"Hello {project_name}")
@app.command() @app.command()