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
|
import logging, lxml.etree, posixpath, re, os, sys
|
||||||
from cStringIO import StringIO
|
from cStringIO import StringIO
|
||||||
import Bcfg2.Server.Plugin
|
import Bcfg2.Server.Plugin
|
||||||
|
import traceback
|
||||||
|
|
||||||
sys.path.append('/usr/scripts/bcfg2')
|
sys.path.append('/usr/scripts/bcfg2')
|
||||||
import pygen
|
import pygen
|
||||||
|
@ -55,6 +56,15 @@ else:
|
||||||
# Dico nom de fichier -> code
|
# Dico nom de fichier -> code
|
||||||
includes = {}
|
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):
|
def dump(env, incfile):
|
||||||
exec(includes[incfile], env)
|
exec(includes[incfile], env)
|
||||||
|
|
||||||
|
@ -68,7 +78,7 @@ def load_file(filename):
|
||||||
try:
|
try:
|
||||||
return pygen.load(filename, os.path.dirname(filename) + "/." + os.path.basename(filename) + ".COMPILED")
|
return pygen.load(filename, os.path.dirname(filename) + "/." + os.path.basename(filename) + ".COMPILED")
|
||||||
except Exception, e:
|
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
|
return None
|
||||||
|
|
||||||
class PythonProperties(Bcfg2.Server.Plugin.SingleXMLFileBacked):
|
class PythonProperties(Bcfg2.Server.Plugin.SingleXMLFileBacked):
|
||||||
|
@ -129,19 +139,10 @@ class Python(Bcfg2.Server.Plugin.Plugin):
|
||||||
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).decode("UTF-8")
|
||||||
debug(entry.text)
|
debug(entry.text)
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
import traceback
|
log_traceback(fname, 'exec', e)
|
||||||
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
|
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']
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue