← Back to team overview

openlp-core team mailing list archive

[Merge] lp:~tomasgroth/openlp/portable-path into lp:openlp

 

Tomas Groth has proposed merging lp:~tomasgroth/openlp/portable-path into lp:openlp.

Commit message:
Make it possible to specify the portable path to use for OpenLP Data when in portable mode. This is very useful during development.

Requested reviews:
  OpenLP Core (openlp-core)

For more details, see:
https://code.launchpad.net/~tomasgroth/openlp/portable-path/+merge/366734
-- 
Your team OpenLP Core is requested to review the proposed merge of lp:~tomasgroth/openlp/portable-path into lp:openlp.
=== modified file 'openlp/core/app.py'
--- openlp/core/app.py	2019-03-28 21:03:32 +0000
+++ openlp/core/app.py	2019-04-30 19:47:11 +0000
@@ -30,6 +30,7 @@
 import logging
 import sys
 import time
+import os
 from datetime import datetime
 from traceback import format_exception
 
@@ -40,7 +41,7 @@
 from openlp.core.common.applocation import AppLocation
 from openlp.core.loader import loader
 from openlp.core.common.i18n import LanguageManager, UiStrings, translate
-from openlp.core.common.path import copytree, create_paths
+from openlp.core.common.path import copytree, create_paths, str_to_path
 from openlp.core.common.registry import Registry
 from openlp.core.common.settings import Settings
 from openlp.core.display.screens import ScreenList
@@ -301,6 +302,8 @@
                         help='Set logging to LEVEL level. Valid values are "debug", "info", "warning".')
     parser.add_argument('-p', '--portable', dest='portable', action='store_true',
                         help='Specify if this should be run as a portable app, ')
+    parser.add_argument('-pp', '--portable-path', dest='portablepath', default=None,
+                        help='Specify the path of the portable data, defaults to "<AppDir>/../../".')
     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=[])
@@ -356,7 +359,14 @@
         application.setApplicationName('OpenLPPortable')
         Settings.setDefaultFormat(Settings.IniFormat)
         # Get location OpenLPPortable.ini
-        portable_path = (AppLocation.get_directory(AppLocation.AppDir) / '..' / '..').resolve()
+        if args.portablepath:
+            if os.path.isabs(args.portablepath):
+                portable_path = str_to_path(args.portablepath).resolve()
+            else:
+                portable_path = (AppLocation.get_directory(AppLocation.AppDir) / '..' /
+                                 str_to_path(args.portablepath)).resolve()
+        else:
+            portable_path = (AppLocation.get_directory(AppLocation.AppDir) / '..' / '..').resolve()
         data_path = portable_path / 'Data'
         set_up_logging(portable_path / 'Other')
         log.info('Running portable')

=== modified file 'tests/functional/openlp_core/test_app.py'
--- tests/functional/openlp_core/test_app.py	2019-02-14 15:09:09 +0000
+++ tests/functional/openlp_core/test_app.py	2019-04-30 19:47:11 +0000
@@ -84,6 +84,24 @@
     assert args.rargs == [], 'The service file should be blank'
 
 
+def test_parse_options_portable_and_portable_path():
+    """
+    Test the parse options process works portable and portable-path
+    """
+    # GIVEN: a a set of system arguments.
+    sys.argv[1:] = ['--portable', '--portable-path .']
+
+    # WHEN: We we parse them to expand to options
+    args = parse_options()
+
+    # THEN: the following fields will have been extracted.
+    assert args.loglevel == 'warning', 'The log level should be set to warning'
+    assert args.no_error_form is False, 'The no_error_form should be set to False'
+    assert args.portable is True, 'The portable flag should be set to true'
+    assert args.portablepath == '.', 'The portable path should be set to "."'
+    assert args.rargs == [], 'The service file should be blank'
+
+
 def test_parse_options_all_no_file():
     """
     Test the parse options process works with two options


Follow ups