mirror of
https://github.com/ChuckBuilds/LEDMatrix.git
synced 2026-04-29 20:13:00 +00:00
fix(backup): address Codacy findings
- api_v3: replace 'fonts' in ' '.join(result.restored) substring check
with any(r.startswith("fonts") for r in result.restored) to avoid
fragile joined-string membership testing
- api_v3: replace deprecated datetime.utcnow() and utcfromtimestamp()
with datetime.now(timezone.utc) and fromtimestamp(..., timezone.utc);
add timezone to import
- test: remove unused import io (backup_manager no longer uses BytesIO)
- src/backup_manager.py hardcoded /tmp sentinel was already fixed in a
prior commit (tempfile.TemporaryDirectory)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import io
|
|
||||||
import json
|
import json
|
||||||
import zipfile
|
import zipfile
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import time
|
|||||||
import hashlib
|
import hashlib
|
||||||
import uuid
|
import uuid
|
||||||
import logging
|
import logging
|
||||||
from datetime import datetime
|
from datetime import datetime, timezone
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Optional, Tuple, Dict, Any, Type
|
from typing import Optional, Tuple, Dict, Any, Type
|
||||||
|
|
||||||
@@ -1147,7 +1147,7 @@ def backup_export():
|
|||||||
'status': 'success',
|
'status': 'success',
|
||||||
'filename': zip_path.name,
|
'filename': zip_path.name,
|
||||||
'size': zip_path.stat().st_size,
|
'size': zip_path.stat().st_size,
|
||||||
'created_at': datetime.utcnow().isoformat() + 'Z',
|
'created_at': datetime.now(timezone.utc).isoformat(),
|
||||||
})
|
})
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.exception("[Backup] export failed")
|
logger.exception("[Backup] export failed")
|
||||||
@@ -1167,7 +1167,7 @@ def backup_list():
|
|||||||
entries.append({
|
entries.append({
|
||||||
'filename': path.name,
|
'filename': path.name,
|
||||||
'size': stat.st_size,
|
'size': stat.st_size,
|
||||||
'created_at': datetime.utcfromtimestamp(stat.st_mtime).isoformat() + 'Z',
|
'created_at': datetime.fromtimestamp(stat.st_mtime, timezone.utc).isoformat(),
|
||||||
})
|
})
|
||||||
return jsonify({'status': 'success', 'data': entries})
|
return jsonify({'status': 'success', 'data': entries})
|
||||||
except Exception:
|
except Exception:
|
||||||
@@ -1355,7 +1355,7 @@ def backup_restore():
|
|||||||
result.plugins_failed.append({'plugin_id': plugin_id, 'error': str(install_err)})
|
result.plugins_failed.append({'plugin_id': plugin_id, 'error': str(install_err)})
|
||||||
|
|
||||||
# Clear font catalog cache so restored fonts show up.
|
# Clear font catalog cache so restored fonts show up.
|
||||||
if 'fonts' in ' '.join(result.restored):
|
if any(r.startswith("fonts") for r in result.restored):
|
||||||
try:
|
try:
|
||||||
from web_interface.cache import delete_cached
|
from web_interface.cache import delete_cached
|
||||||
delete_cached('fonts_catalog')
|
delete_cached('fonts_catalog')
|
||||||
|
|||||||
Reference in New Issue
Block a user