From 711c24668779963d8a75d5a0c040e70b3f0446be Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Thu, 24 Mar 2011 17:43:08 +0100 Subject: [PATCH 1/4] clean up --- openlp/core/ui/printservicedialog.py | 14 ++++++-------- openlp/core/utils/__init__.py | 8 +++----- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/openlp/core/ui/printservicedialog.py b/openlp/core/ui/printservicedialog.py index 41101e8ff..3d49533dd 100644 --- a/openlp/core/ui/printservicedialog.py +++ b/openlp/core/ui/printservicedialog.py @@ -64,8 +64,7 @@ class Ui_PrintServiceDialog(object): 'Options')) self.optionsButton.setToolButtonStyle( QtCore.Qt.ToolButtonTextBesideIcon) - self.optionsButton.setIcon(QtGui.QIcon( - build_icon(u':/system/system_configure.png'))) + self.optionsButton.setIcon(build_icon(u':/system/system_configure.png')) self.optionsButton.setCheckable(True) self.toolbar.addWidget(self.optionsButton) self.closeButton = self.toolbar.addAction( @@ -80,24 +79,23 @@ class Ui_PrintServiceDialog(object): translate('OpenLP.PrintServiceForm', 'Copy as HTML')) self.toolbar.addSeparator() self.zoomInButton = QtGui.QToolButton(self.toolbar) - self.zoomInButton.setIcon(QtGui.QIcon( - build_icon(u':/general/general_zoom_in.png'))) + self.zoomInButton.setIcon(build_icon(u':/general/general_zoom_in.png')) self.zoomInButton.setToolTip(translate('OpenLP.PrintServiceForm', 'Zoom In')) self.zoomInButton.setObjectName(u'zoomInButton') self.zoomInButton.setIconSize(QtCore.QSize(22, 22)) self.toolbar.addWidget(self.zoomInButton) self.zoomOutButton = QtGui.QToolButton(self.toolbar) - self.zoomOutButton.setIcon(QtGui.QIcon( - build_icon(u':/general/general_zoom_out.png'))) + self.zoomOutButton.setIcon( + build_icon(u':/general/general_zoom_out.png')) self.zoomOutButton.setToolTip(translate('OpenLP.PrintServiceForm', 'Zoom Out')) self.zoomOutButton.setObjectName(u'zoomOutButton') self.zoomOutButton.setIconSize(QtCore.QSize(22, 22)) self.toolbar.addWidget(self.zoomOutButton) self.zoomOriginalButton = QtGui.QToolButton(self.toolbar) - self.zoomOriginalButton.setIcon(QtGui.QIcon( - build_icon(u':/general/general_zoom_original.png'))) + self.zoomOriginalButton.setIcon( + build_icon(u':/general/general_zoom_original.png')) self.zoomOriginalButton.setToolTip(translate('OpenLP.PrintServiceForm', 'Zoom Original')) self.zoomOriginalButton.setObjectName(u'zoomOriginalButton') diff --git a/openlp/core/utils/__init__.py b/openlp/core/utils/__init__.py index 54b48cdf6..4ee2e84e0 100644 --- a/openlp/core/utils/__init__.py +++ b/openlp/core/utils/__init__.py @@ -44,7 +44,7 @@ if sys.platform != u'win32' and sys.platform != u'darwin': XDG_BASE_AVAILABLE = False import openlp -from openlp.core.lib import Receiver, translate +from openlp.core.lib import Receiver, translate, check_directory_exists log = logging.getLogger(__name__) IMAGES_FILTER = None @@ -146,8 +146,7 @@ class AppLocation(object): Return the path OpenLP stores all its data under. """ path = AppLocation.get_directory(AppLocation.DataDir) - if not os.path.exists(path): - os.makedirs(path) + check_directory_exists(path) return path @staticmethod @@ -157,8 +156,7 @@ class AppLocation(object): """ data_path = AppLocation.get_data_path() path = os.path.join(data_path, section) - if not os.path.exists(path): - os.makedirs(path) + check_directory_exists(path) return path def _get_os_dir_path(dir_type): From 67ee8394c21a5adec83e97aed10444f9270c6131 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Thu, 24 Mar 2011 20:12:27 +0100 Subject: [PATCH 2/4] moved version function --- openlp.pyw | 85 ++------------------------ openlp/.version | 2 +- openlp/core/lib/plugin.py | 6 +- openlp/core/ui/slidecontroller.py | 1 + openlp/core/utils/__init__.py | 87 +++++++++++++++++++++++++++ openlp/plugins/media/lib/mediaitem.py | 4 +- openlp/plugins/songs/lib/xml.py | 5 +- 7 files changed, 103 insertions(+), 87 deletions(-) diff --git a/openlp.pyw b/openlp.pyw index af3908c30..717ea27f9 100755 --- a/openlp.pyw +++ b/openlp.pyw @@ -29,7 +29,6 @@ import sys import logging from optparse import OptionParser from traceback import format_exception -from subprocess import Popen, PIPE from PyQt4 import QtCore, QtGui @@ -40,7 +39,8 @@ from openlp.core.ui.firsttimelanguageform import FirstTimeLanguageForm from openlp.core.ui.firsttimeform import FirstTimeForm from openlp.core.ui.exceptionform import ExceptionForm from openlp.core.ui import SplashScreen, ScreenList -from openlp.core.utils import AppLocation, LanguageManager, VersionThread +from openlp.core.utils import AppLocation, LanguageManager, VersionThread, \ + get_application_version log = logging.getLogger() @@ -73,89 +73,12 @@ class OpenLP(QtGui.QApplication): """ log.info(u'OpenLP Application Loaded') - def _get_version(self): - """ - Load and store current Application Version - """ - if u'--dev-version' in sys.argv or u'-d' in sys.argv: - # If we're running the dev version, let's use bzr to get the version - try: - # If bzrlib is availble, use it - from bzrlib.branch import Branch - b = Branch.open_containing('.')[0] - b.lock_read() - try: - # Get the branch's latest revision number. - revno = b.revno() - # Convert said revision number into a bzr revision id. - revision_id = b.dotted_revno_to_revision_id((revno,)) - # Get a dict of tags, with the revision id as the key. - tags = b.tags.get_reverse_tag_dict() - # Check if the latest - if revision_id in tags: - full_version = u'%s' % tags[revision_id][0] - else: - full_version = '%s-bzr%s' % \ - (sorted(b.tags.get_tag_dict().keys())[-1], revno) - finally: - b.unlock() - except: - # Otherwise run the command line bzr client - bzr = Popen((u'bzr', u'tags', u'--sort', u'time'), stdout=PIPE) - output, error = bzr.communicate() - code = bzr.wait() - if code != 0: - raise Exception(u'Error running bzr tags') - lines = output.splitlines() - if len(lines) == 0: - tag = u'0.0.0' - revision = u'0' - else: - tag, revision = lines[-1].split() - bzr = Popen((u'bzr', u'log', u'--line', u'-r', u'-1'), - stdout=PIPE) - output, error = bzr.communicate() - code = bzr.wait() - if code != 0: - raise Exception(u'Error running bzr log') - latest = output.split(u':')[0] - full_version = latest == revision and tag or \ - u'%s-bzr%s' % (tag, latest) - else: - # We're not running the development version, let's use the file - filepath = AppLocation.get_directory(AppLocation.VersionDir) - filepath = os.path.join(filepath, u'.version') - fversion = None - try: - fversion = open(filepath, u'r') - full_version = unicode(fversion.read()).rstrip() - except IOError: - log.exception('Error in version file.') - full_version = u'0.0.0-bzr000' - finally: - if fversion: - fversion.close() - bits = full_version.split(u'-') - app_version = { - u'full': full_version, - u'version': bits[0], - u'build': bits[1] if len(bits) > 1 else None - } - if app_version[u'build']: - log.info( - u'Openlp version %s build %s', - app_version[u'version'], - app_version[u'build'] - ) - else: - log.info(u'Openlp version %s' % app_version[u'version']) - return app_version - def run(self): """ Run the OpenLP application. """ - app_version = self._get_version() + app_version = get_application_version( + u'--dev-version' in sys.argv or u'-d' in sys.argv) # provide a listener for widgets to reqest a screen update. QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'openlp_process_events'), self.processEvents) diff --git a/openlp/.version b/openlp/.version index ae8249b9a..4543cdd14 100644 --- a/openlp/.version +++ b/openlp/.version @@ -1 +1 @@ -1.9.2-bzr987 \ No newline at end of file +1.9.4-bzr1416 \ No newline at end of file diff --git a/openlp/core/lib/plugin.py b/openlp/core/lib/plugin.py index 6195cb248..72d51ca1d 100644 --- a/openlp/core/lib/plugin.py +++ b/openlp/core/lib/plugin.py @@ -32,6 +32,7 @@ from PyQt4 import QtCore from openlp.core.lib import Receiver from openlp.core.lib.ui import UiStrings +from openlp.core.utils import get_application_version log = logging.getLogger(__name__) @@ -145,7 +146,10 @@ class Plugin(QtCore.QObject): self.textStrings = {} self.setPluginTextStrings() self.nameStrings = self.textStrings[StringContent.Name] - self.version = version if version else u'1.9.4' + if version: + self.version = version + else: + self.version = get_application_version()[u'version'] self.settingsSection = self.name.lower() self.icon = None self.mediaItemClass = mediaItemClass diff --git a/openlp/core/ui/slidecontroller.py b/openlp/core/ui/slidecontroller.py index ae0c52273..ad6143796 100644 --- a/openlp/core/ui/slidecontroller.py +++ b/openlp/core/ui/slidecontroller.py @@ -46,6 +46,7 @@ class SlideList(QtGui.QTableWidget): QtGui.QTableWidget.__init__(self, parent.controller) self.parent = parent + class SlideController(QtGui.QWidget): """ SlideController is the slide controller widget. This widget is what the diff --git a/openlp/core/utils/__init__.py b/openlp/core/utils/__init__.py index 4ee2e84e0..60dd4b920 100644 --- a/openlp/core/utils/__init__.py +++ b/openlp/core/utils/__init__.py @@ -33,6 +33,7 @@ import sys import time import urllib2 from datetime import datetime +from subprocess import Popen, PIPE from PyQt4 import QtGui, QtCore @@ -50,6 +51,7 @@ log = logging.getLogger(__name__) IMAGES_FILTER = None UNO_CONNECTION_TYPE = u'pipe' #UNO_CONNECTION_TYPE = u'socket' +APPLICATION_VERSION = u'' class VersionThread(QtCore.QThread): """ @@ -206,6 +208,91 @@ def _get_frozen_path(frozen_option, non_frozen_option): return frozen_option return non_frozen_option +def get_application_version(dev_version=False): + """ + Returns the application version of the running instance of OpenLP:: + + {u'full': u'1.9.4-bzr1249', u'version': u'1.9.4', u'build': u'bzr1249'} + + ``dev_version`` + If ``True``, then it is assumed, that we are running a dev version and + attempt to receive the version number using bzr. **Note**, that this + argument is only important the first time the function is called. + """ + global APPLICATION_VERSION + if APPLICATION_VERSION: + # We already know the version, so just return it. + return APPLICATION_VERSION + if dev_version: + # If we're running the dev version, let's use bzr to get the version. + try: + # If bzrlib is available, use it. + from bzrlib.branch import Branch + b = Branch.open_containing('.')[0] + b.lock_read() + try: + # Get the branch's latest revision number. + revno = b.revno() + # Convert said revision number into a bzr revision id. + revision_id = b.dotted_revno_to_revision_id((revno,)) + # Get a dict of tags, with the revision id as the key. + tags = b.tags.get_reverse_tag_dict() + # Check if the latest + if revision_id in tags: + full_version = u'%s' % tags[revision_id][0] + else: + full_version = '%s-bzr%s' % \ + (sorted(b.tags.get_tag_dict().keys())[-1], revno) + finally: + b.unlock() + except: + # Otherwise run the command line bzr client. + bzr = Popen((u'bzr', u'tags', u'--sort', u'time'), stdout=PIPE) + output, error = bzr.communicate() + code = bzr.wait() + if code != 0: + raise Exception(u'Error running bzr tags') + lines = output.splitlines() + if len(lines) == 0: + tag = u'0.0.0' + revision = u'0' + else: + tag, revision = lines[-1].split() + bzr = Popen((u'bzr', u'log', u'--line', u'-r', u'-1'), stdout=PIPE) + output, error = bzr.communicate() + code = bzr.wait() + if code != 0: + raise Exception(u'Error running bzr log') + latest = output.split(u':')[0] + full_version = latest == revision and tag or \ + u'%s-bzr%s' % (tag, latest) + else: + # We're not running the development version, let's use the file. + filepath = AppLocation.get_directory(AppLocation.VersionDir) + filepath = os.path.join(filepath, u'.version') + fversion = None + try: + fversion = open(filepath, u'r') + full_version = unicode(fversion.read()).rstrip() + except IOError: + log.exception('Error in version file.') + full_version = u'0.0.0-bzr000' + finally: + if fversion: + fversion.close() + bits = full_version.split(u'-') + APPLICATION_VERSION = { + u'full': full_version, + u'version': bits[0], + u'build': bits[1] if len(bits) > 1 else None + } + if APPLICATION_VERSION[u'build']: + log.info(u'Openlp version %s build %s', + APPLICATION_VERSION[u'version'], APPLICATION_VERSION[u'build']) + else: + log.info(u'Openlp version %s' % APPLICATION_VERSION[u'version']) + return APPLICATION_VERSION + def check_latest_version(current_version): """ Check the latest version of OpenLP against the version file on the OpenLP diff --git a/openlp/plugins/media/lib/mediaitem.py b/openlp/plugins/media/lib/mediaitem.py index 8a1bc2b76..8118e08d7 100644 --- a/openlp/plugins/media/lib/mediaitem.py +++ b/openlp/plugins/media/lib/mediaitem.py @@ -36,7 +36,7 @@ from openlp.core.lib.ui import UiStrings, critical_error_message_box from PyQt4.phonon import Phonon log = logging.getLogger(__name__) - + class MediaMediaItem(MediaManagerItem): """ This is the custom media manager item for Media Slides. @@ -182,7 +182,7 @@ class MediaMediaItem(MediaManagerItem): if (datetime.now() - start).seconds > 5: return False return True - + def initialise(self): self.listView.clear() self.listView.setIconSize(QtCore.QSize(88, 50)) diff --git a/openlp/plugins/songs/lib/xml.py b/openlp/plugins/songs/lib/xml.py index 0bf64c6fa..f98d50098 100644 --- a/openlp/plugins/songs/lib/xml.py +++ b/openlp/plugins/songs/lib/xml.py @@ -68,6 +68,7 @@ from lxml import etree, objectify from openlp.plugins.songs.lib import clean_song, VerseType from openlp.plugins.songs.lib.db import Author, Book, Song, Topic +from openlp.core.utils import get_application_version log = logging.getLogger(__name__) @@ -230,8 +231,8 @@ class OpenLyrics(object): # Append the necessary meta data to the song. song_xml.set(u'xmlns', u'http://openlyrics.info/namespace/2009/song') song_xml.set(u'version', OpenLyrics.IMPLEMENTED_VERSION) - song_xml.set(u'createdIn', u'OpenLP 1.9.4') # Use variable - song_xml.set(u'modifiedIn', u'OpenLP 1.9.4') # Use variable + song_xml.set(u'createdIn', get_application_version()[u'version']) + song_xml.set(u'modifiedIn', get_application_version()[u'version']) song_xml.set(u'modifiedDate', datetime.datetime.now().strftime(u'%Y-%m-%dT%H:%M:%S')) properties = etree.SubElement(song_xml, u'properties') From 24b58ff518bbd772ab7213d171c3960dce921868 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Fri, 25 Mar 2011 17:29:39 +0100 Subject: [PATCH 3/4] fixed application version --- openlp.pyw | 8 +++----- openlp/core/ui/aboutform.py | 11 ++++++----- openlp/core/ui/mainwindow.py | 10 ++++------ openlp/core/utils/__init__.py | 20 +++++++------------- 4 files changed, 20 insertions(+), 29 deletions(-) diff --git a/openlp.pyw b/openlp.pyw index 96871ad79..f9c92dc44 100755 --- a/openlp.pyw +++ b/openlp.pyw @@ -71,7 +71,6 @@ class OpenLP(QtGui.QApplication): The core application class. This class inherits from Qt's QApplication class in order to provide the core of the application. """ - app_version = None def run(self): """ @@ -103,8 +102,7 @@ class OpenLP(QtGui.QApplication): # make sure Qt really display the splash screen self.processEvents() # start the main app window - self.mainWindow = MainWindow(screens, self.app_version, - self.clipboard()) + self.mainWindow = MainWindow(screens, self.clipboard()) self.mainWindow.show() if show_splash: # now kill the splashscreen @@ -116,7 +114,7 @@ class OpenLP(QtGui.QApplication): update_check = QtCore.QSettings().value( u'general/update check', QtCore.QVariant(True)).toBool() if update_check: - VersionThread(self.mainWindow, self.app_version).start() + VersionThread(self.mainWindow).start() return self.exec_() def hookException(self, exctype, value, traceback): @@ -194,7 +192,7 @@ def main(): app.setOrganizationName(u'OpenLP') app.setOrganizationDomain(u'openlp.org') app.setApplicationName(u'OpenLP') - app.setApplicationVersion(app.get_version()[u'version']) + app.setApplicationVersion(get_application_version()[u'version']) # First time checks in settings if not QtCore.QSettings().value(u'general/has run wizard', QtCore.QVariant(False)).toBool(): diff --git a/openlp/core/ui/aboutform.py b/openlp/core/ui/aboutform.py index 5c26167e3..4112cfd8f 100644 --- a/openlp/core/ui/aboutform.py +++ b/openlp/core/ui/aboutform.py @@ -28,25 +28,26 @@ from PyQt4 import QtCore, QtGui from aboutdialog import Ui_AboutDialog from openlp.core.lib import translate +from openlp.core.utils import get_application_version class AboutForm(QtGui.QDialog, Ui_AboutDialog): """ The About dialog """ - def __init__(self, parent, applicationVersion): + def __init__(self, parent): """ Do some initialisation stuff """ QtGui.QDialog.__init__(self, parent) - self.applicationVersion = applicationVersion + applicationVersion = get_application_version() self.setupUi(self) about_text = self.aboutTextEdit.toPlainText() about_text = about_text.replace(u'', - self.applicationVersion[u'version']) - if self.applicationVersion[u'build']: + applicationVersion[u'version']) + if applicationVersion[u'build']: build_text = unicode(translate('OpenLP.AboutForm', ' build %s')) % \ - self.applicationVersion[u'build'] + applicationVersion[u'build'] else: build_text = u'' about_text = about_text.replace(u'', build_text) diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index e421edd98..b8dfc35f5 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -38,7 +38,7 @@ from openlp.core.ui import AboutForm, SettingsForm, ServiceManager, \ ThemeManager, SlideController, PluginForm, MediaDockManager, \ ShortcutListForm, DisplayTagForm from openlp.core.utils import AppLocation, add_actions, LanguageManager, \ - ActionList + ActionList, get_application_version log = logging.getLogger(__name__) @@ -469,14 +469,13 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): actionList = ActionList() - def __init__(self, screens, applicationVersion, clipboard): + def __init__(self, screens, clipboard): """ This constructor sets up the interface, the various managers, and the plugins. """ QtGui.QMainWindow.__init__(self) self.screens = screens - self.applicationVersion = applicationVersion self.clipboard = clipboard # Set up settings sections for the main application # (not for use by plugins) @@ -487,7 +486,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): self.serviceNotSaved = False self.actionList = ActionList() self.settingsmanager = SettingsManager(screens) - self.aboutForm = AboutForm(self, applicationVersion) + self.aboutForm = AboutForm(self) self.settingsForm = SettingsForm(self.screens, self, self) self.displayTagForm = DisplayTagForm(self) self.shortcutForm = ShortcutListForm(self) @@ -651,7 +650,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): 'version from http://openlp.org/.')) QtGui.QMessageBox.question(self, translate('OpenLP.MainWindow', 'OpenLP Version Updated'), - version_text % (version, self.applicationVersion[u'full'])) + version_text % (version, get_application_version()[u'full'])) def show(self): """ @@ -734,7 +733,6 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): """ Show the About form """ - self.aboutForm.applicationVersion = self.applicationVersion self.aboutForm.exec_() def onPluginItemClicked(self): diff --git a/openlp/core/utils/__init__.py b/openlp/core/utils/__init__.py index 22c56e7c1..3c639297e 100644 --- a/openlp/core/utils/__init__.py +++ b/openlp/core/utils/__init__.py @@ -48,19 +48,18 @@ import openlp from openlp.core.lib import Receiver, translate, check_directory_exists log = logging.getLogger(__name__) +APPLICATION_VERSION = {} IMAGES_FILTER = None UNO_CONNECTION_TYPE = u'pipe' #UNO_CONNECTION_TYPE = u'socket' -APPLICATION_VERSION = u'' class VersionThread(QtCore.QThread): """ A special Qt thread class to fetch the version of OpenLP from the website. This is threaded so that it doesn't affect the loading time of OpenLP. """ - def __init__(self, parent, app_version): + def __init__(self, parent): QtCore.QThread.__init__(self, parent) - self.app_version = app_version self.version_splitter = re.compile( r'([0-9]+).([0-9]+).([0-9]+)(?:-bzr([0-9]+))?') @@ -70,7 +69,8 @@ class VersionThread(QtCore.QThread): """ time.sleep(1) Receiver.send_message(u'maindisplay_blank_check') - version = check_latest_version(self.app_version) + app_version = get_application_version() + version = check_latest_version(app_version) remote_version = {} local_version = {} match = self.version_splitter.match(version) @@ -82,7 +82,7 @@ class VersionThread(QtCore.QThread): remote_version[u'revision'] = int(match.group(4)) else: return - match = self.version_splitter.match(self.app_version[u'full']) + match = self.version_splitter.match(app_version[u'full']) if match: local_version[u'major'] = int(match.group(1)) local_version[u'minor'] = int(match.group(2)) @@ -208,22 +208,16 @@ def _get_frozen_path(frozen_option, non_frozen_option): return frozen_option return non_frozen_option -def get_application_version(dev_version=False): +def get_application_version(): """ Returns the application version of the running instance of OpenLP:: {u'full': u'1.9.4-bzr1249', u'version': u'1.9.4', u'build': u'bzr1249'} - - ``dev_version`` - If ``True``, then it is assumed, that we are running a dev version and - attempt to receive the version number using bzr. **Note**, that this - argument is only important the first time the function is called. """ global APPLICATION_VERSION if APPLICATION_VERSION: - # We already know the version, so just return it. return APPLICATION_VERSION - if dev_version: + if u'--dev-version' in sys.argv or u'-d' in sys.argv: # If we're running the dev version, let's use bzr to get the version. try: # If bzrlib is available, use it. From ad1d57faab933a7d04861462b441c91a6475495e Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Fri, 25 Mar 2011 19:49:53 +0100 Subject: [PATCH 4/4] fixed version file --- openlp/.version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openlp/.version b/openlp/.version index 4543cdd14..998994b7f 100644 --- a/openlp/.version +++ b/openlp/.version @@ -1 +1 @@ -1.9.4-bzr1416 \ No newline at end of file +1.9.5-bzr1421 \ No newline at end of file