Mercurial > piecrust2
comparison piecrust/appconfig.py @ 839:b8f089092281
bug: Fix crashes for commands run outside of a website.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Wed, 15 Feb 2017 22:15:06 -0800 |
parents | fd694f1297c7 |
children | 4850f8c21b6e |
comparison
equal
deleted
inserted
replaced
838:89a44af17062 | 839:b8f089092281 |
---|---|
95 paths.append(self._theme_path) | 95 paths.append(self._theme_path) |
96 if self._path: | 96 if self._path: |
97 paths.append(self._path) | 97 paths.append(self._path) |
98 paths += self._custom_paths | 98 paths += self._custom_paths |
99 | 99 |
100 if len(paths) == 0: | |
101 raise ConfigurationError( | |
102 "No paths to load configuration from. " | |
103 "Specify paths, or set the values directly.") | |
104 | |
105 # Build the cache-key. | 100 # Build the cache-key. |
106 path_times = [os.path.getmtime(p) for p in paths] | 101 path_times = [os.path.getmtime(p) for p in paths] |
107 cache_key_hash = hashlib.md5( | 102 cache_key_hash = hashlib.md5( |
108 ("version=%s&cache=%d" % ( | 103 ("version=%s&cache=%d" % ( |
109 APP_VERSION, CACHE_VERSION)).encode('utf8')) | 104 APP_VERSION, CACHE_VERSION)).encode('utf8')) |
110 for p in paths: | 105 for p in paths: |
111 cache_key_hash.update(("&path=%s" % p).encode('utf8')) | 106 cache_key_hash.update(("&path=%s" % p).encode('utf8')) |
112 cache_key = cache_key_hash.hexdigest() | 107 cache_key = cache_key_hash.hexdigest() |
113 | 108 |
114 # Check the cache for a valid version. | 109 # Check the cache for a valid version. |
115 if self._cache.isValid('config.json', path_times): | 110 if path_times and self._cache.isValid('config.json', path_times): |
116 logger.debug("Loading configuration from cache...") | 111 logger.debug("Loading configuration from cache...") |
117 config_text = self._cache.read('config.json') | 112 config_text = self._cache.read('config.json') |
118 self._values = json.loads( | 113 self._values = json.loads( |
119 config_text, | 114 config_text, |
120 object_pairs_hook=collections.OrderedDict) | 115 object_pairs_hook=collections.OrderedDict) |