Skip to content
Browse files

Merge pull request #491 from kaj/master

[#1472] Better handling of @include in python parsing of application.conf
  • Loading branch information...
2 parents 90cae11 + 233ecf8 commit eaf8190f1f2f4b7431673ae6a6c32ca056729e0c @pepite pepite committed
Showing with 19 additions and 5 deletions.
  1. +19 −5 framework/pym/play/application.py
View
24 framework/pym/play/application.py
@@ -24,7 +24,8 @@ def __init__(self, application_path, env, ignoreMissingModules = False):
confFolder = os.path.join(application_path, 'conf/')
try:
self.conf = PlayConfParser(confFolder, env)
- except:
+ except Exception as err:
+ print "~ Faile to parse application configuration", err
self.conf = None # No app / Invalid app
else:
self.conf = None
@@ -330,11 +331,14 @@ def readFile(self, confFolder, filename):
# process all include files
for includeFile in includeFiles:
# read include file
- fromIncludeFile = self.readFile(confFolder, includeFile)
+ try:
+ fromIncludeFile = self.readFile(confFolder, self._expandValue(includeFile))
- # add everything from include file
- for (key, value) in fromIncludeFile.items():
- washedResult[key]=value
+ # add everything from include file
+ for (key, value) in fromIncludeFile.items():
+ washedResult[key]=value
+ except Exception as err:
+ print "~ Failed to load included configuration %s: %s" % (includeFile, err)
return washedResult
@@ -358,6 +362,16 @@ def getAll(self, query):
result.append(self.entries.get(key))
return result
+ def _expandValue(self, value):
+ def expandvar(match):
+ key = match.group(1)
+ if key == 'play.id':
+ return self.id
+ else: # unkonwn
+ return '${%s}' % key
+
+ return re.sub('\${([a-z.]+)}', expandvar, value)
+
def hasKey(arr, elt):
try:
i = arr.index(elt)

0 comments on commit eaf8190

Please sign in to comment.
Something went wrong with that request. Please try again.