Skip to content
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions requirements.d/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ coverage
flake8
macholib
nox
peewee
Comment thread
SAMAD101 marked this conversation as resolved.
Outdated
pkgconfig
pre-commit
pyinstaller
Expand Down
16 changes: 8 additions & 8 deletions src/vorta/store/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is proper use of type hints. Shouldn't it be the following instead?

Suggested change
last_backups_per_profile = Tuple(
last_backups_per_profile : Tuple =

@SAMAD101 SAMAD101 Apr 1, 2024

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

last_scheduled_backups_per_profile just a bit below (line 71) was assigned like that ( = Tuple(...)) so, I did it to last_backups_per_profile for consistency. I think it would be better to do it according to your suggestion or keep both like:

last_backups_per_profile: Tuple = 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)
Comment thread
SAMAD101 marked this conversation as resolved.
Outdated
entry = Tuple(EventLogModel.profile, EventLogModel.start_time)
EventLogModel.delete().where(
EventLogModel.start_time < three_months_ago,
Expand Down Expand Up @@ -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')
Comment thread
SAMAD101 marked this conversation as resolved.
Outdated
backup_file_name = f'settings_v{schema_version}_{timestamp}.db'
shutil.copy(config.SETTINGS_DIR / 'settings.db', config.SETTINGS_DIR / backup_file_name)
2 changes: 1 addition & 1 deletion src/vorta/store/migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 10 additions & 9 deletions src/vorta/store/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Comment thread
SAMAD101 marked this conversation as resolved.
Outdated
"""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)

Expand All @@ -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:
Expand Down Expand Up @@ -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 (
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)