Read-only ops are separated in different standard and OS dependent folders from read-write ones (fixed #43), bump Nuitka 2.3
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
from configparser import ConfigParser
|
||||
from artemis.utils.constants import Constants
|
||||
|
||||
from artemis.utils.path_utils import PREFERENCES_DIR, BASE_DIR
|
||||
from artemis.utils.sys_utils import copy_file
|
||||
|
||||
|
||||
class Config(ConfigParser):
|
||||
@@ -29,4 +31,11 @@ class Config(ConfigParser):
|
||||
with open(self._config_file_path, 'w') as f:
|
||||
self.write(f, space_around_delimiters=self._space_around_delimiters)
|
||||
|
||||
CONFIGURE_QT = Config((Constants.PREFERENCES_DIR / 'qtquickcontrols2.conf').resolve().as_posix())
|
||||
|
||||
if not (PREFERENCES_DIR / 'qtquickcontrols2.conf').exists():
|
||||
copy_file(
|
||||
BASE_DIR / 'config' / 'qtquickcontrols2.conf',
|
||||
PREFERENCES_DIR / 'qtquickcontrols2.conf'
|
||||
)
|
||||
|
||||
CONFIGURE_QT = Config((PREFERENCES_DIR / 'qtquickcontrols2.conf').resolve().as_posix())
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import os
|
||||
import locale
|
||||
import sys
|
||||
|
||||
from PySide6.QtCore import qVersion
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
class Constants():
|
||||
@@ -14,13 +12,6 @@ class Constants():
|
||||
ORGANIZATION_DOMAIN = 'aresvalley.com'
|
||||
APPLICATION_VERSION = '4.0.0'
|
||||
|
||||
BASE_DIR = Path(os.path.dirname(__file__)) / '../..'
|
||||
PREFERENCES_DIR = BASE_DIR / 'config'
|
||||
DB_DIR = BASE_DIR / 'data'
|
||||
UI_DIR = BASE_DIR / 'ui'
|
||||
IMAGES_DIR = BASE_DIR / 'images'
|
||||
LOGS_DIR = BASE_DIR / 'logs'
|
||||
|
||||
SQL_NAME = 'data.sqlite'
|
||||
|
||||
LATEST_VERSION_URL = 'https://raw.githubusercontent.com/AresValley/Artemis/master/config/release-info.json'
|
||||
|
||||
@@ -6,6 +6,7 @@ from packaging.version import Version
|
||||
from artemis.utils.constants import Constants, Messages
|
||||
from artemis.utils.sql_utils import ArtemisDatabase
|
||||
from artemis.utils.sys_utils import is_windows, is_linux, is_macos
|
||||
from artemis.utils.path_utils import DATA_DIR
|
||||
|
||||
|
||||
class NetworkManager:
|
||||
@@ -14,7 +15,7 @@ class NetworkManager:
|
||||
|
||||
def __init__(self, parent):
|
||||
self._parent = parent
|
||||
self.sigid_db_path = Constants.DB_DIR / 'sigID' / Constants.SQL_NAME
|
||||
self.sigid_db_path = DATA_DIR / 'SigID' / Constants.SQL_NAME
|
||||
|
||||
self.show_popup = False
|
||||
self.db_update = None
|
||||
@@ -92,7 +93,7 @@ class NetworkManager:
|
||||
""" Loads the local database if exists
|
||||
"""
|
||||
if os.path.exists(self.sigid_db_path):
|
||||
local_db = ArtemisDatabase('sigID')
|
||||
local_db = ArtemisDatabase('SigID')
|
||||
local_db.load()
|
||||
return local_db
|
||||
return None
|
||||
|
||||
@@ -1,14 +1,8 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
from artemis.utils.sql_utils import ArtemisDatabase
|
||||
from artemis.utils.constants import Constants
|
||||
from artemis.utils.sys_utils import *
|
||||
|
||||
|
||||
def check_data_dir():
|
||||
if not os.path.exists(Constants.DB_DIR):
|
||||
os.makedirs(Constants.DB_DIR)
|
||||
from artemis.utils.sys_utils import is_windows, is_linux, is_macos
|
||||
|
||||
|
||||
def normalize_dialog_path(path):
|
||||
@@ -19,38 +13,37 @@ def normalize_dialog_path(path):
|
||||
return norm_path
|
||||
|
||||
|
||||
def logs_dir():
|
||||
def _app_dir():
|
||||
if is_macos():
|
||||
logs_dir_path = Path.home() / 'Library/Logs/' / Constants.ORGANIZATION_NAME / Constants.APPLICATION_NAME
|
||||
app_dir_path = Path.home() / 'Library' / 'Application Support' / Constants.ORGANIZATION_NAME / Constants.APPLICATION_NAME
|
||||
elif is_windows():
|
||||
logs_dir_path = Path.home() / 'AppData/Local/' / Constants.ORGANIZATION_NAME / Constants.APPLICATION_NAME / 'logs'
|
||||
app_dir_path = Path.home() / 'AppData' / 'Local' / Constants.ORGANIZATION_NAME / Constants.APPLICATION_NAME
|
||||
elif is_linux():
|
||||
logs_dir_path = Path.home() / '/var/log/' / Constants.ORGANIZATION_NAME / Constants.APPLICATION_NAME
|
||||
app_dir_path = Path.home() / '.local' / 'share' / Constants.ORGANIZATION_NAME / Constants.APPLICATION_NAME
|
||||
else:
|
||||
logs_dir_path = Constants.LOGS_DIR
|
||||
app_dir_path = BASE_DIR
|
||||
|
||||
if not logs_dir_path.exists():
|
||||
logs_dir_path.mkdir(parents=True)
|
||||
if not app_dir_path.exists():
|
||||
app_dir_path.mkdir(parents=True)
|
||||
|
||||
return logs_dir_path
|
||||
return app_dir_path
|
||||
|
||||
|
||||
def valid_db(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
|
||||
no errors.
|
||||
def _data_dir():
|
||||
data_dir_path = APP_DIR / 'data'
|
||||
if not data_dir_path.exists():
|
||||
data_dir_path.mkdir(parents=True)
|
||||
return data_dir_path
|
||||
|
||||
Args:
|
||||
db_dir_name (str): name of the db folder
|
||||
"""
|
||||
if os.path.exists(Constants.DB_DIR / db_dir_name / Constants.SQL_NAME):
|
||||
try:
|
||||
database = ArtemisDatabase(db_dir_name)
|
||||
database.load()
|
||||
return True
|
||||
except Exception as e:
|
||||
# Invalid or corrupted DB
|
||||
return False
|
||||
else:
|
||||
# The dir is not containing a data.sqlite file
|
||||
return False
|
||||
|
||||
def _preference_dir():
|
||||
preference_dir_path = APP_DIR / 'config'
|
||||
if not preference_dir_path.exists():
|
||||
preference_dir_path.mkdir(parents=True)
|
||||
return preference_dir_path
|
||||
|
||||
|
||||
BASE_DIR = Path(os.path.dirname(__file__)) / '../..'
|
||||
APP_DIR = _app_dir()
|
||||
DATA_DIR = _data_dir()
|
||||
PREFERENCES_DIR = _preference_dir()
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
import sqlite3
|
||||
import os
|
||||
import sqlite3
|
||||
|
||||
from PySide6.QtCore import QUrl
|
||||
from operator import itemgetter
|
||||
from datetime import datetime
|
||||
from contextlib import closing
|
||||
|
||||
from artemis.utils.constants import Query, Constants
|
||||
from artemis.utils.generic_utils import *
|
||||
from contextlib import closing
|
||||
from artemis.utils.path_utils import DATA_DIR
|
||||
from artemis.utils.generic_utils import format_frequency
|
||||
|
||||
|
||||
class Database():
|
||||
@@ -51,7 +52,7 @@ class ArtemisDatabase(Database):
|
||||
|
||||
def __init__(self, db_dir_name):
|
||||
self.db_dir_name = db_dir_name
|
||||
self.db_dir = Constants.DB_DIR / db_dir_name
|
||||
self.db_dir = DATA_DIR / db_dir_name
|
||||
self.sql_path = self.db_dir / Constants.SQL_NAME
|
||||
self.media_dir = self.db_dir / 'media'
|
||||
super().__init__(self.sql_path)
|
||||
|
||||
@@ -6,7 +6,7 @@ import hashlib
|
||||
from shutil import rmtree, copyfile, make_archive, unpack_archive
|
||||
from pathlib import Path
|
||||
|
||||
from artemis.utils.constants import Constants, Messages
|
||||
from artemis.utils.constants import Messages
|
||||
|
||||
|
||||
def is_windows():
|
||||
@@ -46,29 +46,38 @@ def open_directory(directory, timeout=3):
|
||||
return
|
||||
|
||||
|
||||
def delete_db_dir(db_dir_name):
|
||||
"""Delete the db folder"""
|
||||
db_dir = Constants.DB_DIR / db_dir_name
|
||||
if os.path.exists(db_dir):
|
||||
rmtree(db_dir)
|
||||
|
||||
|
||||
def copy_file(src_file_path, dst_file_path):
|
||||
copyfile(src_file_path, dst_file_path)
|
||||
|
||||
|
||||
def delete_dir(dir_path):
|
||||
if os.path.exists(dir_path):
|
||||
rmtree(dir_path)
|
||||
|
||||
|
||||
def delete_file(file_path):
|
||||
if os.path.exists(file_path):
|
||||
os.remove(file_path)
|
||||
|
||||
|
||||
def pack_db(save_path, db_dir):
|
||||
make_archive(save_path, 'tar', db_dir.resolve().as_posix())
|
||||
def make_tar(save_path, origin_path):
|
||||
""" Create a tar archive from a folder
|
||||
|
||||
Args:
|
||||
save_path: destination path where new tar is saved
|
||||
origin_path: directory path of the folder to be archived
|
||||
"""
|
||||
make_archive(save_path, 'tar', origin_path.resolve().as_posix())
|
||||
|
||||
|
||||
def unpack_db(tar_path, db_dir_name):
|
||||
db_dir = Constants.DB_DIR / db_dir_name
|
||||
unpack_archive(tar_path, db_dir, 'tar')
|
||||
def unpack_tar(tar_path, destination_path):
|
||||
""" Unpack a tar archive in a folder
|
||||
|
||||
Args:
|
||||
tar_path: path of the tar to be unpacked
|
||||
destination_path: path where the tar is extracted
|
||||
"""
|
||||
unpack_archive(tar_path, destination_path, 'tar')
|
||||
|
||||
|
||||
def match_hash(data, reference_hash):
|
||||
|
||||
Reference in New Issue
Block a user