Improve code logic for password & resolution

This commit is contained in:
yuanmengqi
2025-07-13 06:59:45 +00:00
parent 08bbf77511
commit a070ddda7e
13 changed files with 93 additions and 51 deletions

View File

@@ -27,12 +27,6 @@ import dotenv
# Load environment variables from .env file
dotenv.load_dotenv()
if os.environ.get("PROVIDER_NAME") == "aws":
os.environ["CLIENT_PASSWORD"] = os.environ.get("CLIENT_PASSWORD_AWS", "osworld-public-evaluation")
else:
os.environ["CLIENT_PASSWORD"] = os.environ.get("CLIENT_PASSWORD", "password")
CLIENT_PASSWORD = os.environ["CLIENT_PASSWORD"]
PROXY_CONFIG_FILE = os.getenv("PROXY_CONFIG_FILE", "evaluation_examples/settings/proxy/dataimpulse.json") # Default proxy config file
@@ -45,7 +39,7 @@ init_proxy_pool(PROXY_CONFIG_FILE) # initialize the global proxy pool
MAX_RETRIES = 20
class SetupController:
def __init__(self, vm_ip: str, server_port: int = 5000, chromium_port: int = 9222, vlc_port: int = 8080, cache_dir: str = "cache"):
def __init__(self, vm_ip: str, server_port: int = 5000, chromium_port: int = 9222, vlc_port: int = 8080, cache_dir: str = "cache", client_password: str = "", screen_width: int = 1920, screen_height: int = 1080):
self.vm_ip: str = vm_ip
self.server_port: int = server_port
self.chromium_port: int = chromium_port
@@ -54,6 +48,9 @@ class SetupController:
self.http_server_setup_root: str = f"http://{vm_ip}:{server_port}/setup"
self.cache_dir: str = cache_dir
self.use_proxy: bool = False
self.client_password: str = client_password
self.screen_width: int = screen_width
self.screen_height: int = screen_height
def reset_cache_dir(self, cache_dir: str):
self.cache_dir = cache_dir
@@ -304,22 +301,31 @@ class SetupController:
terminates: bool = False
nb_failings = 0
def replace_screen_env_in_command(command_list):
width = int(os.environ.get("SCREEN_WIDTH", 1920))
height = int(os.environ.get("SCREEN_HEIGHT", 1080))
def replace_screen_env_in_command(command):
password = self.client_password
width = self.screen_width
height = self.screen_height
width_half = str(width // 2)
height_half = str(height // 2)
new_command_list = []
for item in command_list:
if isinstance(item, str):
new_command = ""
if isinstance(command, str):
new_command = command.replace("{CLIENT_PASSWORD}", password)
new_command = new_command.replace("{SCREEN_WIDTH_HALF}", width_half)
new_command = new_command.replace("{SCREEN_HEIGHT_HALF}", height_half)
new_command = new_command.replace("{SCREEN_WIDTH}", str(width))
new_command = new_command.replace("{SCREEN_HEIGHT}", str(height))
return new_command
else:
for item in command:
item = item.replace("{CLIENT_PASSWORD}", password)
item = item.replace("{SCREEN_WIDTH_HALF}", width_half)
item = item.replace("{SCREEN_HEIGHT_HALF}", height_half)
item = item.replace("{SCREEN_WIDTH}", str(width))
item = item.replace("{SCREEN_HEIGHT}", str(height))
new_command_list.append(item)
return new_command_list
if isinstance(command, list):
command = replace_screen_env_in_command(command)
new_command_list.append(item)
return new_command_list
command = replace_screen_env_in_command(command)
payload = json.dumps({"command": command, "shell": shell})
headers = {"Content-Type": "application/json"}
@@ -467,7 +473,7 @@ class SetupController:
except requests.exceptions.RequestException as e:
logger.error("An error occurred while trying to send the request: %s", e)
def _proxy_setup(self, client_password: str = CLIENT_PASSWORD):
def _proxy_setup(self, client_password: str = ""):
"""Setup system-wide proxy configuration using proxy pool
Args: