mirror of https://github.com/borgbackup/borg.git
Change {utcnow} and {now} to ISO-8601 format
This commit is contained in:
parent
765b8f38d6
commit
a56dc44e1f
|
@ -1233,11 +1233,13 @@ class Archiver:
|
||||||
|
|
||||||
{now}
|
{now}
|
||||||
|
|
||||||
The current local date and time.
|
The current local date and time, by default in ISO-8601 format.
|
||||||
|
You can also supply your own `format string <https://docs.python.org/3.4/library/datetime.html#strftime-and-strptime-behavior>`_, e.g. {now:%Y-%m-%d_%H:%M:%S}
|
||||||
|
|
||||||
{utcnow}
|
{utcnow}
|
||||||
|
|
||||||
The current UTC date and time.
|
The current UTC date and time, by default in ISO-8601 format.
|
||||||
|
You can also supply your own `format string <https://docs.python.org/3.4/library/datetime.html#strftime-and-strptime-behavior>`_, e.g. {utcnow:%Y-%m-%d_%H:%M:%S}
|
||||||
|
|
||||||
{user}
|
{user}
|
||||||
|
|
||||||
|
|
|
@ -622,6 +622,16 @@ def partial_format(format, mapping):
|
||||||
return format
|
return format
|
||||||
|
|
||||||
|
|
||||||
|
class DatetimeWrapper:
|
||||||
|
def __init__(self, dt):
|
||||||
|
self.dt = dt
|
||||||
|
|
||||||
|
def __format__(self, format_spec):
|
||||||
|
if format_spec == '':
|
||||||
|
format_spec = '%Y-%m-%dT%H:%M:%S'
|
||||||
|
return self.dt.__format__(format_spec)
|
||||||
|
|
||||||
|
|
||||||
def format_line(format, data):
|
def format_line(format, data):
|
||||||
try:
|
try:
|
||||||
return format.format(**data)
|
return format.format(**data)
|
||||||
|
@ -636,8 +646,8 @@ def replace_placeholders(text):
|
||||||
'pid': os.getpid(),
|
'pid': os.getpid(),
|
||||||
'fqdn': socket.getfqdn(),
|
'fqdn': socket.getfqdn(),
|
||||||
'hostname': socket.gethostname(),
|
'hostname': socket.gethostname(),
|
||||||
'now': current_time.now(),
|
'now': DatetimeWrapper(current_time.now()),
|
||||||
'utcnow': current_time.utcnow(),
|
'utcnow': DatetimeWrapper(current_time.utcnow()),
|
||||||
'user': uid2user(os.getuid(), os.getuid()),
|
'user': uid2user(os.getuid(), os.getuid()),
|
||||||
'uuid4': str(uuid.uuid4()),
|
'uuid4': str(uuid.uuid4()),
|
||||||
'borgversion': borg_version,
|
'borgversion': borg_version,
|
||||||
|
|
|
@ -11,7 +11,7 @@ import msgpack.fallback
|
||||||
|
|
||||||
from ..helpers import Location
|
from ..helpers import Location
|
||||||
from ..helpers import Buffer
|
from ..helpers import Buffer
|
||||||
from ..helpers import partial_format, format_file_size, parse_file_size, format_timedelta, format_line, PlaceholderError
|
from ..helpers import partial_format, format_file_size, parse_file_size, format_timedelta, format_line, PlaceholderError, replace_placeholders
|
||||||
from ..helpers import make_path_safe, clean_lines
|
from ..helpers import make_path_safe, clean_lines
|
||||||
from ..helpers import prune_within, prune_split
|
from ..helpers import prune_within, prune_split
|
||||||
from ..helpers import get_cache_dir, get_keys_dir, get_nonces_dir
|
from ..helpers import get_cache_dir, get_keys_dir, get_nonces_dir
|
||||||
|
@ -1035,3 +1035,9 @@ def test_format_line_erroneous():
|
||||||
assert format_line('{invalid}', data)
|
assert format_line('{invalid}', data)
|
||||||
with pytest.raises(PlaceholderError):
|
with pytest.raises(PlaceholderError):
|
||||||
assert format_line('{}', data)
|
assert format_line('{}', data)
|
||||||
|
|
||||||
|
|
||||||
|
def test_replace_placeholders():
|
||||||
|
now = datetime.now()
|
||||||
|
assert " " not in replace_placeholders('{now}')
|
||||||
|
assert int(replace_placeholders('{now:%Y}')) == now.year
|
||||||
|
|
Loading…
Reference in New Issue