You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.2 KiB
40 lines
1.2 KiB
from pathlib import Path
|
|
import re
|
|
|
|
from dateutil.parser import parse as datetime_parse, ParserError
|
|
import pytz
|
|
|
|
from tibi_hardlinks.cache import cache_manager
|
|
|
|
tzinfos = {name: pytz.timezone(name) for name in pytz.all_timezones}
|
|
|
|
|
|
def parse_property_text(text):
|
|
properties = dict()
|
|
key_value_regex = re.compile(r"(?P<key>^[^=]+)=(?P<value>.*)")
|
|
lines = text.split("\n")
|
|
for line in lines:
|
|
if line.startswith("#"):
|
|
try:
|
|
time = datetime_parse(line.lstrip("#"), tzinfos=tzinfos)
|
|
properties["backup_time"] = time.astimezone(pytz.UTC).timestamp()
|
|
except ParserError:
|
|
pass
|
|
match = key_value_regex.match(line)
|
|
if match:
|
|
key = match.group("key")
|
|
if key != "app_gui_icon":
|
|
value = match.group("value")
|
|
properties[key] = value
|
|
return properties
|
|
|
|
|
|
def read_backup_properties(property_file: Path):
|
|
try:
|
|
data = cache_manager.tibi_cache[property_file.name]
|
|
return data
|
|
except KeyError:
|
|
with open(property_file) as backup_properties:
|
|
data = parse_property_text(backup_properties.read())
|
|
cache_manager.tibi_cache[property_file.name] = data
|
|
return data
|