From cdeaa1495d21cc141c3b10c13c41827358692404 Mon Sep 17 00:00:00 2001 From: manu Date: Thu, 4 May 2017 06:01:52 +0200 Subject: [PATCH] check for global shreddit.yml file in user config dir --- requirements.txt | 1 + shreddit/app.py | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 56c70cd..1dfc88e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,3 +8,4 @@ backports-abc==0.4 tornado==4.3 update-checker==0.15 wheel==0.24.0 +appdirs==1.4.3 diff --git a/shreddit/app.py b/shreddit/app.py index 82521da..d98b4c1 100644 --- a/shreddit/app.py +++ b/shreddit/app.py @@ -5,6 +5,7 @@ import yaml import logging import os import pkg_resources +from appdirs import user_config_dir from shreddit import default_config from shreddit.shredder import Shredder @@ -28,7 +29,15 @@ def main(): fout.write(pkg_resources.resource_string("shreddit", "praw.ini.example")) return - config_filename = args.config or "shreddit.yml" + config_dir = user_config_dir("shreddit/shreddit.yml") + + if args.config: + config_filename = args.config + elif os.path.exists(config_dir): + config_filename = config_dir + else: + config_filename = "shreddit.yml" + if not os.path.isfile(config_filename): print("No shreddit configuration file was found or provided. Run this script with -g to generate one.") return