moved version function

This commit is contained in:
Andreas Preikschat 2011-03-24 20:12:27 +01:00
parent 711c246687
commit 67ee8394c2
7 changed files with 103 additions and 87 deletions

View File

@ -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)

View File

@ -1 +1 @@
1.9.2-bzr987
1.9.4-bzr1416

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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))

View File

@ -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')