def test_specified_config_file(): config = Config(['test']) assert config.config_file == 'test'
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',
def test_default_config_file(): config = Config() assert config.config_file == os.path.join(config.config_dir, 'config.yml')
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'}}
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'
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'
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
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"}}
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"
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
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"
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)
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)
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",