Skip to content

Commit

Permalink
Unbelievably complex to wrap logger calls usefully
Browse files Browse the repository at this point in the history
  • Loading branch information
etotheipi committed Jul 14, 2012
1 parent 8bb9d05 commit 913cf8a
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 25 deletions.
5 changes: 3 additions & 2 deletions ArmoryQt.py
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ def checkForLatestVersion(self, wasRequested=False):

optChkVer = self.settings.getSettingOrSetDefault('CheckVersion', 'Always')
if optChkVer.lower()=='never' and not wasRequested:
LOGINFO('User requested never check for new versions', optChkVer)
LOGINFO('User requested never check for new versions')
return

if wasRequested and not self.internetAvail:
Expand Down Expand Up @@ -792,7 +792,8 @@ def popNextLine(currIdx):
return None


thisVerString = getVersionString(BTCARMORY_VERSION)
#thisVerString = getVersionString(BTCARMORY_VERSION)
thisVerString = '0.80'
changeLog = []
vernum = ''

Expand Down
74 changes: 67 additions & 7 deletions armoryengine.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,12 +273,72 @@ class CompressedKeyError(Exception): pass
# Setup logging to write INFO+ to file, and WARNING+ to console
# In debug mode, will write DEBUG+ to file and INFO+ to console
#
LOGDEBUG = logging.debug
LOGINFO = logging.info
LOGWARN = logging.warning
LOGERROR = logging.error
LOGCRIT = logging.critical
LOGEXCEPT= logging.exception

# Want to get the line in which an error was triggered, but by wrapping
# the logger function (as I will below), the displayed "file:linenum"
# references the logger function, not the function that called it.
# So I use traceback to find the file and line number two up in the
# stack trace, and return that to be displayed instead of default
# [Is this a hack? Yes and no. I see no other way to do this]
def getCallerLine():
stkTwoUp = traceback.extract_stack()[-3]
filename,method = stkTwoUp[0], stkTwoUp[1]
return '%s:%d' % (os.path.basename(filename),method)

# When there's an error in the logging function, it's impossible to find!
# These wrappers will print the full stack so that it's possible to find
# which line triggered the error
def LOGDEBUG(msg, *a):
try:
logstr = msg % a
callerStr = getCallerLine() + ' - '
logging.debug(callerStr + logstr)
except TypeError:
traceback.print_stack()
raise

def LOGINFO(msg, *a):
try:
logstr = msg % a
callerStr = getCallerLine() + ' - '
logging.info(callerStr + logstr)
except TypeError:
traceback.print_stack()
raise
def LOGWARN(msg, *a):
try:
logstr = msg % a
callerStr = getCallerLine() + ' - '
logging.warn(callerStr + logstr)
except TypeError:
traceback.print_stack()
raise
def LOGERROR(msg, *a):
try:
logstr = msg % a
callerStr = getCallerLine() + ' - '
logging.error(callerStr + logstr)
except TypeError:
traceback.print_stack()
raise
def LOGCRIT(msg, *a):
try:
logstr = msg % a
callerStr = getCallerLine() + ' - '
logging.crit(callerStr + logstr)
except TypeError:
traceback.print_stack()
raise
def LOGEXCEPT(msg, *a):
try:
logstr = msg % a
callerStr = getCallerLine() + ' - '
logging.exception(callerStr + logstr)
except TypeError:
traceback.print_stack()
raise



DEFAULT_CONSOLE_LOGTHRESH = logging.WARNING
DEFAULT_FILE_LOGTHRESH = logging.INFO
Expand Down Expand Up @@ -323,7 +383,7 @@ def chopLogFile(filename, size):
# Now set loglevels
DateFormat = '%Y-%m-%d %H:%M'
logging.getLogger('').setLevel(logging.DEBUG)
fileFormatter = logging.Formatter('%(asctime)s (%(levelname)s) -- %(filename)s::%(lineno)d -- %(message)s', \
fileFormatter = logging.Formatter('%(asctime)s (%(levelname)s) -- %(message)s', \
datefmt=DateFormat)
fileHandler = logging.FileHandler(ARMORY_LOG_FILE)
fileHandler.setLevel(DEFAULT_FILE_LOGTHRESH)
Expand Down
36 changes: 20 additions & 16 deletions qtdialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ def verifyInputsBeforeAccept(self):
if kdfUnit.lower()=='kb':
self.kdfBytes = round(float(kdfM)*(1024.0))

LOGINFO('KDF takes %0.2fsec and %dbytes', self.kdfSec, self.kdfBytes)
LOGINFO('KDF takes %0.2f seconds and %d bytes', self.kdfSec, self.kdfBytes)
except:
QMessageBox.critical(self, 'Invalid KDF Parameters', \
'Please specify time with units, such as '
Expand Down Expand Up @@ -3364,7 +3364,7 @@ def __init__(self, parent=None, main=None):
self.btnImport, \
self.btnCreate])
else:
self.btnOkay = QPushButton("Okay!")
self.btnOkay = QPushButton("OK!")
self.connect(self.btnOkay, SIGNAL('clicked()'), self.accept)
buttonBox.addButton(self.btnOkay, QDialogButtonBox.AcceptRole)
frmBtn = makeLayoutFrame('Horiz', [self.chkDnaaIntroDlg, \
Expand Down Expand Up @@ -8463,7 +8463,7 @@ def __init__(self, parent, main):
w,h = tightSizeNChar(fnt, 70)
self.txtbox.setMinimumWidth(w)
self.txtbox.setMinimumHeight(6.2*h)
btnOkay = QPushButton('Okay')
btnOkay = QPushButton('OK')
btnCancel = QPushButton('Cancel')
self.connect(btnOkay, SIGNAL('clicked()'), self.pressOkay)
self.connect(btnCancel, SIGNAL('clicked()'), self.pressCancel)
Expand Down Expand Up @@ -9943,34 +9943,35 @@ class DlgVersionNotify(ArmoryDialog):
def __init__(self, parent, main, changelog, wasRequested=False):
super(DlgVersionNotify, self).__init__(parent, main)

self.myVersion = getVersionString(BTCARMORY_VERSION)
#self.myVersion = getVersionString(BTCARMORY_VERSION)
self.myVersion = '0.80'
self.latestVer = changelog[0][0]
lblDescr = QRichLabel('')

if self.myVersion==self.latestVer:
lblDescr = QRichLabel( \
'Your Armory installation is up-to-date!'
'<br><br>'
'<b>Installed Version</b>: %s<br>'
'<b>Installed Version</b>: %s'
'<br><br>'
'When they become available, you can find and download new '
'versions of Armory from: '
'versions of Armory from:<br><br> '
'<a href="http://bitcoinarmory.com/index.php/get-armory">'
'http://bitcoinarmory.com/index.php/get-armory</a> ' % self.myVersion)
else:
lblDescr = QRichLabel( \
'<font size=4><u><b>There is a new version of Armory available!</b></u></font>'
'<font size=4><u><b>There is a new version of Armory available!</b>'
'</u></font>'
'<br><br>'
'<b>Current Version</b>: %s<br>'
'<b>Lastest Version</b>: %s<br><br>'
'<b>Lastest Version</b>: %s'
'<br><br>'
'Please visit the '
'<a href="http://bitcoinarmory.com/index.php/get-armory">Armory '
'download page</a> (http://bitcoinarmory.com/index.php/get-armory) '
'to get the most recent version. '
'Installing over your existing '
'version is perfectly safe. All your wallets and settings '
'will remain untouched through the update process.' % \
(self.myVersion, self.latestVer))
'All your wallets and settings will remain untouched when you '
'reinstall Armory.' % (self.myVersion, self.latestVer))

lblDescr.setOpenExternalLinks(True)
lblDescr.setTextInteractionFlags(Qt.TextSelectableByMouse | \
Expand Down Expand Up @@ -10006,12 +10007,12 @@ def __init__(self, parent, main, changelog, wasRequested=False):
curs.movePosition(QTextCursor.Start)
txtChangeLog.setTextCursor(curs)

btnDNAA = QPushButton('Do not notify me of new versions')
btnDelay = QPushButton('No more reminders until next version')
btnOkay = QPushButton('Okay')
btnDNAA = QPushButton('&Do not notify me of new versions')
btnDelay = QPushButton('&No more reminders until next version')
btnOkay = QPushButton('&OK')
self.connect(btnDNAA, SIGNAL('clicked()'), self.clickDNAA)
self.connect(btnDelay, SIGNAL('clicked()'), self.clickDelay)
self.connect(btnOkay, SIGNAL('clicked()'), self.accept)
self.connect(btnOkay, SIGNAL('clicked()'), self.clickOkay)

frmDescr = makeVertFrame([lblDescr], STYLE_SUNKEN)
frmLog = makeVertFrame([lblChnglog, 'Space(5)', txtChangeLog], STYLE_SUNKEN)
Expand All @@ -10035,6 +10036,9 @@ def clickDelay(self):
self.main.settings.set('CheckVersion', 'v'+self.latestVer)
self.accept()

def clickOkay(self):
self.main.settings.set('CheckVersion', 'Always')
self.accept()



Expand Down
7 changes: 7 additions & 0 deletions versions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
# about the latest version. This is a good way to document progress,
# anyway...

#-------------------------------------------------------------------------------
VERSION 0.83

- Version 0.82.1 is still the latest version
This fake version was added solely for testing the version notification
window. Version 0.83 does not actually exist yet!


#-------------------------------------------------------------------------------
VERSION 0.82.1
Expand Down

0 comments on commit 913cf8a

Please sign in to comment.