From dd90f6bd9f049e5d5ae5af90e502eb6511d4e267 Mon Sep 17 00:00:00 2001 From: hoangvv Date: Fri, 28 Feb 2025 10:14:34 +0700 Subject: [PATCH] update --- Makefile | 11 +++++-- fix-link.sh | 83 ++++++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 80 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index 7bae6f66c..055edcdab 100644 --- a/Makefile +++ b/Makefile @@ -64,7 +64,12 @@ clean: html: $(HTML_BUILD_DIR)/_static/style.css @echo "Starting build..." - $(SPHINX_BUILD) -q -c $(CONFIG_DIR) -b html $(SPHINXOPTS) $(SOURCE_DIR) $(HTML_BUILD_DIR) >> $(LOGFILE) + $(SPHINX_BUILD) -q -c $(CONFIG_DIR) -b html $(SPHINXOPTS) $(SOURCE_DIR) $(HTML_BUILD_DIR) + @echo "Build finished." +html_log: SPHINXOPTS += -A collapse_menu=True +html_log: $(HTML_BUILD_DIR)/_static/style.css + @echo "Starting build..." + $(SPHINX_BUILD) -q -c $(CONFIG_DIR) -b html $(SPHINXOPTS) $(SOURCE_DIR) $(HTML_BUILD_DIR) > $(LOGFILE) 2>&1 @echo "Build finished." live: SPHINXOPTS += -A collapse_menu=True @@ -74,7 +79,7 @@ live: --port 8000 --host $(SERVER_IP) \ --watch $(THEME) --watch $(LOCALE) --watch $(STATIC) --watch $(REDIRECTS) --watch $(THEME_STATIC) --watch . \ --pre-build "sh -c 'mkdir -p $(HTML_BUILD_DIR)/_static && python3 -m pysassc $(THEME)/static/style.scss $(HTML_BUILD_DIR)/_static/style.css'" \ - $(SPHINXOPTS) -c $(CONFIG_DIR) -b html + $(SPHINXOPTS) -c $(CONFIG_DIR) -b html @@ -102,7 +107,7 @@ $(HTML_BUILD_DIR)/_static/style.css: extensions/odoo_theme/static/style.scss ext #=== Development and debugging rules ===# fast: SPHINXOPTS += -A collapse_menu=True -fast: html +fast: hmlt static: $(HTML_BUILD_DIR)/_static/style.css cp -r extensions/odoo_theme/static/* $(HTML_BUILD_DIR)/_static/ diff --git a/fix-link.sh b/fix-link.sh index a59866b2a..a1a2cbdcf 100755 --- a/fix-link.sh +++ b/fix-link.sh @@ -1,28 +1,89 @@ #!/bin/bash +# Setup logging +LOG_FILE="_build/script_log_$(date +%Y%m%d_%H%M%S).log" +log_message() { + local timestamp="$(date '+%Y-%m-%d %H:%M:%S')" + echo "[$timestamp] $1" | tee -a "$LOG_FILE" +} + +# Check input file INPUT_FILE="$1" -if [[ ! -f "$INPUT_FILE" ]]; then - echo "Error: Input file does not exist." +if [[ -z "$INPUT_FILE" ]]; then + log_message "ERROR: No input file provided. Usage: $0 " exit 1 fi +if [[ ! -f "$INPUT_FILE" ]]; then + log_message "ERROR: Input file '$INPUT_FILE' does not exist." + exit 1 +fi + +log_message "INFO: Starting script with input file: $INPUT_FILE" + +# Counter for processed lines +processed_count=0 +error_count=0 + while IFS=':' read -r file_path line_err status desc data; do + ((processed_count++)) + # Trim whitespace from variables file_path="$(echo "$file_path" | xargs)" line_err="$(echo "$line_err" | xargs)" status="$(echo "$status" | xargs)" desc="$(echo "$desc" | xargs)" - data="$(echo "$data" | xargs | tr -d "'")" # Remove quotes from data + data="$(echo "$data" | xargs | tr -d "'")" # Remove single quotes from data + + # Log the current line being processed + log_message "DEBUG: Processing line $processed_count - File: $file_path, Desc: $desc, Data: $data" - if [[ -f "$file_path" ]]; then - if [[ "$desc" == "undefined label" ]]; then - fixed_data="$(echo "$data" | tr '\\/_' '-')" - sed -i "s@$data@$fixed_data@g" "$file_path" - elif [[ "$desc" == *"toctree contains reference to nonexisting document"* ]]; then - fixed_data="$(echo "$data" | tr '\\/_' '-')" - sed -i "s@$data@$fixed_data@g" "$file_path" - fi + if [[ -z "$file_path" ]]; then + log_message "WARNING: Empty file path encountered at line $processed_count" + ((error_count++)) + continue fi + if [[ ! -f "$file_path" ]]; then + log_message "ERROR: File not found: $file_path at line $processed_count" + ((error_count++)) + continue + fi + + if [[ ! -w "$file_path" ]]; then + log_message "ERROR: File not writable: $file_path at line $processed_count" + ((error_count++)) + continue + fi + + case "$desc" in + "undefined label"|*"toctree contains reference to nonexisting document"*) + fixed_data="$(echo "$data" | tr '\\/_' '-')" + if sed -i "s@$data@$fixed_data@g" "$file_path" 2>>"$LOG_FILE"; then + log_message "INFO: Successfully fixed issue in $file_path: '$data' -> '$fixed_data'" + else + log_message "ERROR: Failed to modify $file_path" + ((error_count++)) + fi + ;; + *) + log_message "DEBUG: No matching condition for description: $desc" + ;; + esac + done < "$INPUT_FILE" + +# Final summary +log_message "INFO: Script completed" +log_message "INFO: Total lines processed: $processed_count" +log_message "INFO: Total errors encountered: $error_count" + +# Exit with appropriate status +if [[ $error_count -gt 0 ]]; then + log_message "WARNING: Script completed with $error_count errors" + exit 1 +else + log_message "INFO: Script completed successfully" + exit 0 +fi