Update public source

This commit is contained in:
2026-11-12 13:41:13 +03:00
parent 7e8d251210
commit b96a3dfe36
+88 -116
View File
@@ -4,8 +4,6 @@ import logging
import sqlite3
import csv
from vendor_import import VendorImporter
class EnvironmentChecker:
"""
Проверка окружения проекта.
@@ -63,12 +61,16 @@ class EnvironmentChecker:
self.check_hcxdumptool_version()
self.check_vendor_database()
vendor_database_ok = self.check_vendor_database()
if vendor_database_ok:
self.log.info(
"Environment OK"
)
else:
self.log.warning(
"Environment checks completed; vendor lookup unavailable"
)
@@ -174,141 +176,111 @@ class EnvironmentChecker:
database = self.config.vendor_database
rebuild = False
if not database.exists():
self.log.warning(
"Vendor database not found"
"Vendor database not found: %s",
database
)
rebuild = True
return False
elif database.stat().st_size == 0:
if database.stat().st_size == 0:
self.log.warning(
"Vendor database is empty"
"Vendor database is empty: %s",
database
)
rebuild = True
return False
else:
connection = None
try:
try:
connection = sqlite3.connect(
database
)
cursor = connection.cursor()
cursor.execute(
"SELECT name FROM sqlite_master "
"WHERE type='table' "
"AND name='oui'"
)
if cursor.fetchone() is None:
raise RuntimeError(
"vendors table not found"
)
cursor.execute(
"SELECT COUNT(*) FROM oui"
)
records = cursor.fetchone()[0]
if records < 50000:
raise RuntimeError(
f"Only {records} records"
)
cursor.execute(
"SELECT value "
"FROM metadata "
"WHERE key='import_status'"
)
row = cursor.fetchone()
if (
row is None
or
row[0] != "ok"
):
raise RuntimeError(
"Invalid import_status"
)
connection.close()
self.log.info(
f"Vendor database: OK ({records} records)"
)
return
except KeyboardInterrupt:
self.log.warning(
"Download cancelled by user"
)
raise
except Exception as error:
self.log.warning(
f"Vendor database is invalid: {error}"
)
rebuild = True
if rebuild:
database.unlink(
missing_ok=True
connection = sqlite3.connect(
f"{database.resolve().as_uri()}?mode=ro",
uri=True
)
self.log.info(
"Creating vendor database..."
cursor = connection.cursor()
cursor.execute(
"SELECT name FROM sqlite_master "
"WHERE type='table' "
"AND name='oui'"
)
importer = VendorImporter(
self.config
)
importer.bootstrap()
if not database.exists():
if cursor.fetchone() is None:
raise RuntimeError(
"oui table not found"
)
"Unable to create vendor database."
cursor.execute(
"SELECT COUNT(*) FROM oui"
)
records = cursor.fetchone()[0]
if records < 50000:
raise RuntimeError(
f"Only {records} records"
)
cursor.execute(
"SELECT name FROM sqlite_master "
"WHERE type='table' "
"AND name='metadata'"
)
if cursor.fetchone() is None:
raise RuntimeError(
"metadata table not found"
)
cursor.execute(
"SELECT value "
"FROM metadata "
"WHERE key='import_status'"
)
row = cursor.fetchone()
if row is None or row[0] != "ok":
raise RuntimeError(
"Invalid import_status"
)
self.log.info(
"Vendor database created"
"Vendor database: OK (%s records)",
records
)
return True
except sqlite3.Error as error:
self.log.warning(
"Vendor database is invalid: %s",
error
)
return False
except RuntimeError as error:
self.log.warning(
"Vendor database is invalid: %s",
error
)
return False
finally:
if connection is not None:
connection.close()