Пример #1
0
    def test_can_upgrade(self):
        """Test the Settings.can_upgrade() method"""
        # GIVEN: A Settings object
        local_settings = Settings()

        # WHEN: can_upgrade() is run
        result = local_settings.can_upgrade()

        # THEN: The result should be True
        assert result is True, 'The settings should be upgradeable'
Пример #2
0
def main(args=None):
    """
    The main function which parses command line options and then runs

    :param args: Some args
    """
    args = parse_options(args)
    qt_args = []
    if args and args.loglevel.lower() in ['d', 'debug']:
        log.setLevel(logging.DEBUG)
    elif args and args.loglevel.lower() in ['w', 'warning']:
        log.setLevel(logging.WARNING)
    else:
        log.setLevel(logging.INFO)
    # Throw the rest of the arguments at Qt, just in case.
    qt_args.extend(args.rargs)
    # Bug #1018855: Set the WM_CLASS property in X11
    if not is_win() and not is_macosx():
        qt_args.append('OpenLP')
    # Initialise the resources
    qInitResources()
    # Now create and actually run the application.
    application = OpenLP(qt_args)
    application.setOrganizationName('OpenLP')
    application.setOrganizationDomain('openlp.org')
    application.setAttribute(QtCore.Qt.AA_UseHighDpiPixmaps, True)
    application.setAttribute(QtCore.Qt.AA_DontCreateNativeWidgetSiblings, True)
    if args.portable:
        application.setApplicationName('OpenLPPortable')
        Settings.setDefaultFormat(Settings.IniFormat)
        # Get location OpenLPPortable.ini
        portable_path = (AppLocation.get_directory(AppLocation.AppDir) / '..' /
                         '..').resolve()
        data_path = portable_path / 'Data'
        set_up_logging(portable_path / 'Other')
        log.info('Running portable')
        portable_settings_path = data_path / 'OpenLP.ini'
        # Make this our settings file
        log.info('INI file: {name}'.format(name=portable_settings_path))
        Settings.set_filename(str(portable_settings_path))
        portable_settings = Settings()
        # Set our data path
        log.info('Data path: {name}'.format(name=data_path))
        # Point to our data path
        portable_settings.setValue('advanced/data path', data_path)
        portable_settings.setValue('advanced/is portable', True)
        portable_settings.sync()
    else:
        application.setApplicationName('OpenLP')
        set_up_logging(AppLocation.get_directory(AppLocation.CacheDir))
    Registry.create()
    Registry().register('application', application)
    Registry().set_flag('no_web_server', args.no_web_server)
    application.setApplicationVersion(get_version()['version'])
    # Check if an instance of OpenLP is already running. Quit if there is a running instance and the user only wants one
    server = Server()
    if server.is_another_instance_running():
        application.is_already_running()
        server.post_to_server(qt_args)
        sys.exit()
    else:
        server.start_server()
        application.server = server
    # If the custom data path is missing and the user wants to restore the data path, quit OpenLP.
    if application.is_data_path_missing():
        server.close_server()
        sys.exit()
    # Upgrade settings.
    settings = Settings()
    if settings.can_upgrade():
        now = datetime.now()
        # Only back up if OpenLP has previously run.
        if settings.value('core/has run wizard'):
            back_up_path = AppLocation.get_data_path() / (
                now.strftime('%Y-%m-%d %H-%M') + '.conf')
            log.info(
                'Settings about to be upgraded. Existing settings are being backed up to {back_up_path}'
                .format(back_up_path=back_up_path))
            QtWidgets.QMessageBox.information(
                None, translate('OpenLP', 'Settings Upgrade'),
                translate(
                    'OpenLP',
                    'Your settings are about to be upgraded. A backup will be created at '
                    '{back_up_path}').format(back_up_path=back_up_path))
            settings.export(back_up_path)
        settings.upgrade_settings()
    # First time checks in settings
    if not Settings().value('core/has run wizard'):
        if not FirstTimeLanguageForm().exec():
            # if cancel then stop processing
            server.close_server()
            sys.exit()
    # i18n Set Language
    language = LanguageManager.get_language()
    translators = LanguageManager.get_translators(language)
    for translator in translators:
        if not translator.isEmpty():
            application.installTranslator(translator)
    if not translators:
        log.debug('Could not find translators.')
    if args and not args.no_error_form:
        sys.excepthook = application.hook_exception
    sys.exit(application.run(qt_args))