mirror of
https://github.com/zen-browser/desktop.git
synced 2025-07-08 01:19:59 +02:00
Update update_newtab.py
feat: Enhance error handling and logging in newtab update script Add directory existence validation for NEW_TAB_DIR and ENGINE_DIR Implement detailed subprocess output capturing with error logging Introduce comprehensive exception handling with specific error types Signed-off-by: Jarm7 <kotek.moorkotek@gmail.com>
This commit is contained in:
parent
0fbc5178f6
commit
796a52625e
1 changed files with 56 additions and 24 deletions
|
@ -2,40 +2,72 @@ import os
|
||||||
import subprocess
|
import subprocess
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
# Set up logging
|
logging.basicConfig(
|
||||||
logging.basicConfig(level=logging.INFO)
|
level=logging.INFO,
|
||||||
|
format='%(asctime)s - %(levelname)s - %(message)s'
|
||||||
|
)
|
||||||
|
|
||||||
# Constants for paths
|
|
||||||
NEW_TAB_DIR = "./engine/browser/components/newtab"
|
NEW_TAB_DIR = "./engine/browser/components/newtab"
|
||||||
ENGINE_DIR = "./engine"
|
ENGINE_DIR = "./engine"
|
||||||
NPM_INSTALL_COMMANDS = ["npm install", "npm install meow@9.0.0"]
|
NPM_INSTALL_COMMANDS = ["npm install", "npm install meow@9.0.0"]
|
||||||
BUNDLE_COMMAND = "npm run bundle --prefix=browser/components/newtab"
|
BUNDLE_COMMAND = "npm run bundle --prefix=browser/components/newtab"
|
||||||
|
|
||||||
|
|
||||||
def install_dependencies():
|
def install_dependencies():
|
||||||
"""Install necessary npm packages for the newtab component."""
|
if not os.path.isdir(NEW_TAB_DIR):
|
||||||
for command in NPM_INSTALL_COMMANDS:
|
logging.error(f"Directory not found: {NEW_TAB_DIR}")
|
||||||
logging.info(f"Running command: {command} in {NEW_TAB_DIR}")
|
raise FileNotFoundError(f"New tab directory {NEW_TAB_DIR} does not exist")
|
||||||
subprocess.run(command.split(), cwd=NEW_TAB_DIR, check=True)
|
|
||||||
|
for command in NPM_INSTALL_COMMANDS:
|
||||||
|
try:
|
||||||
|
logging.info(f"Running command: {command} in {NEW_TAB_DIR}")
|
||||||
|
subprocess.run(
|
||||||
|
command.split(),
|
||||||
|
cwd=NEW_TAB_DIR,
|
||||||
|
check=True,
|
||||||
|
capture_output=True,
|
||||||
|
text=True
|
||||||
|
)
|
||||||
|
logging.info(f"Successfully executed: {command}")
|
||||||
|
except subprocess.CalledProcessError as e:
|
||||||
|
logging.error(f"Command failed: {command} - {e.stderr}")
|
||||||
|
raise
|
||||||
|
|
||||||
def bundle_newtab_components():
|
def bundle_newtab_components():
|
||||||
"""Bundle the newtab components."""
|
if not os.path.isdir(ENGINE_DIR):
|
||||||
logging.info(f"Bundling newtab components in {ENGINE_DIR}")
|
logging.error(f"Directory not found: {ENGINE_DIR}")
|
||||||
subprocess.run(BUNDLE_COMMAND.split(), cwd=ENGINE_DIR, check=True)
|
raise FileNotFoundError(f"Engine directory {ENGINE_DIR} does not exist")
|
||||||
|
|
||||||
|
try:
|
||||||
|
logging.info(f"Bundling newtab components in {ENGINE_DIR}")
|
||||||
|
result = subprocess.run(
|
||||||
|
BUNDLE_COMMAND.split(),
|
||||||
|
cwd=ENGINE_DIR,
|
||||||
|
check=True,
|
||||||
|
capture_output=True,
|
||||||
|
text=True
|
||||||
|
)
|
||||||
|
logging.info(f"Bundle completed successfully: {result.stdout}")
|
||||||
|
except subprocess.CalledProcessError as e:
|
||||||
|
logging.error(f"Bundle failed: {e.stderr}")
|
||||||
|
raise
|
||||||
|
|
||||||
def update_newtab(init: bool = True):
|
def update_newtab(init: bool = True):
|
||||||
"""Update the newtab components, optionally initializing dependencies."""
|
try:
|
||||||
try:
|
if init:
|
||||||
if init:
|
logging.info("Starting dependency installation")
|
||||||
install_dependencies()
|
install_dependencies()
|
||||||
|
logging.info("Dependencies installed successfully")
|
||||||
bundle_newtab_components()
|
|
||||||
except subprocess.CalledProcessError as e:
|
logging.info("Starting bundle process")
|
||||||
logging.error(f"An error occurred: {e}")
|
bundle_newtab_components()
|
||||||
raise
|
logging.info("Newtab update completed successfully")
|
||||||
|
|
||||||
|
except (subprocess.CalledProcessError, FileNotFoundError) as e:
|
||||||
|
logging.error(f"Update process failed: {str(e)}")
|
||||||
|
raise
|
||||||
|
except Exception as e:
|
||||||
|
logging.error(f"Unexpected error: {str(e)}")
|
||||||
|
raise
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
update_newtab(init=False)
|
update_newtab(init=False)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue