From c74b64d3afa8d95dcb92e588c9420eeb17daf38e Mon Sep 17 00:00:00 2001 From: Toyga <330282372@qq.com> Date: Wed, 8 Mar 2023 17:10:59 +0800 Subject: [PATCH] appmanage:add trademark --- appmanage/api/service/manage.py | 100 +++++++++++++++++++------------- 1 file changed, 59 insertions(+), 41 deletions(-) diff --git a/appmanage/api/service/manage.py b/appmanage/api/service/manage.py index f7e45f5b..ff86c43c 100644 --- a/appmanage/api/service/manage.py +++ b/appmanage/api/service/manage.py @@ -8,8 +8,6 @@ from api.model.response import Response # 获取所有app的信息 def get_my_app(app_name=None): #{"name":"id",...} - ip_result = shell_execute.execute_command_output_all("curl ifconfig.me") - ip = ip_result["result"] ret = Response(code=const.RETURN_FAIL, message="app查询失败") # get all info @@ -20,45 +18,7 @@ def get_my_app(app_name=None): list = [] output_list = output_list[4:] num = int(len(output_list) / 3) - for i in range(0, num): - name = output_list[3 * i] #name - image_url = "https://libs.websoft9.com/Websoft9/logo/product/" + name + "-websoft9.png" - trade_mark = "" - id = 0 #id - status = output_list[3 * i + 1].split("(")[0] #status - if(status.startswith("r")): - status_code = const.RETURN_RUNNING #status_code - else: - status_code = const.RETURN_STOP - volume = output_list[3 * i+2] #volume - j = 2 - while not volume.startswith("/"): - volume = output_list[3*i+j] - j = j+1 - # get env info - path = "/data/apps/" + name + "/.env" - http_port_env, http_port = docker.read_env(path, "APP_HTTP_PORT") - db_port_env, db_port = docker.read_env(path, "APP_DB.*_PORT") - # get port and url - port = 0 - url = "-" - if http_port != "": - port = int(http_port) - url = "http://"+ip+":"+str(port) - elif db_port != "": - port = int(db_port) - - # get user_name - username_env, user_name = docker.read_env(path, "APP_USER") - if user_name == "": - user_name = "-" - # get password - password_env, password = docker.read_env(path, "POWER_PASSWORD") - if password == "": - password = "-" - - app = App(id=id, name=name, status_code=status_code, status=status, port=port, volume=volume, url=url, image_url=image_url, trade_mark=trade_mark, user_name=user_name, password=password) - list.append(app.dict()) + list = set_app_info(output_list, num) flag = 0 if app_name != None: for app in list: @@ -72,6 +32,64 @@ def get_my_app(app_name=None): ret = ret.dict() return ret +def set_app_info(output_list, num): + ip_result = shell_execute.execute_command_output_all("curl ifconfig.me") + ip = ip_result["result"] + list = [] + for i in range(0, num): + name = output_list[3 * i] # name + image_url = "https://libs.websoft9.com/Websoft9/logo/product/" + name + "-websoft9.png" + # get trade_mark + trade_mark = "" + var_path = "/data/apps/" + name + "/variables.json" + try: + f = open(var_path, 'r', encoding='utf-8') + var = json.load(f) + try: + trade_mark = var["trademark"] + except KeyError: + pass + except FileNotFoundError: + pass + id = 0 # id + case = output_list[3 * i + 1].split("(")[0] # case + if (case.startswith("r")): + case_code = const.RETURN_RUNNING # case_code + else: + case = "stop" + case_code = const.RETURN_STOP + volume = output_list[3 * i + 2] # volume + j = 2 + while not volume.startswith("/"): + volume = output_list[3 * i + j] + j = j + 1 + # get env info + path = "/data/apps/" + name + "/.env" + http_port_env, http_port = docker.read_env(path, "APP_HTTP_PORT") + db_port_env, db_port = docker.read_env(path, "APP_DB.*_PORT") + # get port and url + port = 0 + url = "-" + if http_port != "": + port = int(http_port) + url = "http://" + ip + ":" + str(port) + elif db_port != "": + port = int(db_port) + + # get user_name + username_env, user_name = docker.read_env(path, "APP_USER") + if user_name == "": + user_name = "-" + # get password + password_env, password = docker.read_env(path, "POWER_PASSWORD") + if password == "": + password = "-" + + app = App(id=id, name=name, status_code=case_code, status=case, port=port, volume=volume, url=url, + image_url=image_url, trade_mark=trade_mark, user_name=user_name, password=password) + list.append(app.dict()) + return list + def install_app(app_name): # check directory if docker.check_app_directory(app_name):