adds path config checks in config and dummy scraper
This commit is contained in:
parent
012163ba3f
commit
987c76969b
@ -70,25 +70,31 @@ def _update_download_path(new_path):
|
|||||||
# Try to create it if it doesn't exist
|
# Try to create it if it doesn't exist
|
||||||
try:
|
try:
|
||||||
os.makedirs(new_path, exist_ok=True)
|
os.makedirs(new_path, exist_ok=True)
|
||||||
ActivityLog.log_system_activity(
|
ActivityLog.log_scraper_activity(
|
||||||
action="create_directory",
|
action="create_directory",
|
||||||
status="info",
|
status="info",
|
||||||
description=f"Created download directory: {new_path}"
|
description=f"Created download directory: {new_path}"
|
||||||
)
|
)
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
ActivityLog.log_system_activity(
|
ActivityLog.log_error(
|
||||||
action="create_directory",
|
error_message=f"Failed to create download directory: {new_path}, Error: {str(e)}",
|
||||||
status="error",
|
source="update_download_path"
|
||||||
description=f"Failed to create download directory: {new_path}, Error: {str(e)}"
|
|
||||||
)
|
)
|
||||||
return False, f"Path '{new_path}' is not a valid directory and could not be created: {e}", None
|
return False, f"Path '{new_path}' is not a valid directory and could not be created: {e}", None
|
||||||
|
|
||||||
|
# Check if the path is readable
|
||||||
|
if not os.access(new_path, os.R_OK):
|
||||||
|
ActivityLog.log_error(
|
||||||
|
error_message=f"Download path '{new_path}' is not readable.",
|
||||||
|
source="check_directory_permissions"
|
||||||
|
)
|
||||||
|
return False, f"Path '{new_path}' exists but is not readable by the application.", None
|
||||||
|
|
||||||
# Check if the path is writable
|
# Check if the path is writable
|
||||||
if not os.access(new_path, os.W_OK):
|
if not os.access(new_path, os.W_OK):
|
||||||
ActivityLog.log_system_activity(
|
ActivityLog.log_error(
|
||||||
action="check_directory_permissions",
|
error_message=f"Download path '{new_path}' is not writable.",
|
||||||
status="error",
|
source="check_directory_permissions"
|
||||||
description=f"Download path '{new_path}' is not writable."
|
|
||||||
)
|
)
|
||||||
return False, f"Path '{new_path}' exists but is not writable by the application.", None
|
return False, f"Path '{new_path}' exists but is not writable by the application.", None
|
||||||
# --- End of validation ---
|
# --- End of validation ---
|
||||||
|
@ -37,8 +37,72 @@ class Scraper(BaseScraper):
|
|||||||
file_name = f"{doi.replace('/', '_')}.pdf"
|
file_name = f"{doi.replace('/', '_')}.pdf"
|
||||||
file_path = f"{download_path}/{file_name}"
|
file_path = f"{download_path}/{file_name}"
|
||||||
|
|
||||||
# Create directory if it doesn't exist
|
# Check if the path is readable and writable
|
||||||
os.makedirs(download_path, exist_ok=True)
|
if not os.path.exists(download_path):
|
||||||
|
try:
|
||||||
|
# Create directory if it doesn't exist
|
||||||
|
os.makedirs(download_path, exist_ok=True)
|
||||||
|
except OSError as e:
|
||||||
|
error_msg = f"Failed to create download directory: {str(e)}"
|
||||||
|
paper.status = "Failed"
|
||||||
|
paper.error_msg = error_msg
|
||||||
|
|
||||||
|
ActivityLog.log_scraper_activity(
|
||||||
|
action="dummy_scrape_path_error",
|
||||||
|
status="error",
|
||||||
|
description=error_msg,
|
||||||
|
paper_id=paper.id
|
||||||
|
)
|
||||||
|
|
||||||
|
return ScrapeResult(
|
||||||
|
status="error",
|
||||||
|
message=error_msg,
|
||||||
|
data={"error_code": "path_creation_error"},
|
||||||
|
duration=time.time() - start_time,
|
||||||
|
timestamp=datetime.utcnow()
|
||||||
|
)
|
||||||
|
|
||||||
|
# Check if the path is readable
|
||||||
|
if not os.access(download_path, os.R_OK):
|
||||||
|
error_msg = f"Download path '{download_path}' is not readable"
|
||||||
|
paper.status = "Failed"
|
||||||
|
paper.error_msg = error_msg
|
||||||
|
|
||||||
|
ActivityLog.log_scraper_activity(
|
||||||
|
action="dummy_scrape_path_error",
|
||||||
|
status="error",
|
||||||
|
description=error_msg,
|
||||||
|
paper_id=paper.id
|
||||||
|
)
|
||||||
|
|
||||||
|
return ScrapeResult(
|
||||||
|
status="error",
|
||||||
|
message=error_msg,
|
||||||
|
data={"error_code": "path_read_error"},
|
||||||
|
duration=time.time() - start_time,
|
||||||
|
timestamp=datetime.utcnow()
|
||||||
|
)
|
||||||
|
|
||||||
|
# Check if the path is writable
|
||||||
|
if not os.access(download_path, os.W_OK):
|
||||||
|
error_msg = f"Download path '{download_path}' is not writable"
|
||||||
|
paper.status = "Failed"
|
||||||
|
paper.error_msg = error_msg
|
||||||
|
|
||||||
|
ActivityLog.log_scraper_activity(
|
||||||
|
action="dummy_scrape_path_error",
|
||||||
|
status="error",
|
||||||
|
description=error_msg,
|
||||||
|
paper_id=paper.id
|
||||||
|
)
|
||||||
|
|
||||||
|
return ScrapeResult(
|
||||||
|
status="error",
|
||||||
|
message=error_msg,
|
||||||
|
data={"error_code": "path_write_error"},
|
||||||
|
duration=time.time() - start_time,
|
||||||
|
timestamp=datetime.utcnow()
|
||||||
|
)
|
||||||
|
|
||||||
# Create a simple dummy PDF file
|
# Create a simple dummy PDF file
|
||||||
try:
|
try:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user