feat&fix: add proxy support in setup and remove hardcoded proxy from example
This commit is contained in:
@@ -47,11 +47,12 @@ class SetupController:
|
||||
self.http_server: str = f"http://{vm_ip}:{server_port}"
|
||||
self.http_server_setup_root: str = f"http://{vm_ip}:{server_port}/setup"
|
||||
self.cache_dir: str = cache_dir
|
||||
self.use_proxy: bool = False
|
||||
|
||||
def reset_cache_dir(self, cache_dir: str):
|
||||
self.cache_dir = cache_dir
|
||||
|
||||
def setup(self, config: List[Dict[str, Any]])-> bool:
|
||||
def setup(self, config: List[Dict[str, Any]], use_proxy: bool = False)-> bool:
|
||||
"""
|
||||
Args:
|
||||
config (List[Dict[str, Any]]): list of dict like {str: Any}. each
|
||||
@@ -63,6 +64,7 @@ class SetupController:
|
||||
parameters
|
||||
}
|
||||
"""
|
||||
self.use_proxy = use_proxy
|
||||
# make sure connection can be established
|
||||
logger.info(f"try to connect {self.http_server}")
|
||||
retry = 0
|
||||
@@ -237,6 +239,9 @@ class SetupController:
|
||||
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()
|
||||
|
||||
if command[0] == "google-chrome" and self.use_proxy:
|
||||
command.append("--proxy-server=http://127.0.0.1:18888") # Use the proxy server set up by _proxy_setup
|
||||
|
||||
payload = json.dumps({"command": command, "shell": shell})
|
||||
headers = {"Content-Type": "application/json"}
|
||||
|
||||
@@ -203,7 +203,7 @@ class DesktopEnv(gym.Env):
|
||||
self._set_task_info(task_config)
|
||||
self.setup_controller.reset_cache_dir(self.cache_dir)
|
||||
logger.info("Setting up environment...")
|
||||
success = self.setup_controller.setup(self.config)
|
||||
success = self.setup_controller.setup(self.config, task_config.get("proxy", False) and self.enable_proxy)
|
||||
if success:
|
||||
break
|
||||
else:
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
"parameters": {
|
||||
"command": [
|
||||
"google-chrome",
|
||||
"--proxy-server=http://127.0.0.1:18888",
|
||||
"--remote-debugging-port=1337"
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user