Skip to content

Commit

Permalink
fix: use glob instead of re
Browse files Browse the repository at this point in the history
  • Loading branch information
Kraymer committed Apr 27, 2020
1 parent cbf3f64 commit 9bc8101
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions cronicle/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import glob
import logging
import os
import re

from collections import OrderedDict
import datetime as dt
Expand Down Expand Up @@ -97,16 +96,17 @@ def find_config(filename, cfg=None):
"""
res = copy.deepcopy(DEFAULT_CFG)
dirname, basename = os.path.split(filename)

if not cfg:
cfg = config

# Overwrite default config fields with matched config ones
for pattern in cfg.keys():
abspattern = (
os.path.join(dirname, pattern) if not os.path.isabs(pattern) else pattern
)
if re.match(abspattern, filename):
for x in glob.glob(abspattern):
if not x.endswith(filename):
continue
pattern_cfg = cfg[pattern] if isinstance(cfg, dict) else cfg[pattern].get()
res.update(pattern_cfg)
for frequency in pattern_cfg:
Expand Down Expand Up @@ -153,7 +153,6 @@ def is_spaced_enough(self, filename, target_dir):
_last_archive_date = last_archive_date(
filename, target_dir, self.cfg["pattern"]
)

if _last_archive_date:
delta = relativedelta(file_date, _last_archive_date)
delta_unit, delta_min = frequency_folder_days(target_dir)
Expand Down

0 comments on commit 9bc8101

Please sign in to comment.