ver Jan14th

setup method for Thunderbird composing tasks
This commit is contained in:
David Chang
2024-01-14 23:13:56 +08:00
parent 005b054a0b
commit 59fdd9f1a2
4 changed files with 71 additions and 11 deletions

View File

@@ -204,15 +204,15 @@ class SetupController:
except requests.exceptions.RequestException as e:
logger.error("An error occurred while trying to send the request: %s", e)
def _launch_setup(self, command: Union[str, List[str]]):
def _launch_setup(self, command: Union[str, List[str]], shell: bool = False):
if not command:
raise Exception("Empty command to launch.")
if isinstance(command, str) and len(command.split()) > 1:
if not shell and isinstance(command, str) and len(command.split()) > 1:
logger.warning("Command should be a list of strings. Now it is a string. Will split it by space.")
command = command.split()
payload = json.dumps({"command": command})
payload = json.dumps({"command": command, "shell": shell})
headers = {"Content-Type": "application/json"}
try:
@@ -239,7 +239,7 @@ class SetupController:
while not terminates:
try:
response = requests.post(self.http_server_setup_root + "/execute", headers=headers, data=payload)
response = requests.post(self.http_server + "/setup" + "/execute", headers=headers, data=payload)
if response.status_code == 200:
results: Dict[str, str] = response.json()
if stdout:

View File

@@ -61,11 +61,12 @@ def execute_command():
@app.route('/setup/launch', methods=["POST"])
def launch_app():
data = request.json
command: List[str] = data.get("command", [])
shell = data.get("shell", False)
command: List[str] = data.get("command", "" if shell else [])
try:
subprocess.Popen(command)
return "{:} launched successfully".format(" ".join(command))
subprocess.Popen(command, shell=shell)
return "{:} launched successfully".format(command if shell else " ".join(command))
except Exception as e:
return jsonify({"status": "error", "message": str(e)}), 500