forked from openlp/openlp
Add an option to pull the version directly from Bazaar (for the developers)
This commit is contained in:
parent
bf7df829d0
commit
4dc526b345
90
openlp.pyw
90
openlp.pyw
@ -30,6 +30,7 @@ import sys
|
|||||||
import logging
|
import logging
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
from traceback import format_exception
|
from traceback import format_exception
|
||||||
|
from subprocess import Popen, PIPE
|
||||||
|
|
||||||
from PyQt4 import QtCore, QtGui
|
from PyQt4 import QtCore, QtGui
|
||||||
|
|
||||||
@ -71,23 +72,68 @@ class OpenLP(QtGui.QApplication):
|
|||||||
"""
|
"""
|
||||||
log.info(u'OpenLP Application Loaded')
|
log.info(u'OpenLP Application Loaded')
|
||||||
|
|
||||||
def notify(self, obj, evt):
|
def _get_version(self):
|
||||||
#TODO needed for presentation exceptions
|
|
||||||
return QtGui.QApplication.notify(self, obj, evt)
|
|
||||||
|
|
||||||
def run(self):
|
|
||||||
"""
|
"""
|
||||||
Run the OpenLP application.
|
Load and store current Application Version
|
||||||
"""
|
"""
|
||||||
#Load and store current Application Version
|
if u'--dev-version' 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 = AppLocation.get_directory(AppLocation.VersionDir)
|
||||||
filepath = os.path.join(filepath, u'.version')
|
filepath = os.path.join(filepath, u'.version')
|
||||||
fversion = None
|
fversion = None
|
||||||
try:
|
try:
|
||||||
fversion = open(filepath, u'r')
|
fversion = open(filepath, u'r')
|
||||||
for line in fversion:
|
full_version = unicode(fversion.read()).rstrip()
|
||||||
full_version = unicode(line).rstrip() #\
|
except IOError:
|
||||||
#.replace(u'\r', u'').replace(u'\n', u'')
|
log.exception('Error in version file.')
|
||||||
|
full_version = u'0.0.0-bzr000'
|
||||||
|
finally:
|
||||||
|
if fversion:
|
||||||
|
fversion.close()
|
||||||
bits = full_version.split(u'-')
|
bits = full_version.split(u'-')
|
||||||
app_version = {
|
app_version = {
|
||||||
u'full': full_version,
|
u'full': full_version,
|
||||||
@ -102,16 +148,17 @@ class OpenLP(QtGui.QApplication):
|
|||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
log.info(u'Openlp version %s' % app_version[u'version'])
|
log.info(u'Openlp version %s' % app_version[u'version'])
|
||||||
except IOError:
|
return app_version
|
||||||
log.exception('Error in version file.')
|
|
||||||
app_version = {
|
def notify(self, obj, evt):
|
||||||
u'full': u'1.9.0-bzr000',
|
#TODO needed for presentation exceptions
|
||||||
u'version': u'1.9.0',
|
return QtGui.QApplication.notify(self, obj, evt)
|
||||||
u'build': u'bzr000'
|
|
||||||
}
|
def run(self):
|
||||||
finally:
|
"""
|
||||||
if fversion:
|
Run the OpenLP application.
|
||||||
fversion.close()
|
"""
|
||||||
|
app_version = self._get_version()
|
||||||
#provide a listener for widgets to reqest a screen update.
|
#provide a listener for widgets to reqest a screen update.
|
||||||
QtCore.QObject.connect(Receiver.get_receiver(),
|
QtCore.QObject.connect(Receiver.get_receiver(),
|
||||||
QtCore.SIGNAL(u'openlp_process_events'), self.processEvents)
|
QtCore.SIGNAL(u'openlp_process_events'), self.processEvents)
|
||||||
@ -172,6 +219,9 @@ def main():
|
|||||||
parser.add_option('-p', '--portable', dest='portable',
|
parser.add_option('-p', '--portable', dest='portable',
|
||||||
action='store_true', help='Specify if this should be run as a '
|
action='store_true', help='Specify if this should be run as a '
|
||||||
'portable app, off a USB flash drive (not implemented).')
|
'portable app, off a USB flash drive (not implemented).')
|
||||||
|
parser.add_option('-d', '--dev-version', dest='dev_version',
|
||||||
|
action='store_true', help='Ignore the version file and pull the '
|
||||||
|
'version directly from Bazaar')
|
||||||
parser.add_option('-s', '--style', dest='style',
|
parser.add_option('-s', '--style', dest='style',
|
||||||
help='Set the Qt4 style (passed directly to Qt4).')
|
help='Set the Qt4 style (passed directly to Qt4).')
|
||||||
# Set up logging
|
# Set up logging
|
||||||
|
Loading…
Reference in New Issue
Block a user