From 3a66937205fd739d77b9432e15fdce1604982472 Mon Sep 17 00:00:00 2001 From: Florian Bruhin Date: Thu, 2 Oct 2014 21:54:52 +0200 Subject: [PATCH] Clean up argument handling in get_standard_dir --- qutebrowser/utils/utils.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/qutebrowser/utils/utils.py b/qutebrowser/utils/utils.py index 54814d9c1..d2447e135 100644 --- a/qutebrowser/utils/utils.py +++ b/qutebrowser/utils/utils.py @@ -177,14 +177,24 @@ def get_standard_dir(typ, args=None): args: An argparse namespace which could be used to override the locations. """ + # First check if it's been overridden + typ_to_argparse_arg = { + QStandardPaths.ConfigLocation: 'confdir' + } if args is not None: - if typ == QStandardPaths.ConfigLocation: - if args.confdir is None: + try: + argname = typ_to_argparse_arg[typ] + except KeyError: + pass + else: + arg_value = getattr(args, argname) + if arg_value is None: pass - elif args.confdir == '': + elif arg_value == '': return None else: - return args.confdir + return arg_value + # If not, get it from Qt qapp = QCoreApplication.instance() orgname = qapp.organizationName() # We need to temporarily unset the organisationname here since the