commit 9e13acaa6e7c0369dff9e1f24ce114ad9e44ed82
parent 6b84e3b3fe7922d8812f3e24a75950c04ca0187c
Author: nolash <dev@holbrook.no>
Date: Sun, 28 Jun 2020 21:18:42 +0200
Add xdg support
Diffstat:
2 files changed, 30 insertions(+), 7 deletions(-)
diff --git a/src/feedwarrior/config.py b/src/feedwarrior/config.py
@@ -3,15 +3,35 @@ import os
import configparser
import hashlib
+# third party imports
+from xdg import BaseDirectory
+
+
class config:
- def __init__(self, filename):
+ def __init__(self, filename=None):
+ self.data_dir = BaseDirectory.save_data_path('feedwarrior')
cp = configparser.ConfigParser()
- cp.read(filename)
- self.data_dir = cp['FEEDWARRIOR']['datadir']
- self.feeds_dir = os.path.join(cp['FEEDWARRIOR']['datadir'], 'feeds')
- self.entries_dir = os.path.join(cp['FEEDWARRIOR']['datadir'], 'entries')
+
+ config_paths = [filename]
+ config_loaded = False
+ if filename == None:
+ config_paths = BaseDirectory.load_config_paths('feedwarrior')
+
+ for p in config_paths:
+ try:
+ cp.read(filename)
+ break
+ except FileNotFoundError:
+ pass
+
+ if cp.has_section('FEEDWARRIOR'):
+ self.data_dir = cp['FEEDWARRIOR'].get(['datadir'])
+
+ self.feeds_dir = os.path.join(self.data_dir, 'feeds')
+ self.entries_dir = os.path.join(self.data_dir, 'entries')
self.hasher = hashlib.sha256
+
def load_config(filename):
return config(filename)
diff --git a/src/main.py b/src/main.py
@@ -22,10 +22,9 @@ logging.basicConfig(level=logging.ERROR)
logg = logging.getLogger()
-
argparser = argparse.ArgumentParser(description='create and manipulate feedwarrior feeds')
argparser.add_argument('-l', help='feed log to operate on')
-argparser.add_argument('-c', required=True, type=str, help='configuration file')
+argparser.add_argument('-c', type=str, help='configuration file')
argparser.add_argument('-v', action='store_true', help='be verbose')
sub = argparser.add_subparsers()
# TODO: add subparser to same level flags as main parser
@@ -66,6 +65,7 @@ if args.l != None:
sys.stderr.write('cannot resolve feed {}\n'.format(args.l))
sys.exit(1)
+
cmd_mod = None
if args.command == 'create':
feed_current = feedwarrior.feed(parent=feed_current)
@@ -73,6 +73,9 @@ if args.command == 'create':
elif args.command == 'entry':
cmd_mod = cmd_entry
elif args.command == 'show' or args.command == None:
+ if feed_current == None:
+ sys.stderr.write('plesae speficy a feed for showing\n')
+ sys.exit(1)
feed_current = feedwarrior.load_feed(os.path.join(config.feeds_dir, str(feed_current.uuid)))
cmd_mod = cmd_show
else: