Index: infra/libs/git2/config_ref.py |
diff --git a/infra/services/gnumbd/support/config_ref.py b/infra/libs/git2/config_ref.py |
similarity index 57% |
rename from infra/services/gnumbd/support/config_ref.py |
rename to infra/libs/git2/config_ref.py |
index 719938e852d6876e04e5ab7ca8b7f380aaa8f9fe..11714f0d380ad7ce89b82d10fddf77738b293239 100644 |
--- a/infra/services/gnumbd/support/config_ref.py |
+++ b/infra/libs/git2/config_ref.py |
@@ -4,29 +4,31 @@ |
import json |
import logging |
-from infra.services.gnumbd.support.util import cached_property |
-from infra.services.gnumbd.support.git import INVALID |
+from infra.libs.decorators import cached_property |
+ |
+from infra.libs import git2 |
LOGGER = logging.getLogger(__name__) |
class ConfigRef(object): |
- CONVERT = { |
- 'interval': lambda self, val: float(val), |
- 'pending_tag_prefix': lambda self, val: str(val), |
- 'pending_ref_prefix': lambda self, val: str(val), |
- 'enabled_refglobs': lambda self, val: map(str, list(val)), |
- } |
- DEFAULTS = { |
- 'interval': 5.0, |
- 'pending_tag_prefix': 'refs/pending-tags', |
- 'pending_ref_prefix': 'refs/pending', |
- 'enabled_refglobs': [], |
- } |
- |
- def __init__(self, ref, filename='config.json'): |
- self.ref = ref |
- self.repo = ref.repo |
- self.filename = filename |
+ # {key: lambda self, val: convert(val)} |
+ CONVERT = {} |
+ |
+ # {key: default_val} |
+ DEFAULTS = {} |
+ |
+ REF = None |
+ |
+ FILENAME = 'config.json' |
+ |
+ def __init__(self, repo): |
+ assert self.REF is not None |
+ self._ref = repo[self.REF] |
+ self._repo = repo |
+ |
+ # pylint: disable=W0212 |
+ ref = property(lambda self: self._ref) |
+ repo = property(lambda self: self._repo) |
def __getitem__(self, key): |
return self.current[key] |
@@ -35,11 +37,11 @@ class ConfigRef(object): |
def current(self): |
cur = self.ref.commit |
- while cur is not None and cur is not INVALID: |
- LOGGER.debug('Evaluating config at %s:%s', cur.hsh, self.filename) |
+ while cur is not None and cur is not git2.INVALID: |
+ LOGGER.debug('Evaluating config at %s:%s', cur.hsh, self.FILENAME) |
try: |
data = self.repo.run('cat-file', 'blob', |
- '%s:%s' % (cur.hsh, self.filename)) |
+ '%s:%s' % (cur.hsh, self.FILENAME)) |
data = json.loads(data) |
if not isinstance(data, dict): |
LOGGER.error('Non-dict config: %r', data) |