websoft9/cli/controller.py

63 lines
1.5 KiB
Python
Raw Normal View History

2021-09-28 10:34:18 +00:00
import model, os, sys, subprocess
from model import GitOp
2021-09-26 09:57:34 +00:00
path_repo = "./data/application.list"
path_project = ""
2021-09-26 15:05:59 +00:00
# for Git clone HA
github_url = ("https://github.com", "https://github.com.cnpmjs.org", "https://hub.fastgit.org")
2021-09-26 09:57:34 +00:00
class Print:
def __init__(self):
pass
def printRepo():
2021-09-26 15:05:59 +00:00
model.FileOp.printJson(path_repo)
2021-09-27 09:32:10 +00:00
class Create:
2021-09-26 15:05:59 +00:00
2021-09-27 09:32:10 +00:00
def __init__(self, app_name: str, project_name: str):
self.folder = None
self.app_name = app_name
self.project_name = project_name
if self.project_name != None:
self.folder = self.project_name
else:
self.folder = self.app_name
2021-09-26 15:05:59 +00:00
2021-09-27 09:32:10 +00:00
def downRepo(self):
2021-09-28 10:34:18 +00:00
'''download repository'''
2021-10-08 07:03:27 +00:00
geturl = model.SmoothUrl()
gitop = model.GitOp()
cmd = "git clone --depth=1 " + geturl.res(github_url) + "/websoft9/docker-" + self.app_name + " " + self.folder
2021-09-27 09:32:10 +00:00
if os.path.exists("./"+self.folder):
print(os.path.abspath(self.folder)+" folder already exists")
2021-09-28 10:34:18 +00:00
sys.exit(0)
2021-09-27 09:32:10 +00:00
else:
2021-10-08 07:03:27 +00:00
gitop.gitClone(cmd)
2021-09-28 10:34:18 +00:00
def setEnv(self):
'''set the usable port for application'''
2021-10-08 07:03:27 +00:00
fileop=model.FileOp()
2021-10-10 15:54:15 +00:00
print(fileop.fileToJson(self.folder+'/.env'))
2021-09-28 10:34:18 +00:00
pass
2021-09-27 09:32:10 +00:00
def upRepo(self):
2021-09-28 10:34:18 +00:00
'''docker-compose up repository'''
2021-10-08 07:03:27 +00:00
cmd = "docker-compose up -d"
2021-09-26 15:05:59 +00:00
print(cmd)
2021-09-27 09:32:10 +00:00
os.chdir(self.folder)
2021-09-28 10:34:18 +00:00
os.system(cmd)
def printResult(self):
2021-10-07 09:36:09 +00:00
pass