94b0c9c74c424cb6fdcb5bfb1db83974202c684e — Greg Anders 2 years ago 08a24ae
Look in multiple locations for default config file

First check for $XDG_CONFIG_HOME/janitor/config and if not present look
for $HOME/.janitorrc.
2 files changed, 9 insertions(+), 2 deletions(-)

M src/janitor/console.py
M src/janitor/sweep.py
M src/janitor/console.py => src/janitor/console.py +8 -2
@@ 23,7 23,6 @@ def run():
        help="path to config file",

@@ 36,12 35,19 @@ def run():

    args = parser.parse_args()

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

    config = configparser.ConfigParser()
        with open(args.config, "r") as f:
    except FileNotFoundError:
        print("No configuration file found.")
        print("Configuration file {} not found".format(args.config))

    for path in config.sections():

M src/janitor/sweep.py => src/janitor/sweep.py +1 -0
@@ 13,6 13,7 @@ def sweep(path, num_days, ignored, trash=None, dry_run=False):
    :num_days: Remove files older than this many days
    :ignored: Regex pattern of paths to ignore
    :trash: If set, move files to this directory instead of deleting them
    :dry_run: Only show what would happen without actually doing anything

    now = time.time()