本文整理汇总了Python中supybot.log.exception函数的典型用法代码示例。如果您正苦于以下问题:Python exception函数的具体用法?Python exception怎么用?Python exception使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了exception函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_bug
def get_bug(self, id): # This is still a little rough, but it works :)
url = "%s/%d" % (self.url, id)
try:
raw = utils.web.getUrl("%s?format=tab" % url).decode('utf-8')
except Exception as e:
# Due to unreliable matching
if '.' in self.name:
supylog.exception(self.errget % (self.description, e, url))
return
if 'HTTP Error 500' in str(e):
raise BugNotFoundError
raise BugtrackerError(self.errget % (self.description, e, url))
raw = raw.replace('\r\n', '\n')
(headers, rest) = raw.split('\n', 1)
headers = headers.strip().split('\t')
rest = rest.strip().split('\t')
title = status = package = severity = assignee = ""
if "summary" in headers:
title = rest[headers.index("summary")]
if "status" in headers:
status = rest[headers.index("status")]
if "component" in headers:
package = rest[headers.index("component")]
if "severity" in headers:
severity = rest[headers.index("severity")]
elif "priority" in headers:
severity = rest[headers.index("priority")]
if "owner" in headers:
assignee = rest[headers.index("owner")]
return (id, package, title, severity, status, assignee, url, [], [])
示例2: __init__
def __init__(self, *args, **kwargs):
IBugtracker.__init__(self, *args, **kwargs)
self.lp = None
# A word to the wise:
# The Launchpad API is much better than the /+text interface we currently use,
# it's faster and easier to get the information we need.
# The current /+text interface is not really maintained by Launchpad and most,
# or all, of the Launchpad developers hate it. For this reason, we are dropping
# support for /+text in the future in favour of launchpadlib.
# Terence Simpson (tsimpson) 2010-04-20
try: # Attempt to use launchpadlib, python bindings for the Launchpad API
from launchpadlib.launchpad import Launchpad
cachedir = os.path.join(conf.supybot.directories.data.tmp(), 'lpcache')
if hasattr(Launchpad, 'login_anonymously'):
self.lp = Launchpad.login_anonymously("Ubuntu Bots - Bugtracker", 'production', cachedir)
else: #NOTE: Most people should have a launchpadlib new enough for .login_anonymously
self.lp = Launchpad.login("Ubuntu Bots - Bugtracker", '', '', 'production', cahedir)
except ImportError:
# Ask for launchpadlib to be installed
supylog.warning("Please install python-launchpadlib, the old interface is deprecated")
except Exception: # Something unexpected happened
self.lp = None
supylog.exception("Unknown exception while accessing the Launchpad API")
示例3: flush
def flush():
"""Flushes all the registered flushers."""
for (i, f) in enumerate(flushers):
try:
f()
except Exception, e:
log.exception("Uncaught exception in flusher #%s (%s):", i, f)
示例4: _loadPlugins
def _loadPlugins(self, irc):
self.log.info('Loading plugins (connecting to %s).', irc.network)
alwaysLoadImportant = conf.supybot.plugins.alwaysLoadImportant()
important = conf.supybot.commands.defaultPlugins.importantPlugins()
for (name, value) in conf.supybot.plugins.getValues(fullNames=False):
if irc.getCallback(name) is None:
load = value()
if not load and name in important:
if alwaysLoadImportant:
s = '%s is configured not to be loaded, but is being '\
'loaded anyway because ' \
'supybot.plugins.alwaysLoadImportant is True.'
self.log.warning(s, name)
load = True
if load:
# We don't load plugins that don't start with a capital
# letter.
if name[0].isupper() and not irc.getCallback(name):
# This is debug because each log logs its beginning.
self.log.debug('Loading %s.', name)
try:
m = plugin.loadPluginModule(name,
ignoreDeprecation=True)
plugin.loadPluginClass(irc, m)
except callbacks.Error, e:
# This is just an error message.
log.warning(str(e))
except (plugins.NoSuitableDatabase, ImportError), e:
s = 'Failed to load %s: %s' % (name, e)
if not s.endswith('.'):
s += '.'
log.warning(s)
except Exception, e:
log.exception('Failed to load %s:', name)
示例5: _runCommandFunction
def _runCommandFunction(self, irc, msg, command):
"""Run a command from message, as if command was sent over IRC."""
tokens = callbacks.tokenize(command)
try:
self.Proxy(irc.irc, msg, tokens)
except Exception, e:
log.exception('Uncaught exception in function called by MessageParser:')
示例6: get_bug_new
def get_bug_new(self, id): #TODO: Rename this method to 'get_bug'
try:
bugdata = self.lp.bugs[id]
if bugdata.private:
raise BugtrackerError, "This bug is private"
dup = bugdata.duplicate_of
summary_prefix = '' # Used to made dups easier
while dup:
summary_prefix = 'duplicate for #%d ' % id
bugdata = dup
dup = bugdata.duplicate_of
affected = bugdata.users_affected_count_with_dupes
heat = bugdata.heat
tasks = bugdata.bug_tasks
if tasks.total_size != 1:
tasks = list(tasks)
try:
tasks.sort(self._sort)
taskdata = tasks[-1]
except ValueError:
tasks = [_ for _ in tasks if _.bug_target_name.endswith(u'(Ubuntu)')]
if tasks:
if len(tasks) != 1:
try:
tasks.sort(self._sort)
taskdata = tasks[-1]
except ValueError:
taskdata = bugdata.bug_tasks[bugdata.bug_tasks.total_size - 1]
else:
taskdata = tasks[-1]
else:
taskdata = tasks[-1]
else:
taskdata = tasks[0]
assignee = taskdata.assignee
t = taskdata.bug_target_display_name #task name
if assignee: # "Diaplay Name (Launchpad ID)"
assignee = u"%s (%s)" % (assignee.display_name, assignee.name)
else:
assignee = ''
except Exception, e:
if type(e).__name__ == 'HTTPError': # messy, but saves trying to import lazr.restfulclient.errors.HTPError
if e.response.status == 404:
bugNo = e.content.split(None)[-1][2:-1] # extract the real bug number
if bugNo != str(id): # A duplicate of a private bug, at least we know it exists
raise BugtrackerError, 'Bug #%s is a duplicate of bug #%s, but it is private (%s/bugs/%s)' % (id, bugNo, self.url, bugNo)
raise BugtrackerError, "Bug #%s (%s/bugs/%d) is private or doesn't exist" % (id, self.url, id) # Could be private, could just not exist
supylog.exception("Error gathering bug data for %s bug #%d" % (self.description, id))
raise BugtrackerError, "Could not gather data from %s for bug #%s (%s/bugs/%s). The error has been logged" % (self.description, id, self.url, id)
elif isinstance(e, KeyError):
raise BugNotFoundError
supylog.exception("Error gathering bug data for %s bug %d" % (self.description, id))
raise BugtrackerError, "Could not gather data from %s for bug #%s (%s/bugs/%s). The error has been logged" % (self.description, id, self.url, id)
示例7: newf
def newf(*args, **kwargs):
for x in range(0, 3):
try:
return f(*args, **kwargs)
except Exception:
log.exception('Shrinking URL failed. Trying again.')
time.sleep(1)
return f(*args, **kwargs)
示例8: _loadPlugins
def _loadPlugins(self, irc):
self.log.info('Loading plugins (connecting to %s).', irc.network)
alwaysLoadImportant = conf.supybot.plugins.alwaysLoadImportant()
important = conf.supybot.commands.defaultPlugins.importantPlugins()
for (name, value) in conf.supybot.plugins.getValues(fullNames=False):
if irc.getCallback(name) is None:
load = value()
if not load and name in important:
if alwaysLoadImportant:
s = '%s is configured not to be loaded, but is being '\
'loaded anyway because ' \
'supybot.plugins.alwaysLoadImportant is True.'
self.log.warning(s, name)
load = True
if load:
# We don't load plugins that don't start with a capital
# letter.
if name[0].isupper() and not irc.getCallback(name):
# This is debug because each log logs its beginning.
self.log.debug('Loading %s.', name)
try:
m = plugin.loadPluginModule(name,
ignoreDeprecation=True)
plugin.loadPluginClass(irc, m)
except callbacks.Error as e:
# This is just an error message.
log.warning(str(e))
except plugins.NoSuitableDatabase as e:
s = 'Failed to load %s: no suitable database(%s).' % (
name, e)
log.warning(s)
except ImportError as e:
e = str(e)
if e.endswith(name):
s = 'Failed to load {0}: No plugin named {0} exists.'.format(
utils.str.dqrepr(name))
elif "No module named 'config'" in e:
s = (
"Failed to load %s: This plugin may be incompatible "
"with your current Python version. If this error is appearing "
"with stock Supybot plugins, remove the stock plugins directory "
"(usually ~/Limnoria/plugins) from 'config directories.plugins'." %
name)
else:
s = 'Failed to load %s: import error (%s).' % (
name, e)
log.warning(s)
except Exception as e:
log.exception('Failed to load %s:', name)
else:
# Let's import the module so configuration is preserved.
try:
_ = plugin.loadPluginModule(name)
except Exception as e:
log.debug('Attempted to load %s to preserve its '
'configuration, but load failed: %s',
name, e)
world.starting = False
示例9: _email_callback
def _email_callback(self, fileobj):
try:
email = parse_mail(fileobj)
msg = get_message(email, new_queue=self.new_queue)
if not msg:
return
txt = colourise(msg.for_irc())
# Simple flood/duplicate detection
if txt in self.last_n_messages:
return
self.last_n_messages.insert(0, txt)
self.last_n_messages = self.last_n_messages[:20]
for channel in self.irc.state.channels:
package_regex = self.registryValue(
'package_regex',
channel,
) or 'a^' # match nothing by default
package_match = re.search(package_regex, msg.package)
maintainer_match = False
maintainer_regex = self.registryValue(
'maintainer_regex',
channel)
if maintainer_regex:
info = Maintainer().get_maintainer(msg.package)
if info:
maintainer_match = re.search(maintainer_regex, info['email'])
if not package_match and not maintainer_match:
continue
distribution_regex = self.registryValue(
'distribution_regex',
channel,
)
if distribution_regex:
if not hasattr(msg, 'distribution'):
# If this channel has a distribution regex, don't
# bother continuing unless the message actually has a
# distribution. This filters security messages, etc.
continue
if not re.search(distribution_regex, msg.distribution):
# Distribution doesn't match regex; don't send this
# message.
continue
ircmsg = supybot.ircmsgs.privmsg(channel, txt)
self.irc.queueMsg(ircmsg)
except Exception as e:
log.exception('Uncaught exception: %s ' % e)
示例10: flush
def flush(self):
"""Exports the database to a file."""
tmp_filename = self.filename + '.tmp'
try:
with open(tmp_filename, 'wb') as f:
pickle.dump(self.db, f, 2)
os.rename(tmp_filename, self.filename)
except Exception as e:
log.exception('%s: Unable to write database: %s', self._plugin_name, e)
示例11: _dispatch
def _dispatch(self, name, args):
if name not in self.connector.rpcMethods:
raise TypeError('no such method (%s)' % name)
try:
return self.connector.rpcMethods[name](*args)
except Fault:
raise
except:
log.exception('Unhandled exception in Trac XMLRPC:')
raise
示例12: __del__
def __del__(self):
try:
Connection.__del__(self)
except AttributeError:
pass
except Exception, e:
try:
log.exception('Uncaught exception in __del__:')
except:
pass
示例13: run
def run(self):
if len(drivers._drivers) == 1 and not world.testing:
log.error('Schedule is the only remaining driver, '
'why do we continue to live?')
time.sleep(1) # We're the only driver; let's pause to think.
while self.schedule and self.schedule[0][0] < time.time():
(t, name) = heapq.heappop(self.schedule)
f = self.events[name]
del self.events[name]
try:
f()
except Exception, e:
log.exception('Uncaught exception in scheduled function:')
示例14: open
def open(self, filename):
self.filename = filename
reader = unpreserve.Reader(IrcUserCreator, self)
try:
self.noFlush = True
try:
reader.readFile(filename)
self.noFlush = False
self.flush()
except EnvironmentError, e:
log.error('Invalid user dictionary file, resetting to empty.')
log.error('Exact error: %s', utils.exnToString(e))
except Exception, e:
log.exception('Exact error:')
示例15: open
def open(self, filename):
self.noFlush = True
try:
self.filename = filename
reader = unpreserve.Reader(IrcChannelCreator, self)
try:
reader.readFile(filename)
self.noFlush = False
self.flush()
except EnvironmentError, e:
log.error("Invalid channel database, resetting to empty.")
log.error("Exact error: %s", utils.exnToString(e))
except Exception, e:
log.error("Invalid channel database, resetting to empty.")
log.exception("Exact error:")