Commit 74bd5d7b authored by Jeremie Dimino's avatar Jeremie Dimino

Ajout du traceback pour debogger + facilement

darcs-hash:20080209024200-af139-c87e0534b390a7f84229eefbcd405a9360c68a39.gz
parent 70dd2676
......@@ -27,6 +27,7 @@ __all__ = ["Python"]
import logging, lxml.etree, posixpath, re, os, sys
from cStringIO import StringIO
import Bcfg2.Server.Plugin
import traceback
sys.path.append('/usr/scripts/bcfg2')
import pygen
......@@ -55,6 +56,15 @@ else:
# Dico nom de fichier -> code
includes = {}
def log_traceback(fname, section, exn):
logger.error('Python %s error: %s: %s: %s' % (section, fname, str(exn.__class__).split('.', 2)[1], str(exn)))
s = StringIO()
sys.stderr = s
traceback.print_exc()
sys.stderr = sys.__stderr__
for line in s.getvalue().splitlines():
logger.error('Python %s error: -> %s' % (section, line))
def dump(env, incfile):
exec(includes[incfile], env)
......@@ -68,7 +78,7 @@ def load_file(filename):
try:
return pygen.load(filename, os.path.dirname(filename) + "/." + os.path.basename(filename) + ".COMPILED")
except Exception, e:
logger.error('Python compilation error: %s: %s' % (str(e.__class__).split('.', 2)[1], str(e)))
log_traceback(filename, 'compilation', e)
return None
class PythonProperties(Bcfg2.Server.Plugin.SingleXMLFileBacked):
......@@ -115,7 +125,7 @@ class Python(Bcfg2.Server.Plugin.Plugin):
def BuildEntry(self, entry, metadata):
'''Construit le fichier'''
code = self.codes[entry.get('name')]
code = self.codes[entry.get('name')]
fname = entry.get('realname', entry.get('name'))
debug("building config file: %s" % fname, 'blue')
env = pygen.Environment()
......@@ -126,22 +136,13 @@ class Python(Bcfg2.Server.Plugin.Plugin):
env["info"] = { 'owner': 'root',
'group': 'root',
'perms': 0644 }
env.included = set([])
env.included = set([])
try:
include(env, "common")
entry.text = pygen.generate(code, env)
entry.text = pygen.generate(code, env).decode("UTF-8")
debug(entry.text)
except Exception, e:
import traceback
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)
log_traceback(fname, 'exec', e)
raise Bcfg2.Server.Plugin.PluginExecutionError
entry.attrib['owner'] = env["info"]['owner']
entry.attrib['group'] = env["info"]['group']
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment