From fcdaf7ce0b41b14f295b90e7b150af4e629b7352 Mon Sep 17 00:00:00 2001 From: Jason Lee Date: Thu, 4 Jul 2024 09:37:13 -0500 Subject: [PATCH] Update setup.py for update_browse_history function --- desktop_env/controllers/setup.py | 41 ++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/desktop_env/controllers/setup.py b/desktop_env/controllers/setup.py index 3bacb25..7604d11 100644 --- a/desktop_env/controllers/setup.py +++ b/desktop_env/controllers/setup.py @@ -580,11 +580,33 @@ class SetupController: return browser, context def _update_browse_history_setup(self, **config): - db_path = os.path.join("desktop_env", "assets", "history_empty.sqlite") - - # copy a new history file in the tmp folder cache_path = os.path.join(self.cache_dir, "history_new.sqlite") - shutil.copyfile(db_path, cache_path) + db_url = "https://drive.usercontent.google.com/u/0/uc?id=1Lv74QkJYDWVX0RIgg0Co-DUcoYpVL0oX&export=download" # google drive + if not os.path.exists(cache_path): + max_retries = 3 + downloaded = False + e = None + for i in range(max_retries): + try: + response = requests.get(db_url, stream=True) + response.raise_for_status() + + with open(cache_path, 'wb') as f: + for chunk in response.iter_content(chunk_size=8192): + if chunk: + f.write(chunk) + logger.info("File downloaded successfully") + downloaded = True + break + + except requests.RequestException as e: + logger.error( + f"Failed to download {db_url} caused by {e}. Retrying... ({max_retries - i - 1} attempts left)") + if not downloaded: + raise requests.RequestException(f"Failed to download {db_url}. No retries left. Error: {e}") + else: + logger.info("File already exists in cache directory") + # copy a new history file in the tmp folder db_path = cache_path history = config['history'] @@ -632,9 +654,14 @@ class SetupController: """import os; print(os.path.join(os.getenv('HOME'), "Library", "Application Support", "Google", "Chrome", "Default", "History"))""")[ 'output'].strip() elif os_type == 'Linux': - chrome_history_path = controller.execute_python_command( - "import os; print(os.path.join(os.getenv('HOME'), '.config', 'google-chrome', 'Default', 'History'))")[ - 'output'].strip() + if "arm" in platform.machine(): + chrome_history_path = controller.execute_python_command( + "import os; print(os.path.join(os.getenv('HOME'), 'snap', 'chromium', 'common', 'chromium', 'Default', 'History'))")[ + 'output'].strip() + else: + chrome_history_path = controller.execute_python_command( + "import os; print(os.path.join(os.getenv('HOME'), '.config', 'google-chrome', 'Default', 'History'))")[ + 'output'].strip() else: raise Exception('Unsupported operating system')