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

View file

@ -22,16 +22,41 @@ def create(app_name: str, project_name: Optional[str] = None):
create.setEnv()
create.upRepo()
create.printResult()
@app.command()
def start(app_name: str, project_name: Optional[str] = None):
'''start one application'''
pass
@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'''
typer.echo(f"Hello {name}")
typer.echo(f"Hello {project_name}")
@app.command()