File diff 992c91fc90de → 55f5833aa071
oxrlib/config.py
Show inline comments
...
 
@@ -20,6 +20,7 @@ def currency_list(s):
 
class Configuration:
 
    DATE_SEPS = frozenset('.-/ ')
 
    DEFAULT_CONFIG_PATH = pathlib.Path(HOME_PATH, '.config', 'oxrlib.ini')
 
    NO_DENOMINATION = object()
 
    PREPOSITIONS = frozenset(['in', 'to', 'into'])
 
    TODAY = datetime.date.today()
 

	
...
 
@@ -97,6 +98,17 @@ class Configuration:
 
            action='store_false', dest='ledger',
 
            help="Turn off an earlier --ledger setting",
 
        )
 
        hist_parser.add_argument(
 
            '--denomination',
 
            metavar='CODE', type=currency_code,
 
            help="In Ledger conversion output, always show rates to convert "
 
            "to this currency",
 
        )
 
        hist_parser.add_argument(
 
            '--no-denomination',
 
            dest='denomination', action='store_const', const=self.NO_DENOMINATION,
 
            help="Turn off an earlier --denomination setting",
 
        )
 
        hist_parser.add_argument(
 
            '--signed-currency', '--sign-currency',
 
            type=currency_code, action='append', dest='signed_currencies',
...
 
@@ -132,14 +144,16 @@ class Configuration:
 
        return configparser.ConfigParser()
 

	
 
    def _read_from_conffile(self, argname, sectionname, fallback, convert_to=None,
 
                            confname=None, getter='get', unset=None):
 
                            confname=None, getter='get', unset=None,
 
                            *, convert_fallback=False):
 
        if getattr(self.args, argname) is not unset:
 
            return
 
        elif confname is None:
 
            confname = argname
 
        get_method = getattr(self.conffile, getter)
 
        value = get_method(sectionname, confname, fallback=fallback)
 
        if convert_to is not None:
 
        if (convert_to is not None
 
            and (value is not fallback or convert_fallback)):
 
            value = self._convert_or_error(convert_to, value, confname)
 
        setattr(self.args, argname, value)
 

	
...
 
@@ -162,7 +176,12 @@ class Configuration:
 
            # Don't let the user specify ambiguous dates.
 
            self.error("historical data not available from year {}".format(year))
 
        self._read_from_conffile('base', 'Historical', 'USD', currency_code)
 
        self._read_from_conffile('signed_currencies', 'Historical', self.args.base, currency_list)
 
        if self.args.denomination is self.NO_DENOMINATION:
 
            self.args.denomination = None
 
        else:
 
            self._read_from_conffile('denomination', 'Historical', None, currency_code)
 
        self._read_from_conffile('signed_currencies', 'Historical', self.args.base,
 
                                 currency_list, convert_fallback=True)
 
        self._read_from_conffile('ledger', 'Historical', False, getter='getboolean')
 
        self.args.to_currency = self.args.base
 
        if self.args.word4 and (self.args.word3.lower() in self.PREPOSITIONS):