Update public source
This commit is contained in:
+57
-85
@@ -4,8 +4,6 @@ import logging
|
|||||||
import sqlite3
|
import sqlite3
|
||||||
import csv
|
import csv
|
||||||
|
|
||||||
from vendor_import import VendorImporter
|
|
||||||
|
|
||||||
class EnvironmentChecker:
|
class EnvironmentChecker:
|
||||||
"""
|
"""
|
||||||
Проверка окружения проекта.
|
Проверка окружения проекта.
|
||||||
@@ -63,12 +61,16 @@ class EnvironmentChecker:
|
|||||||
self.check_hcxdumptool_version()
|
self.check_hcxdumptool_version()
|
||||||
|
|
||||||
|
|
||||||
self.check_vendor_database()
|
vendor_database_ok = self.check_vendor_database()
|
||||||
|
|
||||||
|
|
||||||
|
if vendor_database_ok:
|
||||||
self.log.info(
|
self.log.info(
|
||||||
"Environment OK"
|
"Environment OK"
|
||||||
)
|
)
|
||||||
|
else:
|
||||||
|
self.log.warning(
|
||||||
|
"Environment checks completed; vendor lookup unavailable"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -174,30 +176,31 @@ class EnvironmentChecker:
|
|||||||
|
|
||||||
database = self.config.vendor_database
|
database = self.config.vendor_database
|
||||||
|
|
||||||
rebuild = False
|
|
||||||
|
|
||||||
if not database.exists():
|
if not database.exists():
|
||||||
|
|
||||||
self.log.warning(
|
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(
|
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(
|
connection = sqlite3.connect(
|
||||||
database
|
f"{database.resolve().as_uri()}?mode=ro",
|
||||||
|
uri=True
|
||||||
)
|
)
|
||||||
|
|
||||||
cursor = connection.cursor()
|
cursor = connection.cursor()
|
||||||
@@ -211,13 +214,11 @@ class EnvironmentChecker:
|
|||||||
if cursor.fetchone() is None:
|
if cursor.fetchone() is None:
|
||||||
|
|
||||||
raise RuntimeError(
|
raise RuntimeError(
|
||||||
"vendors table not found"
|
"oui table not found"
|
||||||
)
|
)
|
||||||
|
|
||||||
cursor.execute(
|
cursor.execute(
|
||||||
|
|
||||||
"SELECT COUNT(*) FROM oui"
|
"SELECT COUNT(*) FROM oui"
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
records = cursor.fetchone()[0]
|
records = cursor.fetchone()[0]
|
||||||
@@ -225,90 +226,61 @@ class EnvironmentChecker:
|
|||||||
if records < 50000:
|
if records < 50000:
|
||||||
|
|
||||||
raise RuntimeError(
|
raise RuntimeError(
|
||||||
|
|
||||||
f"Only {records} records"
|
f"Only {records} records"
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
cursor.execute(
|
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 "
|
"SELECT value "
|
||||||
"FROM metadata "
|
"FROM metadata "
|
||||||
"WHERE key='import_status'"
|
"WHERE key='import_status'"
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
row = cursor.fetchone()
|
row = cursor.fetchone()
|
||||||
|
|
||||||
if (
|
if row is None or row[0] != "ok":
|
||||||
|
|
||||||
row is None
|
|
||||||
|
|
||||||
or
|
|
||||||
|
|
||||||
row[0] != "ok"
|
|
||||||
|
|
||||||
):
|
|
||||||
|
|
||||||
raise RuntimeError(
|
raise RuntimeError(
|
||||||
|
|
||||||
"Invalid import_status"
|
"Invalid import_status"
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
self.log.info(
|
||||||
|
"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()
|
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
|
|
||||||
)
|
|
||||||
|
|
||||||
self.log.info(
|
|
||||||
"Creating vendor database..."
|
|
||||||
)
|
|
||||||
|
|
||||||
importer = VendorImporter(
|
|
||||||
self.config
|
|
||||||
)
|
|
||||||
|
|
||||||
importer.bootstrap()
|
|
||||||
|
|
||||||
if not database.exists():
|
|
||||||
|
|
||||||
raise RuntimeError(
|
|
||||||
|
|
||||||
"Unable to create vendor database."
|
|
||||||
|
|
||||||
)
|
|
||||||
|
|
||||||
self.log.info(
|
|
||||||
"Vendor database created"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user