Update public source
This commit is contained in:
+57
-85
@@ -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,30 +176,31 @@ 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:
|
||||
|
||||
connection = sqlite3.connect(
|
||||
database
|
||||
f"{database.resolve().as_uri()}?mode=ro",
|
||||
uri=True
|
||||
)
|
||||
|
||||
cursor = connection.cursor()
|
||||
@@ -211,13 +214,11 @@ class EnvironmentChecker:
|
||||
if cursor.fetchone() is None:
|
||||
|
||||
raise RuntimeError(
|
||||
"vendors table not found"
|
||||
"oui table not found"
|
||||
)
|
||||
|
||||
cursor.execute(
|
||||
|
||||
"SELECT COUNT(*) FROM oui"
|
||||
|
||||
)
|
||||
|
||||
records = cursor.fetchone()[0]
|
||||
@@ -225,90 +226,61 @@ class EnvironmentChecker:
|
||||
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"
|
||||
|
||||
):
|
||||
if row is None or row[0] != "ok":
|
||||
|
||||
raise RuntimeError(
|
||||
|
||||
"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()
|
||||
|
||||
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