Ajout du traceback pour debogger + facilement
darcs-hash:20080209024200-af139-c87e0534b390a7f84229eefbcd405a9360c68a39.gz
This commit is contained in:
parent
70dd267674
commit
74bd5d7b45
1 changed files with 15 additions and 14 deletions
|
@ -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):
|
||||
|
@ -129,19 +139,10 @@ class Python(Bcfg2.Server.Plugin.Plugin):
|
|||
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']
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue