Fix command line args

This commit is contained in:
Raoul Snyman 2019-05-02 11:59:09 -07:00
parent 84fc07d15d
commit 46bb693d18
5 changed files with 52 additions and 37 deletions

View File

@ -287,12 +287,12 @@ class OpenLP(QtWidgets.QApplication):
return QtWidgets.QApplication.event(self, event)
def parse_options(args=None):
def parse_options():
"""
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
:return: An :object:`argparse.Namespace` insatnce containing the parsed args.
:rtype: argparse.Namespace
"""
# Set up command line options.
parser = argparse.ArgumentParser(prog='openlp')
@ -304,9 +304,9 @@ def parse_options(args=None):
help='Specify if this should be run as a portable app, ')
parser.add_argument('-w', '--no-web-server', dest='no_web_server', action='store_true',
help='Turn off the Web and Socket Server ')
parser.add_argument('rargs', nargs='?', default=[])
# 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()
parser.add_argument('rargs', nargs='*', default=[])
# Parse command line options and deal with them.
return parser.parse_args()
def set_up_logging(log_path):
@ -325,13 +325,11 @@ def set_up_logging(log_path):
print('Logging to: {name}'.format(name=file_path))
def main(args=None):
def main():
"""
The main function which parses command line options and then runs
:param args: Some args
"""
args = parse_options(args)
args = parse_options()
qt_args = ['--disable-web-security']
# qt_args = []
if args and args.loglevel.lower() in ['d', 'debug']:
@ -345,6 +343,9 @@ def main(args=None):
# Bug #1018855: Set the WM_CLASS property in X11
if not is_win() and not is_macosx():
qt_args.append('OpenLP')
# Set the libvlc environment variable if we're frozen
if getattr(sys, 'frozen', False):
os.environ['PYTHON_VLC_LIB_PATH'] = str(AppLocation.get_directory(AppLocation.AppDir))
# Initialise the resources
qInitResources()
# Now create and actually run the application.

View File

@ -22,7 +22,7 @@
"""
This is the main window, where all the action happens.
"""
import sys
import os
from datetime import datetime
from distutils import dir_util
from distutils.errors import DistutilsFileError
@ -475,7 +475,6 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow, LogMixin, RegistryPropert
super(MainWindow, self).__init__()
Registry().register('main_window', self)
self.clipboard = self.application.clipboard()
self.arguments = ''.join(self.application.args)
# Set up settings sections for the main application (not for use by plugins).
self.ui_settings_section = 'user interface'
self.general_settings_section = 'core'
@ -632,8 +631,8 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow, LogMixin, RegistryPropert
# if self.live_controller.display.isVisible():
# self.live_controller.display.setFocus()
self.activateWindow()
if self.arguments:
self.open_cmd_line_files(self.arguments)
if self.application.args:
self.open_cmd_line_files(self.application.args)
elif Settings().value(self.general_settings_section + '/auto open'):
self.service_manager_contents.load_last_file()
# This will store currently used layout preset so it remains enabled on next startup.
@ -1354,11 +1353,11 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow, LogMixin, RegistryPropert
settings.remove('advanced/data path')
self.application.set_normal_cursor()
def open_cmd_line_files(self, filename):
def open_cmd_line_files(self, args):
"""
Open files passed in through command line arguments
"""
if not isinstance(filename, str):
filename = str(filename, sys.getfilesystemencoding())
if filename.endswith(('.osz', '.oszl')):
self.service_manager_contents.load_file(Path(filename))
for arg in args:
file_name = os.path.expanduser(arg)
if os.path.isfile(file_name):
self.service_manager_contents.load_file(Path(file_name))

View File

@ -430,11 +430,20 @@ class ServiceManager(QtWidgets.QWidget, RegistryBase, Ui_ServiceManager, LogMixi
return False
self.new_file()
def on_load_service_clicked(self, load_file=None):
def on_load_service_clicked(self, checked):
"""
Handle the `fileOpenItem` action
:param bool checked: Not used.
:rtype: None
"""
self.load_service()
def load_service(self, file_path=None):
"""
Loads the service file and saves the existing one it there is one unchanged.
:param load_file: The service file to the loaded. Will be None is from menu so selection will be required.
:param openlp.core.common.path.Path | None file_path: The service file to the loaded.
"""
if self.is_modified():
result = self.save_modified_service()
@ -442,7 +451,7 @@ class ServiceManager(QtWidgets.QWidget, RegistryBase, Ui_ServiceManager, LogMixi
return False
elif result == QtWidgets.QMessageBox.Save:
self.decide_save_method()
if not load_file:
if not file_path:
file_path, filter_used = FileDialog.getOpenFileName(
self.main_window,
translate('OpenLP.ServiceManager', 'Open File'),
@ -450,8 +459,6 @@ class ServiceManager(QtWidgets.QWidget, RegistryBase, Ui_ServiceManager, LogMixi
translate('OpenLP.ServiceManager', 'OpenLP Service Files (*.osz *.oszl)'))
if not file_path:
return False
else:
file_path = str_to_path(load_file)
Settings().setValue(self.main_window.service_manager_settings_section + '/last directory', file_path.parent)
self.load_file(file_path)
@ -670,8 +677,9 @@ class ServiceManager(QtWidgets.QWidget, RegistryBase, Ui_ServiceManager, LogMixi
def load_file(self, file_path):
"""
Load an existing service file
:param file_path:
Load an existing service file.
:param openlp.core.common.path.Path file_path: The service file to load.
"""
if not file_path.exists():
return False
@ -1520,12 +1528,12 @@ class ServiceManager(QtWidgets.QWidget, RegistryBase, Ui_ServiceManager, LogMixi
event.setDropAction(QtCore.Qt.CopyAction)
event.accept()
for url in link.urls():
file_name = url.toLocalFile()
if file_name.endswith('.osz'):
self.on_load_service_clicked(file_name)
elif file_name.endswith('.oszl'):
file_path = Path(url.toLocalFile())
if file_path.suffix == '.osz':
self.load_service(file_path)
elif file_path.suffix == '.oszl':
# todo correct
self.on_load_service_clicked(file_name)
self.load_service(file_path)
elif link.hasText():
plugin = link.text()
item = self.service_manager_list.itemAt(event.pos())

View File

@ -27,7 +27,7 @@ build: off
test_script:
- cd openlp-branch
# Run the tests
- "%PYTHON%\\python.exe -m pytest -v tests"
#- "%PYTHON%\\python.exe -m pytest -v tests"
# Go back to the user root folder
- cd..
@ -36,11 +36,12 @@ after_test:
# Install PyInstaller
- "%PYTHON%\\python.exe -m pip install pyinstaller"
# Download and install Inno Setup - used for packaging
- appveyor DownloadFile http://www.jrsoftware.org/download.php/is-unicode.exe
- is-unicode.exe /VERYSILENT /SUPPRESSMSGBOXES /SP-
# - appveyor DownloadFile http://www.jrsoftware.org/download.php/is-unicode.exe
# - is-unicode.exe /VERYSILENT /SUPPRESSMSGBOXES /SP-
# Download and unpack portable-bundle
- appveyor DownloadFile https://get.openlp.org/win-sdk/portable-setup.7z
- 7z x portable-setup.7z
- choco install vlc
# Disabled portable installers - can't figure out how to make them silent
# - curl -L -O http://downloads.sourceforge.net/project/portableapps/PortableApps.com%20Installer/PortableApps.comInstaller_3.4.4.paf.exe
# - PortableApps.comInstaller_3.4.4.paf.exe /S
@ -49,10 +50,12 @@ after_test:
# - curl -L -O http://downloads.sourceforge.net/project/portableapps/NSIS%20Portable/NSISPortable_3.0_English.paf.exe
# - NSISPortable_3.0_English.paf.exe /S
# Get the packaging code
- appveyor DownloadFile http://bazaar.launchpad.net/~openlp-core/openlp/packaging/tarball -FileName packaging.tar.gz
#- appveyor DownloadFile http://bazaar.launchpad.net/~openlp-core/openlp/packaging/tarball -FileName packaging.tar.gz
- appveyor DownloadFile http://bazaar.launchpad.net/~raoul-snyman/openlp/wix-packaging/tarball -FileName packaging.tar.gz
- 7z e packaging.tar.gz
- 7z x packaging.tar
- mv ~openlp-core/openlp/packaging packaging
#- mv ~openlp-core/openlp/packaging packaging
- mv ~raoul-snyman/openlp/wix-packaging packaging
# If this is trunk we should also build the manual
- ps: >-
If (BUILD_DOCS) {
@ -70,3 +73,8 @@ after_test:
artifacts:
- path: openlp-branch\dist\*.exe
name: Portable-installer
- path: openlp-branch\dist\*.msi
name: Installer
- path: packaging\windows\OpenLP.wxs
name: Generated-XML

View File

@ -108,7 +108,6 @@ class TestMainWindow(TestCase, TestMixin):
"""
# GIVEN a non service file as an argument to openlp
service = 'run_openlp.py'
self.main_window.arguments = service
# WHEN the argument is processed
self.main_window.open_cmd_line_files(service)