Merge branch 'zdy'
This commit is contained in:
@@ -3,6 +3,8 @@ from typing import Any, Dict
|
||||
import requests
|
||||
from desktop_env.envs.actions import KEYBOARD_KEYS
|
||||
|
||||
import logging
|
||||
logger = logging.getLogger("desktopenv.pycontroller")
|
||||
|
||||
class PythonController:
|
||||
def __init__(self, http_server: str, pkgs_prefix: str = "python -c \"import pyautogui; {command}\""):
|
||||
@@ -17,7 +19,7 @@ class PythonController:
|
||||
if response.status_code == 200:
|
||||
return response.content
|
||||
else:
|
||||
print("Failed to get screenshot. Status code:", response.status_code)
|
||||
logger.error("Failed to get screenshot. Status code: %d", response.status_code)
|
||||
return None
|
||||
|
||||
def get_file(self, file_path: str):
|
||||
@@ -26,10 +28,10 @@ class PythonController:
|
||||
"""
|
||||
response = requests.post(self.http_server + "/file", data={"file_path": file_path})
|
||||
if response.status_code == 200:
|
||||
print("File downloaded successfully")
|
||||
logger.info("File downloaded successfully")
|
||||
return response.content
|
||||
else:
|
||||
print("Failed to get file. Status code:", response.status_code)
|
||||
logger.error("Failed to get file. Status code: %d", response.status_code)
|
||||
return None
|
||||
|
||||
def execute_python_command(self, command: str) -> None:
|
||||
@@ -38,7 +40,7 @@ class PythonController:
|
||||
It can be used to execute the pyautogui commands, or... any other python command. who knows?
|
||||
"""
|
||||
command = self.pkgs_prefix.format(command=command)
|
||||
payload = json.dumps({"command": command})
|
||||
payload = json.dumps({"command": command, "shell": True})
|
||||
headers = {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
@@ -46,12 +48,12 @@ class PythonController:
|
||||
try:
|
||||
response = requests.post(self.http_server + "/execute", headers=headers, data=payload)
|
||||
if response.status_code == 200:
|
||||
print("Command executed successfully:", response.text)
|
||||
logger.info("Command executed successfully: %s", response.text)
|
||||
else:
|
||||
print("Failed to execute command. Status code:", response.status_code)
|
||||
logger.error("Failed to execute command. Status code: %d", response.status_code)
|
||||
return response.json()
|
||||
except requests.exceptions.RequestException as e:
|
||||
print("An error occurred while trying to execute the command:", e)
|
||||
logger.error("An error occurred while trying to execute the command: %s", e)
|
||||
|
||||
def execute_action(self, action: Dict[str, Any]):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user