From 20288d4ab420470ab573b470f22c0fbcfe95f77a Mon Sep 17 00:00:00 2001 From: Dmitri Bogomolov <4glitch@gmail.com> Date: Tue, 7 Nov 2017 13:46:23 +0200 Subject: [PATCH] Try to replace copyright year from last commit date --- src/bitmessageqt/dialogs.py | 15 +++++++++++++-- src/bitmessageqt/support.py | 4 ++-- src/paths.py | 17 ++++++++++++----- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/bitmessageqt/dialogs.py b/src/bitmessageqt/dialogs.py index ce1702df..ef22fd3b 100644 --- a/src/bitmessageqt/dialogs.py +++ b/src/bitmessageqt/dialogs.py @@ -113,10 +113,11 @@ class AboutDialog(QtGui.QDialog, RetranslateMixin): def __init__(self, parent=None): super(AboutDialog, self).__init__(parent) widgets.load('about.ui', self) - commit = paths.lastCommit()[:7] + last_commit = paths.lastCommit() version = softwareVersion + commit = last_commit.get('commit') if commit: - version += '-' + commit + version += '-' + commit[:7] self.labelVersion.setText( self.labelVersion.text().replace( ':version:', version @@ -124,6 +125,16 @@ class AboutDialog(QtGui.QDialog, RetranslateMixin): ) self.labelVersion.setOpenExternalLinks(True) + try: + self.label_2.setText( + self.label_2.text().replace( + '2017', str(last_commit.get('time').year) + )) + except AttributeError: + pass + + QtGui.QWidget.resize(self, QtGui.QWidget.sizeHint(self)) + class IconGlossaryDialog(QtGui.QDialog, RetranslateMixin): def __init__(self, parent=None, config=None): diff --git a/src/bitmessageqt/support.py b/src/bitmessageqt/support.py index 03b302e6..db690a2b 100644 --- a/src/bitmessageqt/support.py +++ b/src/bitmessageqt/support.py @@ -85,9 +85,9 @@ def createSupportMessage(myapp): return myapp.ui.comboBoxSendFrom.setCurrentIndex(addrIndex) myapp.ui.lineEditTo.setText(SUPPORT_ADDRESS) - + version = softwareVersion - commit = paths.lastCommit() + commit = paths.lastCommit().get('commit') if commit: version += " GIT " + commit diff --git a/src/paths.py b/src/paths.py index 0f843edf..325fcd8b 100644 --- a/src/paths.py +++ b/src/paths.py @@ -1,5 +1,7 @@ from os import environ, path import sys +import re +from datetime import datetime # When using py2exe or py2app, the variable frozen is added to the sys # namespace. This can be used to setup a different code path for @@ -95,13 +97,18 @@ def tail(f, lines=20): all_read_text = ''.join(reversed(blocks)) return '\n'.join(all_read_text.splitlines()[-total_lines_wanted:]) + def lastCommit(): githeadfile = path.join(codePath(), '..', '.git', 'logs', 'HEAD') - version = "" - if (path.isfile(githeadfile)): + result = {} + if path.isfile(githeadfile): try: with open(githeadfile, 'rt') as githead: - version = tail(githead, 1).split()[1] - except IOError: + line = tail(githead, 1) + result['commit'] = line.split()[1] + result['time'] = datetime.fromtimestamp( + float(re.search(r'>\s*(.*?)\s', line).group(1)) + ) + except (IOError, AttributeError, TypeError): pass - return version + return result