From 6abd0f5862140273c6c1a23c33c288f13529f924 Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 1 Sep 2023 23:13:17 +0530 Subject: [PATCH 01/10] added peewee to requirements.d/dev.txt --- requirements.d/dev.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.d/dev.txt b/requirements.d/dev.txt index 5391c54a0..9cc3cc9c8 100644 --- a/requirements.d/dev.txt +++ b/requirements.d/dev.txt @@ -3,6 +3,7 @@ coverage flake8 macholib nox +peewee pkgconfig pre-commit pyinstaller From 7b800661c2e6822c4c259afefe3fd27fb6bf26ed Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 6 Sep 2023 11:57:06 +0530 Subject: [PATCH 02/10] removed peewee from requirements: not necessary --- requirements.d/dev.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/requirements.d/dev.txt b/requirements.d/dev.txt index 9cc3cc9c8..5391c54a0 100644 --- a/requirements.d/dev.txt +++ b/requirements.d/dev.txt @@ -3,7 +3,6 @@ coverage flake8 macholib nox -peewee pkgconfig pre-commit pyinstaller From 77f5c33b5af539a65ca1bae5da1da79061c5d958 Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 13 Dec 2023 14:45:27 +0530 Subject: [PATCH 03/10] add peewee --- requirements.d/dev.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.d/dev.txt b/requirements.d/dev.txt index 5391c54a0..9cc3cc9c8 100644 --- a/requirements.d/dev.txt +++ b/requirements.d/dev.txt @@ -3,6 +3,7 @@ coverage flake8 macholib nox +peewee pkgconfig pre-commit pyinstaller From f0f33c7e0ea5cee75c8f4798ca7a253daa7763f8 Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 22 Dec 2023 02:20:09 +0530 Subject: [PATCH 04/10] made store/ typesafe --- src/vorta/store/connection.py | 16 ++++++++-------- src/vorta/store/migrations.py | 2 +- src/vorta/store/models.py | 19 ++++++++++--------- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/vorta/store/connection.py b/src/vorta/store/connection.py index e02efe96b..902403ada 100644 --- a/src/vorta/store/connection.py +++ b/src/vorta/store/connection.py @@ -28,18 +28,18 @@ @signals.post_save(sender=SettingsModel) -def setup_autostart(model_class, instance, created): +def setup_autostart(model_class, instance, created) -> None: if instance.key == 'autostart': open_app_at_startup(instance.value) -def cleanup_db(): +def cleanup_db() -> None: # Clean up database DB.execute_sql("VACUUM") DB.close() -def init_db(con=None): +def init_db(con=None) -> None: if con is not None: os.umask(0o0077) DB.initialize(con) @@ -62,18 +62,18 @@ def init_db(con=None): # Delete old log entries after 6 months. # The last `create` command of each profile must not be deleted # since the scheduler uses it to determine the last backup time. - last_backups_per_profile = ( + last_backups_per_profile = Tuple( EventLogModel.select(EventLogModel.profile, fn.MAX(EventLogModel.start_time)) .where(EventLogModel.subcommand == 'create') .group_by(EventLogModel.profile) ) - last_scheduled_backups_per_profile = ( + last_scheduled_backups_per_profile = Tuple( EventLogModel.select(EventLogModel.profile, fn.MAX(EventLogModel.start_time)) .where(EventLogModel.subcommand == 'create', EventLogModel.category == 'scheduled') .group_by(EventLogModel.profile) ) - three_months_ago = datetime.now() - timedelta(days=6 * 30) + three_months_ago: datetime = datetime.now() - timedelta(days=6 * 30) entry = Tuple(EventLogModel.profile, EventLogModel.start_time) EventLogModel.delete().where( EventLogModel.start_time < three_months_ago, @@ -105,11 +105,11 @@ def init_db(con=None): s.save() -def backup_current_db(schema_version): +def backup_current_db(schema_version) -> None: """ Creates a backup copy of settings.db """ - timestamp = datetime.now().strftime('%Y-%m-%d-%H%M%S') + timestamp: str = datetime.now().strftime('%Y-%m-%d-%H%M%S') backup_file_name = f'settings_v{schema_version}_{timestamp}.db' shutil.copy(config.SETTINGS_DIR / 'settings.db', config.SETTINGS_DIR / backup_file_name) diff --git a/src/vorta/store/migrations.py b/src/vorta/store/migrations.py index a26892597..6f6874b73 100644 --- a/src/vorta/store/migrations.py +++ b/src/vorta/store/migrations.py @@ -251,7 +251,7 @@ def run_migrations(current_schema, db_connection): ) -def _apply_schema_update(current_schema, version_after, *operations): +def _apply_schema_update(current_schema, version_after, *operations) -> None: with DB.atomic(): migrate(*operations) current_schema.version = version_after diff --git a/src/vorta/store/models.py b/src/vorta/store/models.py index 400299fb2..7aecb2a35 100644 --- a/src/vorta/store/models.py +++ b/src/vorta/store/models.py @@ -8,6 +8,7 @@ import logging from datetime import datetime from enum import Enum +from typing import Any, Dict import peewee as pw from playhouse import signals @@ -26,11 +27,11 @@ class JSONField(pw.TextField): From: https://gist.github.com/rosscdh/f4f26758b0228f475b132c688f15af2b """ - def db_value(self, value): + def db_value(self, value) -> (None or str): """Convert the python value for storage in the database.""" return value if value is None else json.dumps(value) - def python_value(self, value): + def python_value(self, value) -> (None or str): """Convert the database value to a pythonic value.""" return value if value is None else json.loads(value) @@ -53,7 +54,7 @@ class RepoModel(BaseModel): create_backup_cmd = pw.CharField(default='') extra_borg_arguments = pw.CharField(default='') - def is_remote_repo(self): + def is_remote_repo(self) -> bool: return not self.url.startswith('/') class Meta: @@ -103,14 +104,14 @@ class BackupProfileModel(BaseModel): post_backup_cmd = pw.CharField(default='') dont_run_on_metered_networks = pw.BooleanField(default=True) - def refresh(self): + def refresh(self) -> None: return type(self).get(self._pk_expr()) - def slug(self): + def slug(self) -> str: return slugify(self.name) - def get_combined_exclusion_string(self): - allPresets = get_exclusion_presets() + def get_combined_exclusion_string(self) -> str: + allPresets: Dict[str, Dict[str, Any]] = get_exclusion_presets() excludes = "" if ( @@ -202,7 +203,7 @@ class ArchiveModel(BaseModel): size = pw.IntegerField(null=True) trigger = pw.CharField(null=True) - def formatted_time(self): + def formatted_time(self) -> None: return class Meta: @@ -266,5 +267,5 @@ class Meta: class BackupProfileMixin: """Extend to support multiple profiles later.""" - def profile(self): + def profile(self) -> BackupProfileModel: return BackupProfileModel.get(id=self.window().current_profile.id) From 5f5b4e373953a74d7c472934c2cc2d7a6645d02e Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 22 Dec 2023 02:20:09 +0530 Subject: [PATCH 05/10] made store/ typesafe --- src/vorta/store/models.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/vorta/store/models.py b/src/vorta/store/models.py index 7aecb2a35..099e8f933 100644 --- a/src/vorta/store/models.py +++ b/src/vorta/store/models.py @@ -8,7 +8,11 @@ import logging from datetime import datetime from enum import Enum +<<<<<<< HEAD from typing import Any, Dict +======= +from typing import Any, Dict, Optional +>>>>>>> 194ab15 (made store/ typesafe) import peewee as pw from playhouse import signals @@ -27,11 +31,19 @@ class JSONField(pw.TextField): From: https://gist.github.com/rosscdh/f4f26758b0228f475b132c688f15af2b """ +<<<<<<< HEAD def db_value(self, value) -> (None or str): """Convert the python value for storage in the database.""" return value if value is None else json.dumps(value) def python_value(self, value) -> (None or str): +======= + def db_value(self, value) -> Optional[str]: + """Convert the python value for storage in the database.""" + return value if value is None else json.dumps(value) + + def python_value(self, value) -> Optional[str]: +>>>>>>> 194ab15 (made store/ typesafe) """Convert the database value to a pythonic value.""" return value if value is None else json.loads(value) From 0c3829ce736be20a6a9a3009883d234fc02e1e4b Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 25 Dec 2023 15:24:20 +0530 Subject: [PATCH 06/10] conflict resolved --- src/vorta/store/models.py | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/vorta/store/models.py b/src/vorta/store/models.py index 099e8f933..d195f938d 100644 --- a/src/vorta/store/models.py +++ b/src/vorta/store/models.py @@ -8,11 +8,7 @@ import logging from datetime import datetime from enum import Enum -<<<<<<< HEAD -from typing import Any, Dict -======= from typing import Any, Dict, Optional ->>>>>>> 194ab15 (made store/ typesafe) import peewee as pw from playhouse import signals @@ -31,19 +27,11 @@ class JSONField(pw.TextField): From: https://gist.github.com/rosscdh/f4f26758b0228f475b132c688f15af2b """ -<<<<<<< HEAD - def db_value(self, value) -> (None or str): - """Convert the python value for storage in the database.""" - return value if value is None else json.dumps(value) - - def python_value(self, value) -> (None or str): -======= def db_value(self, value) -> Optional[str]: """Convert the python value for storage in the database.""" return value if value is None else json.dumps(value) def python_value(self, value) -> Optional[str]: ->>>>>>> 194ab15 (made store/ typesafe) """Convert the database value to a pythonic value.""" return value if value is None else json.loads(value) From eee0b42defe773059f8c20e10172e982d8cd939d Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 25 Dec 2023 15:24:20 +0530 Subject: [PATCH 07/10] conflict resolved --- requirements.d/dev.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/requirements.d/dev.txt b/requirements.d/dev.txt index 9cc3cc9c8..5391c54a0 100644 --- a/requirements.d/dev.txt +++ b/requirements.d/dev.txt @@ -3,7 +3,6 @@ coverage flake8 macholib nox -peewee pkgconfig pre-commit pyinstaller From 65fa36b69a66a597cfbebb76b50dbfb2edc488df Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 27 Dec 2023 12:55:34 +0530 Subject: [PATCH 08/10] minor refactor in src/vorta/store/connection.py --- src/vorta/store/connection.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/vorta/store/connection.py b/src/vorta/store/connection.py index 902403ada..66ed74d82 100644 --- a/src/vorta/store/connection.py +++ b/src/vorta/store/connection.py @@ -73,7 +73,7 @@ def init_db(con=None) -> None: .group_by(EventLogModel.profile) ) - three_months_ago: datetime = datetime.now() - timedelta(days=6 * 30) + three_months_ago = datetime.now() - timedelta(days=6 * 30) entry = Tuple(EventLogModel.profile, EventLogModel.start_time) EventLogModel.delete().where( EventLogModel.start_time < three_months_ago, @@ -110,6 +110,6 @@ def backup_current_db(schema_version) -> None: Creates a backup copy of settings.db """ - timestamp: str = datetime.now().strftime('%Y-%m-%d-%H%M%S') + timestamp = datetime.now().strftime('%Y-%m-%d-%H%M%S') backup_file_name = f'settings_v{schema_version}_{timestamp}.db' shutil.copy(config.SETTINGS_DIR / 'settings.db', config.SETTINGS_DIR / backup_file_name) From 73e7d966b0b78c7f827224568596a02465b201e1 Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 23 Feb 2024 15:10:18 +0530 Subject: [PATCH 09/10] chore: minor refactor --- src/vorta/store/connection.py | 7 ++++--- src/vorta/store/migrations.py | 6 ++++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/vorta/store/connection.py b/src/vorta/store/connection.py index 66ed74d82..a9daa11ca 100644 --- a/src/vorta/store/connection.py +++ b/src/vorta/store/connection.py @@ -1,8 +1,9 @@ import os import shutil from datetime import datetime, timedelta +from typing import Any, Optional -from peewee import Tuple, fn +from peewee import SqliteDatabase, Tuple, fn from playhouse import signals from vorta import config @@ -39,7 +40,7 @@ def cleanup_db() -> None: DB.close() -def init_db(con=None) -> None: +def init_db(con: Optional[SqliteDatabase] = None) -> None: if con is not None: os.umask(0o0077) DB.initialize(con) @@ -105,7 +106,7 @@ def init_db(con=None) -> None: s.save() -def backup_current_db(schema_version) -> None: +def backup_current_db(schema_version: Any) -> None: """ Creates a backup copy of settings.db """ diff --git a/src/vorta/store/migrations.py b/src/vorta/store/migrations.py index 6f6874b73..746add22c 100644 --- a/src/vorta/store/migrations.py +++ b/src/vorta/store/migrations.py @@ -1,6 +1,8 @@ from datetime import datetime +from typing import Any import peewee as pw +from peewee import SqliteDatabase from playhouse.migrate import SqliteMigrator, migrate from .models import ( @@ -15,7 +17,7 @@ ) -def run_migrations(current_schema, db_connection): +def run_migrations(current_schema: Any, db_connection: SqliteDatabase): """ Apply new schema versions to database. @@ -251,7 +253,7 @@ def run_migrations(current_schema, db_connection): ) -def _apply_schema_update(current_schema, version_after, *operations) -> None: +def _apply_schema_update(current_schema: Any, version_after: int, *operations) -> None: with DB.atomic(): migrate(*operations) current_schema.version = version_after From 59803e6f18e161667d7d5867a14cb23c435e2126 Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 1 Apr 2024 23:10:58 +0530 Subject: [PATCH 10/10] chore: minor refactor --- src/vorta/store/migrations.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/vorta/store/migrations.py b/src/vorta/store/migrations.py index 746add22c..54345eb84 100644 --- a/src/vorta/store/migrations.py +++ b/src/vorta/store/migrations.py @@ -11,13 +11,14 @@ BackupProfileModel, EventLogModel, RepoModel, + SchemaVersion, SettingsModel, SourceFileModel, WifiSettingModel, ) -def run_migrations(current_schema: Any, db_connection: SqliteDatabase): +def run_migrations(current_schema: SchemaVersion, db_connection: SqliteDatabase): """ Apply new schema versions to database.