Skip to content

Commit

Permalink
better logging
Browse files Browse the repository at this point in the history
  • Loading branch information
jchopard committed Aug 26, 2019
1 parent 4063020 commit 401c5f6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 20 deletions.
12 changes: 5 additions & 7 deletions src/pkglts/config_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,10 @@ def installed_options(self, return_sorted=False):
Returns:
(iter of str)
"""
installed = [key for key in self if not key.startswith("_")]

if return_sorted:
opt_names = list(self.installed_options())
opt_names = installed
installed = []
while opt_names:
name = opt_names.pop(0)
Expand All @@ -155,12 +157,8 @@ def installed_options(self, return_sorted=False):
else:
installed.append(name)

for name in installed:
yield name
else:
for key in self:
if not key.startswith("_"):
yield key
for name in installed:
yield name

def render(self, txt):
"""Use items in config to render text
Expand Down
30 changes: 17 additions & 13 deletions src/pkglts/manage_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,19 +115,22 @@ def _rg_file(src_pth, tgt_name, tgt_pth, cfg, overwrite_file):

LOGGER.debug("render file '%s' into '%s'", src_pth, tgt_pth)

if overwrite_file.get(pth_as_key(tgt_pth), True):
_, ext = splitext(tgt_name)
if ext in NON_BIN_EXT:
blocks = render(cfg, src_pth, tgt_pth)
return dict((bid, compute_hash(cnt)) for bid, cnt in blocks)
else: # binary file
if exists(tgt_pth):
LOGGER.warning("overwrite? %s", tgt_pth)
else:
with open(src_pth, 'rb') as fhr:
content = fhr.read()
with open(tgt_pth, 'wb') as fhw:
fhw.write(content)
if not overwrite_file.get(pth_as_key(tgt_pth), True):
LOGGER.debug("no overwrite")
return None

_, ext = splitext(tgt_name)
if ext in NON_BIN_EXT:
blocks = render(cfg, src_pth, tgt_pth)
return dict((bid, compute_hash(cnt)) for bid, cnt in blocks)
else: # binary file
if exists(tgt_pth):
LOGGER.warning("overwrite? %s", tgt_pth)
else:
with open(src_pth, 'rb') as fhr:
content = fhr.read()
with open(tgt_pth, 'wb') as fhw:
fhw.write(content)


def regenerate_dir(src_dir, tgt_dir, cfg, overwrite_file):
Expand All @@ -143,6 +146,7 @@ def regenerate_dir(src_dir, tgt_dir, cfg, overwrite_file):
Returns:
(dict of str, map): hash key of preserved sections
"""
LOGGER.debug("regenerate_dir: '%s' -> '%s'", src_dir, tgt_dir)
hmap = {}

for src_name in listdir(src_dir):
Expand Down

0 comments on commit 401c5f6

Please sign in to comment.