Browse Source

Made a caching read_backup_properties in backup_parser.py

master
Raphael Roberts 5 years ago
parent
commit
3fbe39771f
  1. 13
      tibi_hardlinks/backup_parser.py

13
tibi_hardlinks/backup_parser.py

@ -1,6 +1,8 @@
import re import re
from dateutil.parser import parse as datetime_parse, ParserError from dateutil.parser import parse as datetime_parse, ParserError
import pytz import pytz
from pathlib import Path
from tibi_hardlinks.cache import tibi_cache
tzinfos = {name: pytz.timezone(name) for name in pytz.all_timezones} tzinfos = {name: pytz.timezone(name) for name in pytz.all_timezones}
@ -22,3 +24,14 @@ def parse_property_text(text):
value = match.group("value") value = match.group("value")
properties[key] = value properties[key] = value
return properties return properties
def read_backup_properties(property_file: Path):
cached_result = tibi_cache.read(property_file.name)
if cached_result is None:
with open(property_file) as backup_properties:
data = parse_property_text(backup_properties.read())
tibi_cache.write(property_file.name, data)
return data
else:
return cached_result
Loading…
Cancel
Save