ajout de traceback
darcs-hash:20080209010131-af139-e1cc9fd883d67c891dac9b8d602bff10aa35bf55.gz
This commit is contained in:
parent
2b9c65a1de
commit
f407272074
2 changed files with 15 additions and 8 deletions
|
@ -115,7 +115,7 @@ class Python(Bcfg2.Server.Plugin.Plugin):
|
||||||
|
|
||||||
def BuildEntry(self, entry, metadata):
|
def BuildEntry(self, entry, metadata):
|
||||||
'''Construit le fichier'''
|
'''Construit le fichier'''
|
||||||
code = self.codes[entry.get('name')]
|
code = self.codes[entry.get('name')]
|
||||||
fname = entry.get('realname', entry.get('name'))
|
fname = entry.get('realname', entry.get('name'))
|
||||||
debug("building config file: %s" % fname, 'blue')
|
debug("building config file: %s" % fname, 'blue')
|
||||||
env = pygen.Environment()
|
env = pygen.Environment()
|
||||||
|
@ -126,14 +126,23 @@ class Python(Bcfg2.Server.Plugin.Plugin):
|
||||||
env["info"] = { 'owner': 'root',
|
env["info"] = { 'owner': 'root',
|
||||||
'group': 'root',
|
'group': 'root',
|
||||||
'perms': 0644 }
|
'perms': 0644 }
|
||||||
env.included = set([])
|
env.included = set([])
|
||||||
try:
|
try:
|
||||||
include(env, "common")
|
include(env, "common")
|
||||||
entry.text = pygen.generate(code, env)
|
entry.text = pygen.generate(code, env)
|
||||||
debug(entry.text)
|
debug(entry.text)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
logger.error('Python exec error: %s: %s' % (str(e.__class__).split('.', 2)[1], str(e)))
|
import traceback
|
||||||
raise Bcfg2.Server.Plugin.PluginExecutionError
|
from cStringIO import StringIO
|
||||||
|
s = StringIO()
|
||||||
|
sys.stderr = s
|
||||||
|
traceback.print_exc()
|
||||||
|
sys.stderr = sys.__stderr__
|
||||||
|
traceback = s.getvalue()
|
||||||
|
logger.error('Python exec error: %s: %s' % (str(e.__class__).split('.', 2)[1], str(e)))
|
||||||
|
for line in traceback.splitlines():
|
||||||
|
logger.error('Python exec error: -> %s' % line)
|
||||||
|
raise Bcfg2.Server.Plugin.PluginExecutionError
|
||||||
entry.attrib['owner'] = env["info"]['owner']
|
entry.attrib['owner'] = env["info"]['owner']
|
||||||
entry.attrib['group'] = env["info"]['group']
|
entry.attrib['group'] = env["info"]['group']
|
||||||
entry.attrib['perms'] = oct(env["info"]['perms'])
|
entry.attrib['perms'] = oct(env["info"]['perms'])
|
||||||
|
|
|
@ -25,7 +25,7 @@ fichier de configuration à partir d'un script python'''
|
||||||
|
|
||||||
__all__ = [ "Environment", "compileSource", "generate", "load" ]
|
__all__ = [ "Environment", "compileSource", "generate", "load" ]
|
||||||
|
|
||||||
import re, marshal, os
|
import re, marshal, os, sys
|
||||||
from cStringIO import StringIO
|
from cStringIO import StringIO
|
||||||
|
|
||||||
# Pour l'arrêt d'un script
|
# Pour l'arrêt d'un script
|
||||||
|
@ -180,8 +180,6 @@ def load(fname, cfname=None):
|
||||||
return code
|
return code
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
import sys
|
|
||||||
|
|
||||||
result = generate(load(sys.argv[1]))
|
result = generate(load(sys.argv[1]))
|
||||||
|
|
||||||
print "resultat:"
|
print "resultat:"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue