コード例 #1
0
ファイル: applocation.py プロジェクト: jkunle/paul
    def get_directory(dir_type=AppDir):
        """
        Return the appropriate directory according to the directory type.

        :param dir_type: The directory type you want, for instance the data directory. Default *AppLocation.AppDir*
        """
        if dir_type == AppLocation.AppDir:
            return get_frozen_path(
                os.path.abspath(os.path.dirname(sys.argv[0])),
                os.path.dirname(openlp.__file__))
        elif dir_type == AppLocation.PluginsDir:
            app_path = os.path.abspath(os.path.dirname(sys.argv[0]))
            return get_frozen_path(
                os.path.join(app_path, 'plugins'),
                os.path.join(os.path.dirname(openlp.__file__), 'plugins'))
        elif dir_type == AppLocation.VersionDir:
            return get_frozen_path(
                os.path.abspath(os.path.dirname(sys.argv[0])),
                os.path.dirname(openlp.__file__))
        elif dir_type == AppLocation.LanguageDir:
            app_path = get_frozen_path(
                os.path.abspath(os.path.dirname(sys.argv[0])),
                _get_os_dir_path(dir_type))
            return os.path.join(app_path, 'i18n')
        elif dir_type == AppLocation.DataDir and AppLocation.BaseDir:
            return os.path.join(AppLocation.BaseDir, 'data')
        else:
            return _get_os_dir_path(dir_type)
コード例 #2
0
    def get_directory(dir_type=AppDir):
        """
        Return the appropriate directory according to the directory type.

        :param dir_type: The directory type you want, for instance the data directory. Default *AppLocation.AppDir*
        :return: The requested path
        :rtype: openlp.core.common.path.Path
        """
        if dir_type == AppLocation.AppDir or dir_type == AppLocation.VersionDir:
            return get_frozen_path(FROZEN_APP_PATH, APP_PATH)
        elif dir_type == AppLocation.PluginsDir:
            return get_frozen_path(FROZEN_APP_PATH, APP_PATH) / 'plugins'
        elif dir_type == AppLocation.LanguageDir:
            return get_frozen_path(FROZEN_APP_PATH,
                                   _get_os_dir_path(dir_type)) / 'i18n'
        else:
            return _get_os_dir_path(dir_type)
コード例 #3
0
ファイル: test_applocation.py プロジェクト: ipic/projecao
def test_get_frozen_path_in_frozen_app(mocked_sys):
    """
    Test the get_frozen_path() function when the application is frozen (compiled by PyInstaller)
    """
    # GIVEN: The sys module *with* a "frozen" attribute
    mocked_sys.frozen = 1

    # WHEN: We call _get_frozen_path() with two parameters
    frozen_path = get_frozen_path('frozen', 'not frozen')

    # THEN: The frozen parameter is returned
    assert frozen_path == 'frozen', 'Should return "frozen"'
コード例 #4
0
ファイル: test_applocation.py プロジェクト: ipic/projecao
def test_get_frozen_path_in_unfrozen_app(mocked_sys):
    """
    Test the _get_frozen_path() function when the application is not frozen (compiled by PyInstaller)
    """
    # GIVEN: The sys module "without" a "frozen" attribute
    mocked_sys.frozen = None

    # WHEN: We call _get_frozen_path() with two parameters
    frozen_path = get_frozen_path('frozen', 'not frozen')

    # THEN: The non-frozen parameter is returned
    assert frozen_path == 'not frozen', '_get_frozen_path should return "not frozen"'
コード例 #5
0
ファイル: applocation.py プロジェクト: crossroadchurch/paul
    def get_directory(dir_type=AppDir):
        """
        Return the appropriate directory according to the directory type.

        :param dir_type: The directory type you want, for instance the data directory. Default *AppLocation.AppDir*
        """
        if dir_type == AppLocation.AppDir:
            return get_frozen_path(os.path.abspath(os.path.dirname(sys.argv[0])), os.path.dirname(openlp.__file__))
        elif dir_type == AppLocation.PluginsDir:
            app_path = os.path.abspath(os.path.dirname(sys.argv[0]))
            return get_frozen_path(os.path.join(app_path, 'plugins'),
                                   os.path.join(os.path.dirname(openlp.__file__), 'plugins'))
        elif dir_type == AppLocation.VersionDir:
            return get_frozen_path(os.path.abspath(os.path.dirname(sys.argv[0])), os.path.dirname(openlp.__file__))
        elif dir_type == AppLocation.LanguageDir:
            app_path = get_frozen_path(os.path.abspath(os.path.dirname(sys.argv[0])), _get_os_dir_path(dir_type))
            return os.path.join(app_path, 'i18n')
        elif dir_type == AppLocation.DataDir and AppLocation.BaseDir:
            return os.path.join(AppLocation.BaseDir, 'data')
        else:
            return _get_os_dir_path(dir_type)
コード例 #6
0
    def get_frozen_path_in_frozen_app_test(self):
        """
        Test the get_frozen_path() function when the application is frozen (compiled by PyInstaller)
        """
        with patch('openlp.core.common.sys') as mocked_sys:
            # GIVEN: The sys module *with* a "frozen" attribute
            mocked_sys.frozen = 1

            # WHEN: We call _get_frozen_path() with two parameters
            frozen_path = get_frozen_path('frozen', 'not frozen')

            # THEN: The frozen parameter is returned
            self.assertEqual('frozen', frozen_path, 'Should return "frozen"')
コード例 #7
0
    def get_frozen_path_in_unfrozen_app_test(self):
        """
        Test the _get_frozen_path() function when the application is not frozen (compiled by PyInstaller)
        """
        with patch('openlp.core.utils.sys') as mocked_sys:
            # GIVEN: The sys module "without" a "frozen" attribute
            mocked_sys.frozen = None

            # WHEN: We call _get_frozen_path() with two parameters
            frozen_path = get_frozen_path('frozen', 'not frozen')

            # THEN: The non-frozen parameter is returned
            self.assertEqual('not frozen', frozen_path, '_get_frozen_path should return "not frozen"')
コード例 #8
0
    def test_get_frozen_path_in_frozen_app(self):
        """
        Test the get_frozen_path() function when the application is frozen (compiled by PyInstaller)
        """
        with patch('openlp.core.common.sys') as mocked_sys:
            # GIVEN: The sys module *with* a "frozen" attribute
            mocked_sys.frozen = 1

            # WHEN: We call _get_frozen_path() with two parameters
            frozen_path = get_frozen_path('frozen', 'not frozen')

            # THEN: The frozen parameter is returned
            self.assertEqual('frozen', frozen_path, 'Should return "frozen"')
コード例 #9
0
ファイル: test_applocation.py プロジェクト: jkunle/paul
    def get_frozen_path_in_unfrozen_app_test(self):
        """
        Test the _get_frozen_path() function when the application is not frozen (compiled by PyInstaller)
        """
        with patch('openlp.core.utils.sys') as mocked_sys:
            # GIVEN: The sys module "without" a "frozen" attribute
            mocked_sys.frozen = None

            # WHEN: We call _get_frozen_path() with two parameters
            frozen_path = get_frozen_path('frozen', 'not frozen')

            # THEN: The non-frozen parameter is returned
            self.assertEqual('not frozen', frozen_path,
                             '_get_frozen_path should return "not frozen"')