Changeset 360f99a in rattail


Ignore:
Timestamp:
07/09/20 16:59:56 (5 weeks ago)
Author:
Lance Edgar <lance@…>
Branches:
master
Children:
47134ca
Parents:
60c52f1
Message:

Let config define arbitrary kwargs for datasync watcher

Location:
rattail/datasync
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • rattail/datasync/config.py

    r60c52f1 r360f99a  
    33#
    44#  Rattail -- Retail Software Framework
    5 #  Copyright © 2010-2019 Lance Edgar
     5#  Copyright © 2010-2020 Lance Edgar
    66#
    77#  This file is part of Rattail.
     
    2626
    2727from __future__ import unicode_literals, absolute_import
     28
     29import re
    2830
    2931from rattail.config import ConfigProfile, parse_list
     
    5456        else:
    5557            dbkey = self._config_string('watcher.db', default='default')
    56             self.watcher = load_object(self.watcher_spec)(config, key, dbkey=dbkey)
     58            kwargs = {'dbkey': dbkey}
     59            pattern = re.compile(r'^{}\.watcher\.kwarg\.(?P<keyword>\w+)$'.format(self.key))
     60            # TODO: this should not be referencing the config parser directly?
     61            # (but we have no other way yet, to know which options are defined)
     62            # (we should at least allow config to be defined in DB Settings)
     63            # (however that should be optional, since some may not have a DB)
     64            for option in self.config.parser.options(self.section):
     65                match = pattern.match(option)
     66                if match:
     67                    keyword = match.group('keyword')
     68                    kwargs[keyword] = self.config.get(self.section, option)
     69            self.watcher = load_object(self.watcher_spec)(config, key, **kwargs)
    5770        self.watcher.delay = self._config_int('watcher.delay', default=self.watcher.delay)
    5871        self.watcher.retry_attempts = self._config_int('watcher.retry_attempts', default=self.watcher.retry_attempts)
  • rattail/datasync/watchers.py

    r60c52f1 r360f99a  
    33#
    44#  Rattail -- Retail Software Framework
    5 #  Copyright © 2010-2018 Lance Edgar
     5#  Copyright © 2010-2020 Lance Edgar
    66#
    77#  This file is part of Rattail.
     
    4040    retry_delay = 1 # seconds
    4141
    42     def __init__(self, config, key, dbkey=None):
     42    def __init__(self, config, key, dbkey=None, **kwargs):
     43        """
     44        Constructor.
     45
     46        Note that while arbitrary kwargs are allowed, the default constructor
     47        method does *not* process these in any way.  So if you need to accept
     48        some kwargs then you must also define the processing thereof.
     49
     50        The primary reason for this is because these kwargs, if present, will
     51        *always* be simple strings due to how they are read from config.
     52        Therefore the burden is on each custom watcher, to interpret them as
     53        whatever data type is necessary.
     54        """
    4355        self.config = config
    4456        self.key = key
Note: See TracChangeset for help on using the changeset viewer.