Exemple #1
0
 def _load(self):
     path = self.path()
     if not core.exists(path):
         return self._load_dot_cola()
     try:
         fp = core.xopen(path, 'rb')
         return mkdict(json.load(fp))
     except: # bad json
         return {}
Exemple #2
0
    def _load_dot_cola(self):
        values = {}
        path = os.path.join(core.expanduser('~'), '.cola')
        if not core.exists(path):
            return {}
        try:
            with core.xopen(path, 'r') as fp:
                json_values = json.load(fp)
        except: # bad json
            return {}

        # Keep only the entries we care about
        for key in self.values:
            try:
                values[key] = json_values[key]
            except KeyError:
                pass

        return values