mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-04-10 21:03:01 +00:00
Refactor stock logo download/save logic and writability check
This commit is contained in:
@@ -51,8 +51,24 @@ class StockManager:
|
|||||||
logger.warning(f"Cannot create logo directory '{self.logo_dir}': {str(e)}. Using temporary directory.")
|
logger.warning(f"Cannot create logo directory '{self.logo_dir}': {str(e)}. Using temporary directory.")
|
||||||
import tempfile
|
import tempfile
|
||||||
self.logo_dir = tempfile.mkdtemp(prefix='stock_logos_')
|
self.logo_dir = tempfile.mkdtemp(prefix='stock_logos_')
|
||||||
elif not os.access(self.logo_dir, os.W_OK):
|
writable = False # Explicitly set writable to false if creation fails
|
||||||
logger.warning(f"Cannot write to logo directory '{self.logo_dir}'. Using temporary directory.")
|
else:
|
||||||
|
writable = True # Assume writable if created successfully
|
||||||
|
else:
|
||||||
|
# Directory exists, check if writable by trying to create a temp file
|
||||||
|
try:
|
||||||
|
temp_file_path = os.path.join(self.logo_dir, ".write_test")
|
||||||
|
with open(temp_file_path, 'w') as f:
|
||||||
|
f.write('test')
|
||||||
|
os.remove(temp_file_path)
|
||||||
|
logger.debug(f"Write test successful in {self.logo_dir}")
|
||||||
|
writable = True
|
||||||
|
except (PermissionError, OSError) as e:
|
||||||
|
logger.warning(f"Cannot write to logo directory '{self.logo_dir}' (write test failed): {e}. Using temporary directory.")
|
||||||
|
writable = False
|
||||||
|
|
||||||
|
# If not writable, switch to a temporary directory
|
||||||
|
if not writable:
|
||||||
import tempfile
|
import tempfile
|
||||||
self.logo_dir = tempfile.mkdtemp(prefix='stock_logos_')
|
self.logo_dir = tempfile.mkdtemp(prefix='stock_logos_')
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user