Add debug info on exceptions
This commit is contained in:
parent
f4ec71bbd0
commit
7b7c4e01cb
@ -18,7 +18,7 @@
|
|||||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
import re, sys, time
|
import re, sys, time, traceback
|
||||||
|
|
||||||
class colors:
|
class colors:
|
||||||
'''
|
'''
|
||||||
@ -220,9 +220,19 @@ def error(data, error=None, timestamp=True):
|
|||||||
if get_level() <= LEVEL_ERROR:
|
if get_level() <= LEVEL_ERROR:
|
||||||
log('-', data, colors.fg.red, timestamp=timestamp)
|
log('-', data, colors.fg.red, timestamp=timestamp)
|
||||||
if not error is None:
|
if not error is None:
|
||||||
debug('Error details: ' + str(error))
|
debug('Error details: ' + str(error) + parse_error())
|
||||||
|
|
||||||
# fatal: when the something so bad has happened that the prorgam must stop
|
# fatal: when the something so bad has happened that the prorgam must stop
|
||||||
def fatal(data, timestamp=True):
|
def fatal(data, timestamp=True):
|
||||||
if get_level() <= LEVEL_FATAL:
|
if get_level() <= LEVEL_FATAL:
|
||||||
log('#', data, colors.bg.red + colors.fg.green + colors.bold, timestamp=timestamp)
|
log('#', data, colors.bg.red + colors.fg.green + colors.bold, timestamp=timestamp)
|
||||||
|
|
||||||
|
# returns a formatted error message
|
||||||
|
def parse_error():
|
||||||
|
details = traceback.extract_tb(sys.exc_info()[2])
|
||||||
|
output = ''
|
||||||
|
|
||||||
|
for line in details:
|
||||||
|
output += '\n ... module %s in %s:%i' % (line[2], line[0], line[1])
|
||||||
|
|
||||||
|
return output
|
||||||
|
@ -293,11 +293,11 @@ class Onionr:
|
|||||||
Displays the Onionr version
|
Displays the Onionr version
|
||||||
'''
|
'''
|
||||||
|
|
||||||
logger.info('Onionr ' + ONIONR_VERSION + ' (' + platform.machine() + ') - API v' + API_VERSION)
|
logger.info('Onionr %s (%s) - API v%s' % (ONIONR_VERSION, platform.machine(), API_VERSION))
|
||||||
if verbosity >= 1:
|
if verbosity >= 1:
|
||||||
logger.info(ONIONR_TAGLINE)
|
logger.info(ONIONR_TAGLINE)
|
||||||
if verbosity >= 2:
|
if verbosity >= 2:
|
||||||
logger.info('Running on ' + platform.platform() + ' ' + platform.release())
|
logger.info('Running on %s %s' % (platform.platform(), platform.release()))
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -323,7 +323,7 @@ class Onionr:
|
|||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
logger.info("Sending message to " + peer)
|
logger.info("Sending message to: " + logger.colors.underline + peer)
|
||||||
self.onionrUtils.sendPM(peer, message)
|
self.onionrUtils.sendPM(peer, message)
|
||||||
|
|
||||||
|
|
||||||
@ -355,6 +355,7 @@ class Onionr:
|
|||||||
'''
|
'''
|
||||||
Adds a Onionr node address
|
Adds a Onionr node address
|
||||||
'''
|
'''
|
||||||
|
|
||||||
try:
|
try:
|
||||||
newAddress = sys.argv[2]
|
newAddress = sys.argv[2]
|
||||||
except:
|
except:
|
||||||
@ -374,22 +375,25 @@ class Onionr:
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
try:
|
||||||
messageToAdd = logger.readline('Broadcast message to network: ')
|
messageToAdd = logger.readline('Broadcast message to network: ')
|
||||||
if len(messageToAdd) >= 1:
|
if len(messageToAdd) >= 1:
|
||||||
break
|
break
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
return
|
||||||
|
|
||||||
#addedHash = self.onionrCore.setData(messageToAdd)
|
#addedHash = self.onionrCore.setData(messageToAdd)
|
||||||
addedHash = self.onionrCore.insertBlock(messageToAdd, header='txt')
|
addedHash = self.onionrCore.insertBlock(messageToAdd, header='txt')
|
||||||
#self.onionrCore.addToBlockDB(addedHash, selfInsert=True)
|
#self.onionrCore.addToBlockDB(addedHash, selfInsert=True)
|
||||||
#self.onionrCore.setBlockType(addedHash, 'txt')
|
#self.onionrCore.setBlockType(addedHash, 'txt')
|
||||||
logger.info("inserted your message as block: " + addedHash)
|
logger.info("Message inserted as as block %s" % addedHash)
|
||||||
return
|
return
|
||||||
|
|
||||||
def getPMs(self):
|
def getPMs(self):
|
||||||
'''
|
'''
|
||||||
display PMs sent to us
|
display PMs sent to us
|
||||||
'''
|
'''
|
||||||
|
|
||||||
self.onionrUtils.loadPMs()
|
self.onionrUtils.loadPMs()
|
||||||
|
|
||||||
def enablePlugin(self):
|
def enablePlugin(self):
|
||||||
@ -399,10 +403,10 @@ class Onionr:
|
|||||||
|
|
||||||
if len(sys.argv) >= 3:
|
if len(sys.argv) >= 3:
|
||||||
plugin_name = sys.argv[2]
|
plugin_name = sys.argv[2]
|
||||||
logger.info('Enabling plugin \"' + plugin_name + '\"...')
|
logger.info('Enabling plugin "%s"...' % plugin_name)
|
||||||
plugins.enable(plugin_name, self)
|
plugins.enable(plugin_name, self)
|
||||||
else:
|
else:
|
||||||
logger.info(sys.argv[0] + ' ' + sys.argv[1] + ' <plugin>')
|
logger.info('%s %s <plugin>' % (sys.argv[0], sys.argv[1]))
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -413,10 +417,10 @@ class Onionr:
|
|||||||
|
|
||||||
if len(sys.argv) >= 3:
|
if len(sys.argv) >= 3:
|
||||||
plugin_name = sys.argv[2]
|
plugin_name = sys.argv[2]
|
||||||
logger.info('Disabling plugin \"' + plugin_name + '\"...')
|
logger.info('Disabling plugin "%s"...' % plugin_name)
|
||||||
plugins.disable(plugin_name, self)
|
plugins.disable(plugin_name, self)
|
||||||
else:
|
else:
|
||||||
logger.info(sys.argv[0] + ' ' + sys.argv[1] + ' <plugin>')
|
logger.info('%s %s <plugin>' % (sys.argv[0], sys.argv[1]))
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -427,7 +431,7 @@ class Onionr:
|
|||||||
|
|
||||||
if len(sys.argv) >= 3:
|
if len(sys.argv) >= 3:
|
||||||
plugin_name = sys.argv[2]
|
plugin_name = sys.argv[2]
|
||||||
logger.info('Reloading plugin \"' + plugin_name + '\"...')
|
logger.info('Reloading plugin "%s"...' % plugin_name)
|
||||||
plugins.stop(plugin_name, self)
|
plugins.stop(plugin_name, self)
|
||||||
plugins.start(plugin_name, self)
|
plugins.start(plugin_name, self)
|
||||||
else:
|
else:
|
||||||
@ -446,21 +450,21 @@ class Onionr:
|
|||||||
plugin_name = re.sub('[^0-9a-zA-Z]+', '', str(sys.argv[2]).lower())
|
plugin_name = re.sub('[^0-9a-zA-Z]+', '', str(sys.argv[2]).lower())
|
||||||
|
|
||||||
if not plugins.exists(plugin_name):
|
if not plugins.exists(plugin_name):
|
||||||
logger.info('Creating plugin \"' + plugin_name + '\"...')
|
logger.info('Creating plugin "%s"...' % plugin_name)
|
||||||
|
|
||||||
os.makedirs(plugins.get_plugins_folder(plugin_name))
|
os.makedirs(plugins.get_plugins_folder(plugin_name))
|
||||||
with open(plugins.get_plugins_folder(plugin_name) + '/main.py', 'a') as main:
|
with open(plugins.get_plugins_folder(plugin_name) + '/main.py', 'a') as main:
|
||||||
main.write(open('static-data/default_plugin.txt').read().replace('$user', os.getlogin()).replace('$date', datetime.datetime.now().strftime('%Y-%m-%d')))
|
main.write(open('static-data/default_plugin.txt').read().replace('$user', os.getlogin()).replace('$date', datetime.datetime.now().strftime('%Y-%m-%d')))
|
||||||
|
|
||||||
logger.info('Enabling plugin \"' + plugin_name + '\"...')
|
logger.info('Enabling plugin "%s"...' % plugin_name)
|
||||||
plugins.enable(plugin_name, self)
|
plugins.enable(plugin_name, self)
|
||||||
else:
|
else:
|
||||||
logger.warn('Cannot create plugin directory structure; plugin "' + plugin_name + '" exists.')
|
logger.warn('Cannot create plugin directory structure; plugin "%s" exists.' % plugin_name)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error('Failed to create plugin directory structure.', e)
|
logger.error('Failed to create plugin directory structure.', e)
|
||||||
else:
|
else:
|
||||||
logger.info(sys.argv[0] + ' ' + sys.argv[1] + ' <plugin>')
|
logger.info('%s %s <plugin>' % (sys.argv[0], sys.argv[1]))
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user