diff options
Diffstat (limited to 'src/leap/base/pluggableconfig.py')
| -rw-r--r-- | src/leap/base/pluggableconfig.py | 38 | 
1 files changed, 36 insertions, 2 deletions
diff --git a/src/leap/base/pluggableconfig.py b/src/leap/base/pluggableconfig.py index b8615ad8..3517db6b 100644 --- a/src/leap/base/pluggableconfig.py +++ b/src/leap/base/pluggableconfig.py @@ -10,6 +10,8 @@ import urlparse  import jsonschema +from leap.util.translations import LEAPTranslatable +  logger = logging.getLogger(__name__) @@ -118,7 +120,6 @@ adaptors['json'] = JSONAdaptor()  # to proper python types.  # TODO: -# - multilingual object.  # - HTTPS uri @@ -132,6 +133,20 @@ class DateType(object):          return time.strftime(self.fmt, data) +class TranslatableType(object): +    """ +    a type that casts to LEAPTranslatable objects. +    Used for labels we get from providers and stuff. +    """ + +    def to_python(self, data): +        return LEAPTranslatable(data) + +    # needed? we already have an extended dict... +    #def get_prep_value(self, data): +        #return dict(data) + +  class URIType(object):      def to_python(self, data): @@ -164,6 +179,7 @@ types = {      'date': DateType(),      'uri': URIType(),      'https-uri': HTTPSURIType(), +    'translatable': TranslatableType(),  } @@ -180,6 +196,8 @@ class PluggableConfig(object):          self.adaptors = adaptors          self.types = types          self._format = format +        self.mtime = None +        self.dirty = False      @property      def option_dict(self): @@ -319,6 +337,13 @@ class PluggableConfig(object):          serializable = self.prep_value(config)          adaptor.write(serializable, filename) +        if self.mtime: +            self.touch_mtime(filename) + +    def touch_mtime(self, filename): +        mtime = self.mtime +        os.utime(filename, (mtime, mtime)) +      def deserialize(self, string=None, fromfile=None, format=None):          """          load configuration from a file or string @@ -364,6 +389,12 @@ class PluggableConfig(object):              content = _try_deserialize()          return content +    def set_dirty(self): +        self.dirty = True + +    def is_dirty(self): +        return self.dirty +      def load(self, *args, **kwargs):          """          load from string or file @@ -373,6 +404,8 @@ class PluggableConfig(object):          """          string = args[0] if args else None          fromfile = kwargs.get("fromfile", None) +        mtime = kwargs.pop("mtime", None) +        self.mtime = mtime          content = None          # start with defaults, so we can @@ -402,7 +435,8 @@ class PluggableConfig(object):          return True -def testmain(): +def testmain():  # pragma: no cover +      from tests import test_validation as t      import pprint  | 
