New logic for local sigid search

This commit is contained in:
Marco Dalla Tiezza
2024-06-15 00:40:00 +02:00
parent ebda950c87
commit d0bfbe40d7
7 changed files with 49 additions and 35 deletions

View File

@@ -8,15 +8,19 @@
### Added
- Possibility to navigate Artemis just with the keyboard [#50](https://github.com/AresValley/Artemis/issues/50)
- **Windows:** automatic updates have been implemented. When a software update is available, Artemis will download the new version and install the updates automatically
- Multiple sigID databases can be conserved. In the case of autoload, the latest local version will be loaded
### Changed
- Improved readability of labels for filter ranges for frequency, bandwidth, and ACF
- Improved Update manager and Downloader functionalities
- OS dependent temporary folders are now used for database download and artemis updates
- The logic for searching the last sigID database has changed, now the discriminant is no longer the folder name but is reported as a signature in the database itself (-1 in the editable field, see documentation)
- Old sigID databases are not deleted anymore when a new version is downloaded. This is to avoid removing databases with user changes or additions
### Fixed
- Added a database load check to avoid (non critical) exceptions when applying filters without having loaded a database.
- Fixed a potential issue involing the forcibly closure of downloader window but the downloader instance keeps running
- With the new logic in the latest sigID database search, manually imported sigID databases are officially recognized as proper ones
## [4.0.3] - 2024-06-10

View File

@@ -345,10 +345,13 @@ class UIArtemis(QObject):
def autoload_db(self):
sig_id_path = DATA_DIR / 'SigID' / Constants.SQL_NAME
""" This will autoload the latest local sigID DB, if present
according to the user settings
"""
sig_id_db = self.dbmanager.get_latest_local_sigid_db()
autoload = CONFIGURE_QT.value("Database", "autoload", 0)
if sig_id_path.exists() and int(autoload):
self.load_db('SigID')
if sig_id_db is not None and int(autoload):
self.load_db(sig_id_db.db_dir_name)
def dialog_popup(self, message_type, title, message):

View File

@@ -49,8 +49,22 @@ class UIdbmanager(QObject):
def load_local_db_list(self):
""" Scan for all the valid DBs in the data folder and show them on the list
"""
db_param = []
valid_db_list = self.scan_db_dir()
self.populate_db_list.emit(valid_db_list)
for db in valid_db_list:
db_param.append(
{
'name': db.name,
'db_dir_name': db.db_dir_name,
'documents_n': db.stats['documents'],
'signals_n': db.stats['signals'],
'images_n': db.stats['images'],
'audio_n': db.stats['audio']
}
)
self.populate_db_list.emit(db_param)
def load_db(self, db_dir_name):
@@ -85,7 +99,7 @@ class UIdbmanager(QObject):
def scan_db_dir(self):
""" Scans the data directory for valid databases and
return a dictionary containing only the valid ones with a summary
return a dictionary containing only the (already loaded) valid ones
"""
valid_db_list = []
db_dirs = next(os.walk(DATA_DIR))[1]
@@ -94,20 +108,25 @@ class UIdbmanager(QObject):
if self._valid_db(db_dir_name):
database = ArtemisDatabase(db_dir_name)
database.load()
valid_db_list.append(
{
'name': database.name,
'db_dir_name': database.db_dir_name,
'documents_n': database.stats['documents'],
'signals_n': database.stats['signals'],
'images_n': database.stats['images'],
'audio_n': database.stats['audio']
}
)
valid_db_list.append(database)
return valid_db_list
def get_latest_local_sigid_db(self):
""" Return the newest valid local sigID database.
Returns None if no valid sigID database is found.
"""
valid_dbs = self._parent.dbmanager.scan_db_dir()
sig_id_dbs = [db for db in valid_dbs if db.editable == -1]
if len(sig_id_dbs) != 0:
sig_id_latest = max(sig_id_dbs, key=lambda x: x.version)
return sig_id_latest
else:
return None
def _valid_db(self, db_dir_name):
""" Checks if db_dir_name is a valid db dir containing a `data.sqlite` file.
Db must be valid as well and should be properly initialized and loaded with

View File

@@ -141,7 +141,7 @@ class ArtemisDatabase(Database):
""" Create new db in the data folder.
The name of folder containing the new db has a unique id as name (db_dir_name).
"""
meta = [name, datetime.now(), 0, 0]
meta = [name, datetime.now(), 1, 1]
os.makedirs(self.db_dir)
os.makedirs(self.media_dir)

View File

@@ -1,4 +1,5 @@
import os
import uuid
import requests
from packaging.version import Version
@@ -15,7 +16,6 @@ class UpdateManager:
def __init__(self, parent):
self._parent = parent
self.sigid_db_path = DATA_DIR / 'SigID' / Constants.SQL_NAME
self.db_update = None
self.art_update = None
@@ -45,7 +45,7 @@ class UpdateManager:
"""
latest_json = self.fetch_remote_json(Constants.LATEST_VERSION_URL, show_popup)
if latest_json:
local_db = self._load_local_db()
local_db = self._parent.dbmanager.get_latest_local_sigid_db()
remote_db = latest_json['sigID_DB']
self.remote_db_version = remote_db['version']
@@ -104,16 +104,6 @@ class UpdateManager:
return None
def _load_local_db(self):
""" Loads the local database if exists
"""
if os.path.exists(self.sigid_db_path):
local_db = ArtemisDatabase('SigID')
local_db.load()
return local_db
return None
def download_db(self):
""" Open the downloader and download the sigID database in the
TMP_DIR folder. After a succesfull download the callback function
@@ -133,9 +123,9 @@ class UpdateManager:
"""
latest_db_tar_path = TMP_DIR / self.remote_db_file_name
if match_hash(latest_db_tar_path, self.remote_db_hash):
delete_dir(DATA_DIR / 'SigID')
unpack_tar(latest_db_tar_path, DATA_DIR / 'SigID')
self._parent.load_db('SigID')
db_dir_name = str(uuid.uuid4())
unpack_tar(latest_db_tar_path, DATA_DIR / db_dir_name)
self._parent.load_db(db_dir_name)
self._show_popup_db_download_complete()
else:
self._show_popup_db_hash_failed()

View File

@@ -2,7 +2,7 @@
"sigID_DB": {
"version": 61,
"url": "https://github.com/AresValley/Artemis-DB/releases/download/v61/v61.tar",
"sha256_hash": "c65d2ab65e9420cd7789190c100abef2f1575ea15489776c2d97b5b09cdc8410",
"sha256_hash": "da4d0f56924940f90b86349bf7a22a478bcf08e969d8de2bcb34e2939e74c885",
"total_bytes": 244449280
},
"windows": {

View File

@@ -21,8 +21,6 @@ A simple integer to denote the database version.
This field should serve as a writing protection on the database.
* **-1**: reserved to sigID database. This is the primary way to distinguish a valid sigID database
* **0**: read-only database
* **1**: database can be edited with no restrictions
!!! example "Experimental"
This feature is experimental and not yet implemented.