コード例 #1
0
def test_specified_config_file():
    config = Config(['test'])
    assert config.config_file == 'test'
コード例 #2
0
        os.environ['PATH'] = sys._MEIPASS + os.pathsep + os.environ['PATH']
    try:
        del sys.modules['twisted.internet.reactor']  # PyInstaller workaround
    except KeyError:
        pass
    if sys.platform not in ('win32', 'darwin'):
        # PyInstaller's bootloader sets the 'LD_LIBRARY_PATH' environment
        # variable to the root of the executable's directory which causes
        # `xdg-open` -- and, by extension, QDesktopServices.openUrl() -- to
        # fail to properly locate/launch applications by MIME-type/URI-handler.
        # Unsetting it globally here fixes this issue.
        os.environ.pop('LD_LIBRARY_PATH', None)
else:
    pkgdir = os.path.dirname(os.path.realpath(__file__))

settings = Config(os.path.join(pkgdir, 'resources', 'config.txt')).load()

try:
    APP_NAME = settings['application']['name']
except KeyError:
    APP_NAME = 'Gridsync'

if sys.platform == 'win32':
    config_dir = os.path.join(os.getenv('APPDATA'), APP_NAME)  # type: ignore
    autostart_file_path = os.path.join(  # type: ignore
        os.getenv('APPDATA'), 'Microsoft', 'Windows', 'Start Menu', 'Programs',
        'Startup', APP_NAME + '.lnk')
elif sys.platform == 'darwin':
    config_dir = os.path.join(os.path.expanduser('~'), 'Library',
                              'Application Support', APP_NAME)
    autostart_file_path = os.path.join(os.path.expanduser('~'), 'Library',
コード例 #3
0
def test_default_config_file():
    config = Config()
    assert config.config_file == os.path.join(config.config_dir, 'config.yml')
コード例 #4
0
def test_config_load(tmpdir):
    config = Config(os.path.join(str(tmpdir), 'test_load.ini'))
    with open(config.filename, 'w') as f:
        f.write('[test_section]\ntest_option = test_value\n\n')
    assert config.load() == {'test_section': {'test_option': 'test_value'}}
コード例 #5
0
def test_config_set(tmpdir):
    config = Config(os.path.join(str(tmpdir), 'test_set.ini'))
    config.set('test_section', 'test_option', 'test_value')
    with open(config.filename) as f:
        assert f.read() == '[test_section]\ntest_option = test_value\n\n'
コード例 #6
0
def test_config_get(tmpdir):
    config = Config(os.path.join(str(tmpdir), 'test_get.ini'))
    with open(config.filename, 'w') as f:
        f.write('[test_section]\ntest_option = test_value\n\n')
    assert config.get('test_section', 'test_option') == 'test_value'
コード例 #7
0
def test_config_get_no_option_error(tmpdir):
    config = Config(os.path.join(str(tmpdir), 'test_get_no_option_error.ini'))
    with open(config.filename, 'w') as f:
        f.write('[test_section]\ntest_option = test_value\n\n')
    assert config.get('test_section', 'missing_option') is None
コード例 #8
0
def test_config_load(tmpdir):
    config = Config(os.path.join(str(tmpdir), "test_load.ini"))
    with open(config.filename, "w") as f:
        f.write("[test_section]\ntest_option = test_value\n\n")
    assert config.load() == {"test_section": {"test_option": "test_value"}}
コード例 #9
0
def test_config_set(tmpdir):
    config = Config(os.path.join(str(tmpdir), "test_set.ini"))
    config.set("test_section", "test_option", "test_value")
    with open(config.filename) as f:
        assert f.read() == "[test_section]\ntest_option = test_value\n\n"
コード例 #10
0
def test_config_get_no_option_error(tmpdir):
    config = Config(os.path.join(str(tmpdir), "test_get_no_option_error.ini"))
    with open(config.filename, "w") as f:
        f.write("[test_section]\ntest_option = test_value\n\n")
    assert config.get("test_section", "missing_option") is None
コード例 #11
0
def test_config_get(tmpdir):
    config = Config(os.path.join(str(tmpdir), "test_get.ini"))
    with open(config.filename, "w") as f:
        f.write("[test_section]\ntest_option = test_value\n\n")
    assert config.get("test_section", "test_option") == "test_value"
コード例 #12
0
def set_preference(section, option, value, config_file=None):
    if not config_file:
        config_file = os.path.join(config_dir, 'preferences.ini')
    config = Config(config_file)
    config.set(section, option, value)
    logging.debug("Set user preference: %s %s %s", section, option, value)
コード例 #13
0
def get_preference(section, option, config_file=None):
    if not config_file:
        config_file = os.path.join(config_dir, 'preferences.ini')
    config = Config(config_file)
    return config.get(section, option)
コード例 #14
0
ファイル: __init__.py プロジェクト: purplesparkle/gridsync
    try:
        del sys.modules["twisted.internet.reactor"]  # PyInstaller workaround
    except KeyError:
        pass
    if sys.platform not in ("win32", "darwin"):
        # PyInstaller's bootloader sets the 'LD_LIBRARY_PATH' environment
        # variable to the root of the executable's directory which causes
        # `xdg-open` -- and, by extension, QDesktopServices.openUrl() -- to
        # fail to properly locate/launch applications by MIME-type/URI-handler.
        # Unsetting it globally here fixes this issue.
        os.environ.pop("LD_LIBRARY_PATH", None)
else:
    pkgdir = os.path.dirname(os.path.realpath(__file__))


settings = Config(os.path.join(pkgdir, "resources", "config.txt")).load()

try:
    APP_NAME = settings["application"]["name"]
except KeyError:
    APP_NAME = "Gridsync"

if sys.platform == "win32":
    appdata = str(os.getenv("APPDATA"))
    config_dir = os.path.join(appdata, APP_NAME)
    autostart_file_path = os.path.join(
        appdata,
        "Microsoft",
        "Windows",
        "Start Menu",
        "Programs",