~gpanders/pushbroom

20f82e9001efa60921a7de5c13c4f4db6889a3c5 — Greg Anders 2 years ago f985a94
Update logging output

- Only log the "Starting pushbroom" message when pushbroom is actually
  started
- Log a message for each of the sections in the config file
3 files changed, 16 insertions(+), 8 deletions(-)

M CHANGELOG.md
M src/pushbroom/console.py
M src/pushbroom/sweep.py
M CHANGELOG.md => CHANGELOG.md +2 -0
@@ 5,6 5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Changed
- Logging output

## [0.1.4] - 2019-06-18
### Added

M src/pushbroom/console.py => src/pushbroom/console.py +12 -6
@@ 36,8 36,12 @@ def run():
    ch.setLevel(logging.ERROR)

    if not args.dry_run:
        # If not doing a dry run log to a file
        log_file = os.path.expanduser("~/.cache/pushbroom/pushbroom.log")
        # If not doing a dry run log, to a file
        log_file = os.path.join(
            os.environ.get("XDG_CACHE_HOME", os.path.expanduser("~/.cache")),
            "pushbroom",
            "pushbroom.log",
        )
        os.makedirs(os.path.dirname(log_file), exist_ok=True)
        fh = logging.FileHandler(log_file)
        fh.setFormatter(logging.Formatter("%(asctime)s [%(levelname)s] %(message)s"))


@@ 52,10 56,11 @@ def run():

    if not args.config:
        # Look under XDG_CONFIG_HOME first, then look for ~/.pushbroomrc
        xdg_config_home = os.environ.get(
            "XDG_CONFIG_HOME", os.path.expanduser("~/.config")
        args.config = os.path.join(
            os.environ.get("XDG_CONFIG_HOME", os.path.expanduser("~/.config")),
            "pushbroom",
            "config",
        )
        args.config = os.path.join(xdg_config_home, "pushbroom", "config")
        if not os.path.exists(args.config):
            args.config = os.path.expanduser("~/.pushbroomrc")



@@ 67,6 72,7 @@ def run():
        logging.error("Configuration file {} not found".format(args.config))
        sys.exit(1)

    logging.info("Starting pushbroom")
    for section in config.sections():
        path = config.get(section, "path")
        fullpath = os.path.abspath(os.path.expanduser(path))


@@ 83,4 89,4 @@ def run():
                if not os.path.isdir(trash):
                    logging.error("No such directory %s", trash)

            pushbroom.sweep(fullpath, num_days, ignored, trash, args.dry_run)
            pushbroom.sweep(section, fullpath, num_days, ignored, trash, args.dry_run)

M src/pushbroom/sweep.py => src/pushbroom/sweep.py +2 -2
@@ 6,7 6,7 @@ import time
SECONDS_PER_DAY = 24 * 60 * 60


def sweep(path, num_days, ignored, trash=None, dry_run=False):
def sweep(name, path, num_days, ignored, trash=None, dry_run=False):
    """Remove old files from a directory

    :path: Path to remove files from


@@ 16,8 16,8 @@ def sweep(path, num_days, ignored, trash=None, dry_run=False):
    :dry_run: Only show what would happen without actually doing anything

    """
    logging.info("Sweeping %s", name)
    now = time.time()
    logging.info("Starting pushbroom")
    num_seconds = num_days * SECONDS_PER_DAY
    thresh = now - num_seconds
    for root, dirs, files in os.walk(path):