Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new placeholder keys #1956

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
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
16 changes: 15 additions & 1 deletion src/vorta/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import os
import re
import socket
import subprocess
import sys
import unicodedata
from datetime import datetime as dt
Expand Down Expand Up @@ -416,14 +417,27 @@ def format_archive_name(profile, archive_name_tpl):
"""
hostname = socket.gethostname()
hostname = hostname.split(".")[0]
fqdn = _getfqdn(hostname)
borg_version = os.getenv("BORG_VERSION")
if not borg_version:
borg_version = subprocess.run(['borg', '--version'], stdout=subprocess.PIPE).stdout.decode('utf-8')
Copy link
Contributor

Choose a reason for hiding this comment

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

You are basically sidestepping everything we do to correctly detect the right borg binary. So while this may work in many cases, it will break in others. So as already mentioned before, it will be better to use the existing borg_compat module.

borg_version = borg_version.split(' ')[1]
borg_version_tuple = tuple(borg_version.split("."))
Comment on lines +420 to +425
Copy link
Collaborator

Choose a reason for hiding this comment

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

Vorta already queries borg version information on startup. Why not use that?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Vorta already queries borg version information on startup. Why not use that?

I get circular import error when importing borg_compat in utils.py:
ImportError: cannot import name 'borg_compat' from partially initialized module 'vorta.utils' (most likely due to a circular import). This is probably why borg version is being queried again here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, be aware of circular imports. Helper functions and modules should only be used by higher level. So maybe format_archive_name() should be moved elsewhere, since it uses helper functions now.

available_vars = {
'hostname': hostname,
'fqdn': _getfqdn(hostname),
'fqdn': fqdn,
'reverse-fqdn': ".".join(reversed(fqdn.split("."))),
'profile_id': profile.id,
'profile_slug': profile.slug(),
'now': dt.now(),
'utc_now': dt.utcnow(),
'utcnow': dt.utcnow(),
'user': getpass.getuser(),
'pid': os.getpid(),
'borgversion': borg_version,
'borgmajor': "%s" % borg_version_tuple[:1],
'borgminor': "%s.%s" % borg_version_tuple[:2],
'borgpatch': "%s.%s.%s" % borg_version_tuple[:3],
}
return archive_name_tpl.format(**available_vars)

Expand Down
Loading