This commit is contained in:
Phill Ridout 2015-01-22 15:05:03 +00:00
parent d6b8cd1d2a
commit 833c6fb800
3 changed files with 41 additions and 16 deletions

View File

@ -269,6 +269,29 @@ class OpenLP(OpenLPMixin, QtGui.QApplication):
else:
return QtGui.QApplication.event(self, event)
def parse_options(args):
"""
Parse the command line arguments
:param args: list of command line arguments
:return: a tuple of parsed options of type optparse.Value and a list of remaining argsZ
"""
print(args)
print(sys.argv)
# Set up command line options.
usage = 'Usage: %prog [options] [qt-options]'
parser = OptionParser(usage=usage)
parser.add_option('-e', '--no-error-form', dest='no_error_form', action='store_true',
help='Disable the error notification form.')
parser.add_option('-l', '--log-level', dest='loglevel', default='warning', metavar='LEVEL',
help='Set logging to LEVEL level. Valid values are "debug", "info", "warning".')
parser.add_option('-p', '--portable', dest='portable', action='store_true',
help='Specify if this should be run as a 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', help='Set the Qt4 style (passed directly to Qt4).')
# Parse command line options and deal with them. Use args supplied pragmatically if possible.
return parser.parse_args(args) if args else parser.parse_args()
def set_up_logging(log_path):
"""
@ -291,21 +314,7 @@ def main(args=None):
:param args: Some args
"""
# Set up command line options.
usage = 'Usage: %prog [options] [qt-options]'
parser = OptionParser(usage=usage)
parser.add_option('-e', '--no-error-form', dest='no_error_form', action='store_true',
help='Disable the error notification form.')
parser.add_option('-l', '--log-level', dest='loglevel', default='warning', metavar='LEVEL',
help='Set logging to LEVEL level. Valid values are "debug", "info", "warning".')
parser.add_option('-p', '--portable', dest='portable', action='store_true',
help='Specify if this should be run as a 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', help='Set the Qt4 style (passed directly to Qt4).')
# Parse command line options and deal with them.
# Use args supplied pragmatically if possible.
(options, args) = parser.parse_args(args) if args else parser.parse_args()
(options, args) = parse_options(args)
qt_args = []
if options.loglevel.lower() in ['d', 'debug']:
log.setLevel(logging.DEBUG)

View File

@ -146,6 +146,7 @@ class PresentationPlugin(Plugin):
"""
Perform tasks on application startup.
"""
# TODO: Can be removed when the upgrade path from 2.0.x to 2.2.x is no longer needed
super().app_startup()
files_from_config = Settings().value('presentations/presentations files')
for file in files_from_config:

View File

@ -29,13 +29,14 @@
"""
Package to test the openlp.core.__init__ package.
"""
from optparse import Values
import os
from unittest import TestCase
from unittest.mock import MagicMock, patch
from PyQt4 import QtCore, QtGui
from openlp.core import OpenLP
from openlp.core import OpenLP, parse_options
from openlp.core.common import Settings
from tests.helpers.testmixin import TestMixin
@ -119,3 +120,17 @@ class TestInit(TestCase, TestMixin):
# THEN: It should ask if we want to create a backup
self.assertEqual(Settings().value('core/application version'), '2.2.0', 'Version should be upgraded!')
self.assertEqual(mocked_question.call_count, 1, 'A question should have been asked!')
def parse_options_short_options_test(self):
"""
Test that parse_options parses short options correctly
"""
# GIVEN: A list of vaild short options
options = ['-e', 'extra', '-l', 'debug', 'qt', '-pd', 'args', '-s', 'style']
# WHEN: Calling parse_options
resluts = parse_options(options)
# THEN: A tuple should be returned with the parsed options and left over args
self.assertEqual(resluts, (Values({'no_error_form': True, 'dev_version': True, 'portable': True,
'style': 'style', 'loglevel': 'debug'}),['extra', 'qt', 'args']))