Skip to content

Commit

Permalink
Some work on logging.
Browse files Browse the repository at this point in the history
Let's not require the pipelines to have used
logmuse options. then all existing
pipelines will be broken.
  • Loading branch information
nsheff committed Jul 18, 2019
1 parent c827021 commit da95289
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions pypiper/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

from attmap import AttMapEcho
from hashlib import md5
from logmuse import init_logger
import logmuse
from yacman import load_yaml
from .exceptions import PipelineHalt, SubprocessError
from .flags import *
Expand Down Expand Up @@ -329,10 +329,13 @@ def __init__(
name = kwds.pop("name")
except KeyError:
name = default_logname
self._logger = init_logger(name, **kwds)
self._logger = logmuse.init_logger(name, **kwds)
else:
logger_kwargs.setdefault("name", default_logname)
self._logger = logger_via_cli(args, **logger_kwargs)
try:
self._logger = logger_via_cli(args, **logger_kwargs)
except logmuse.est.AbsentOptionException:
self._logger = logmuse.init_logger("pypiper")

@property
def _completed(self):
Expand Down Expand Up @@ -544,7 +547,7 @@ def _set_status_flag(self, status):
prev_status = self.status
self.status = status
self._create_file(self._flag_file_path())
print("\nChanged status from {} to {}.".format(
self._logger.info("\nChanged status from {} to {}.".format(
prev_status, self.status))

def _flag_file_path(self, status=None):
Expand Down Expand Up @@ -1965,9 +1968,9 @@ def _cleanup(self, dry_run=False):
self.cleanup_list = []

if len(self.cleanup_list) > 0:
print("\nCleaning up flagged intermediate files. . .")
self.info("\nCleaning up flagged intermediate files. . .")
for expr in self.cleanup_list:
print("\nRemoving glob: " + expr)
self.debug("\nRemoving glob: " + expr)
try:
# Expand regular expression
files = glob.glob(expr)
Expand All @@ -1977,10 +1980,10 @@ def _cleanup(self, dry_run=False):
# and delete the files
for file in files:
if os.path.isfile(file):
print("`rm " + file + "`")
self.debug("`rm {}`".format(file))
os.remove(os.path.join(file))
elif os.path.isdir(file):
print("`rmdir " + file + "`")
self.debug("`rmdir {}`".format(file))
os.rmdir(os.path.join(file))
except:
pass
Expand All @@ -1991,19 +1994,19 @@ def _cleanup(self, dry_run=False):
if COMPLETE_FLAG not in os.path.basename(fn)
and not "{}_{}".format(self.name, run_flag) == os.path.basename(fn)]
if len(flag_files) == 0 and not dry_run:
print("\nCleaning up conditional list. . .")
self.info("\nCleaning up conditional list. . .")
for expr in self.cleanup_list_conditional:
print("\nRemoving glob: " + expr)
self.debug("\nRemoving glob: " + expr)
try:
files = glob.glob(expr)
while files in self.cleanup_list_conditional:
self.cleanup_list_conditional.remove(files)
for file in files:
if os.path.isfile(file):
print("`rm " + file + "`")
self.debug("`rm {}`".format(file))
os.remove(os.path.join(file))
elif os.path.isdir(file):
print("`rmdir " + file + "`")
self.debug("`rmdir {}`".format(file))
os.rmdir(os.path.join(file))
except:
pass
Expand Down

0 comments on commit da95289

Please sign in to comment.