def init_test_environ(): """This needs to be called before any test can be run. Before exiting the process call exit_test_environ() to clean up any resources created. """ global _TEMP_DIR, _BUS_INFO, _VDISPLAY, _faulthandler_fobj # create a user dir in /tmp and set env vars _TEMP_DIR = tempfile.mkdtemp(prefix=fsnative(u"QL-TEST-")) # needed for dbus/dconf runtime_dir = tempfile.mkdtemp(prefix=fsnative(u"RUNTIME-"), dir=_TEMP_DIR) os.chmod(runtime_dir, 0o700) environ["XDG_RUNTIME_DIR"] = runtime_dir # force the old cache dir so that GStreamer can re-use the GstRegistry # cache file environ["XDG_CACHE_HOME"] = xdg_get_cache_home() # GStreamer will update the cache if the environment has changed # (in Gst.init()). Since it takes 0.5s here and doesn't add much, # disable it. If the registry cache is missing it will be created # despite this setting. environ["GST_REGISTRY_UPDATE"] = fsnative(u"no") # set HOME and remove all XDG vars that default to it if not set home_dir = tempfile.mkdtemp(prefix=fsnative(u"HOME-"), dir=_TEMP_DIR) environ["HOME"] = home_dir # set to new default environ.pop("XDG_DATA_HOME", None) if xvfbwrapper is not None: _VDISPLAY = xvfbwrapper.Xvfb() _VDISPLAY.start() _BUS_INFO = None if os.name != "nt" and "DBUS_SESSION_BUS_ADDRESS" in environ: _BUS_INFO = dbus_launch_user() environ.update(_BUS_INFO) quodlibet.init(no_translations=True, no_excepthook=True) quodlibet.app.name = "QL Tests" # to get around pytest silencing _faulthandler_fobj = os.fdopen(os.dup(sys.__stderr__.fileno()), "w") faulthandler.enable(_faulthandler_fobj) # try to make things the same in case a different locale is active. # LANG for gettext, setlocale for number formatting etc. # Note: setlocale has to be called after Gtk.init() try: if os.name != "nt": environ["LANG"] = locale.setlocale(locale.LC_ALL, "en_US.UTF-8") else: environ["LANG"] = "en_US.utf8" locale.setlocale(locale.LC_ALL, "english") except locale.Error: pass
def init_test_environ(): """This needs to be called before any test can be run. Before exiting the process call exit_test_environ() to clean up any resources created. """ global _TEMP_DIR, _BUS_INFO, _VDISPLAY, _faulthandler_fobj # create a user dir in /tmp and set env vars _TEMP_DIR = tempfile.mkdtemp(prefix=fsnative(u"QL-TEST-")) # needed for dbus/dconf runtime_dir = tempfile.mkdtemp(prefix=fsnative(u"RUNTIME-"), dir=_TEMP_DIR) os.chmod(runtime_dir, 0o700) environ["XDG_RUNTIME_DIR"] = runtime_dir # force the old cache dir so that GStreamer can re-use the GstRegistry # cache file environ["XDG_CACHE_HOME"] = xdg_get_cache_home() # GStreamer will update the cache if the environment has changed # (in Gst.init()). Since it takes 0.5s here and doesn't add much, # disable it. If the registry cache is missing it will be created # despite this setting. environ["GST_REGISTRY_UPDATE"] = fsnative(u"no") # set HOME and remove all XDG vars that default to it if not set home_dir = tempfile.mkdtemp(prefix=fsnative(u"HOME-"), dir=_TEMP_DIR) environ["HOME"] = home_dir # set to new default environ.pop("XDG_DATA_HOME", None) if xvfbwrapper is not None: _VDISPLAY = xvfbwrapper.Xvfb() _VDISPLAY.start() _BUS_INFO = None if os.name != "nt" and sys.platform != "darwin": _BUS_INFO = dbus_launch_user() environ.update(_BUS_INFO) quodlibet.init(no_translations=True, no_excepthook=True) quodlibet.app.name = "QL Tests" # to get around pytest silencing _faulthandler_fobj = os.fdopen(os.dup(sys.__stderr__.fileno()), "w") faulthandler.enable(_faulthandler_fobj) # try to make things the same in case a different locale is active. # LANG for gettext, setlocale for number formatting etc. # Note: setlocale has to be called after Gtk.init() try: if os.name != "nt": environ["LANG"] = locale.setlocale(locale.LC_ALL, "en_US.UTF-8") else: environ["LANG"] = "en_US.utf8" locale.setlocale(locale.LC_ALL, "english") except locale.Error: pass
def init_test_environ(): """This needs to be called before any test can be run. Before exiting the process call exit_test_environ() to clean up any resources created. """ global _TEMP_DIR, _BUS_INFO # create a user dir in /tmp and set env vars _TEMP_DIR = tempfile.mkdtemp(prefix=fsnative(u"QL-TEST-")) # needed for dbus/dconf runtime_dir = tempfile.mkdtemp(prefix=fsnative(u"RUNTIME-"), dir=_TEMP_DIR) os.chmod(runtime_dir, 0o700) environ["XDG_RUNTIME_DIR"] = runtime_dir # force the old cache dir so that GStreamer can re-use the GstRegistry # cache file environ["XDG_CACHE_HOME"] = xdg_get_cache_home() # GStreamer will update the cache if the environment has changed # (in Gst.init()). Since it takes 0.5s here and doesn't add much, # disable it. If the registry cache is missing it will be created # despite this setting. environ["GST_REGISTRY_UPDATE"] = fsnative(u"no") # set HOME and remove all XDG vars that default to it if not set home_dir = tempfile.mkdtemp(prefix=fsnative(u"HOME-"), dir=_TEMP_DIR) environ["HOME"] = home_dir # set to new default environ.pop("XDG_DATA_HOME", None) _BUS_INFO = None if os.name != "nt" and "DBUS_SESSION_BUS_ADDRESS" in environ: try: out = subprocess.check_output(["dbus-launch"]) except (subprocess.CalledProcessError, OSError): pass else: if PY3: out = out.decode("ascii") _BUS_INFO = dict([l.split("=", 1) for l in out.splitlines()]) environ.update(_BUS_INFO) # Ideally nothing should touch the FS on import, but we do atm.. # Get rid of all modules so QUODLIBET_USERDIR gets used everywhere. for key in list(sys.modules.keys()): if key.startswith('quodlibet'): del (sys.modules[key]) import quodlibet quodlibet.init(no_translations=True, no_excepthook=True) quodlibet.app.name = "QL Tests"
def get_cache_dir(): """The directory to store things into which can be deleted at any time""" if os.name == "nt" and build.BUILD_TYPE == u"windows-portable": # avoid writing things to the host system for the portable build path = os.path.join(get_user_dir(), "cache") else: path = os.path.join(xdg_get_cache_home(), "quodlibet") mkdir(path, 0o700) return path
def init_test_environ(): """This needs to be called before any test can be run. Before exiting the process call exit_test_environ() to clean up any resources created. """ global _TEMP_DIR, _BUS_INFO # create a user dir in /tmp and set env vars _TEMP_DIR = tempfile.mkdtemp(prefix=fsnative(u"QL-TEST-")) # needed for dbus/dconf runtime_dir = tempfile.mkdtemp(prefix=fsnative(u"RUNTIME-"), dir=_TEMP_DIR) os.chmod(runtime_dir, 0o700) environ["XDG_RUNTIME_DIR"] = runtime_dir # force the old cache dir so that GStreamer can re-use the GstRegistry # cache file environ["XDG_CACHE_HOME"] = xdg_get_cache_home() # GStreamer will update the cache if the environment has changed # (in Gst.init()). Since it takes 0.5s here and doesn't add much, # disable it. If the registry cache is missing it will be created # despite this setting. environ["GST_REGISTRY_UPDATE"] = fsnative(u"no") # set HOME and remove all XDG vars that default to it if not set home_dir = tempfile.mkdtemp(prefix=fsnative(u"HOME-"), dir=_TEMP_DIR) environ["HOME"] = home_dir # set to new default environ.pop("XDG_DATA_HOME", None) _BUS_INFO = None if os.name != "nt" and "DBUS_SESSION_BUS_ADDRESS" in environ: try: out = subprocess.check_output(["dbus-launch"]) except (subprocess.CalledProcessError, OSError): pass else: if PY3: out = out.decode("ascii") _BUS_INFO = dict([l.split("=", 1) for l in out.splitlines()]) environ.update(_BUS_INFO) # Ideally nothing should touch the FS on import, but we do atm.. # Get rid of all modules so QUODLIBET_USERDIR gets used everywhere. for key in list(sys.modules.keys()): if key.startswith('quodlibet'): del(sys.modules[key]) import quodlibet quodlibet.init(no_translations=True, no_excepthook=True) quodlibet.app.name = "QL Tests"
def get_thumbnail_folder(): """Returns a path to the thumbnail folder. The returned path might not exist. """ if os.name == "nt": thumb_folder = os.path.join(quodlibet.get_user_dir(), "thumbnails") else: cache_folder = os.path.join(xdg_get_cache_home(), "thumbnails") thumb_folder = os.path.expanduser('~/.thumbnails') if os.path.exists(cache_folder) or not os.path.exists(thumb_folder): thumb_folder = cache_folder return thumb_folder
def get_thumbnail_folder(): """Returns a path to the thumbnail folder. The returned path might not exist. """ if os.name == "nt": thumb_folder = os.path.join(USERDIR, "thumbnails") else: cache_folder = os.path.join(xdg_get_cache_home(), "thumbnails") thumb_folder = os.path.expanduser('~/.thumbnails') if os.path.exists(cache_folder) or not os.path.exists(thumb_folder): thumb_folder = cache_folder try: mkdir(thumb_folder, 0700) except OSError: pass return thumb_folder
def test_on_windows(self): self.assertTrue(xdg_get_system_data_dirs()) self.assertTrue(xdg_get_cache_home()) self.assertTrue(xdg_get_data_home()) self.assertTrue(xdg_get_config_home())
def fetch_cover(self): """ Method to ask source fetch the cover from its source into location at `self.cover_path`. If this method succeeds in putting the image from its source into `self.cover_path`, `fetch-success` signal shall be emitted and `fetch-failure` otherwise. Return value of this function doesn't have any meaning whatsoever. """ self.fail('This source is incapable of fetching covers') def fail(self, message): """ Shorthand method for emitting `fetch-failure` signals. Most common use pattern would be: return self.fail("Failure message") """ self.emit('fetch-failure', message) cover_dir = path.join(xdg_get_cache_home(), 'quodlibet', 'covers') try: makedirs(cover_dir) except OSError: pass
def init_test_environ(): """This needs to be called before any test can be run. Before exiting the process call exit_test_environ() to clean up any resources created. """ global _TEMP_DIR, _BUS_INFO, _VDISPLAY # create a user dir in /tmp and set env vars _TEMP_DIR = tempfile.mkdtemp(prefix=fsnative(u"QL-TEST-")) # needed for dbus/dconf runtime_dir = tempfile.mkdtemp(prefix=fsnative(u"RUNTIME-"), dir=_TEMP_DIR) os.chmod(runtime_dir, 0o700) environ["XDG_RUNTIME_DIR"] = runtime_dir # force the old cache dir so that GStreamer can re-use the GstRegistry # cache file environ["XDG_CACHE_HOME"] = xdg_get_cache_home() # GStreamer will update the cache if the environment has changed # (in Gst.init()). Since it takes 0.5s here and doesn't add much, # disable it. If the registry cache is missing it will be created # despite this setting. environ["GST_REGISTRY_UPDATE"] = fsnative(u"no") # In flatpak we might get a registry from a different/old flatpak build # when testing new versions etc. Better always update in that case. if util.is_flatpak(): del environ["GST_REGISTRY_UPDATE"] # set HOME and remove all XDG vars that default to it if not set home_dir = tempfile.mkdtemp(prefix=fsnative(u"HOME-"), dir=_TEMP_DIR) environ["HOME"] = home_dir # set to new default environ.pop("XDG_DATA_HOME", None) environ.pop("XDG_CONFIG_HOME", None) # don't use dconf environ["GSETTINGS_BACKEND"] = "memory" # don't use dconf environ["GSETTINGS_BACKEND"] = "memory" # Force the default theme so broken themes don't affect the tests environ["GTK_THEME"] = "Adwaita" if xvfbwrapper is not None: _VDISPLAY = xvfbwrapper.Xvfb() _VDISPLAY.start() _BUS_INFO = None if os.name != "nt" and sys.platform != "darwin": _BUS_INFO = dbus_launch_user() environ.update(_BUS_INFO) quodlibet.init(no_translations=True, no_excepthook=True) quodlibet.app.name = "QL Tests" # try to make things the same in case a different locale is active. # LANG for gettext, setlocale for number formatting etc. # Note: setlocale has to be called after Gtk.init() try: if os.name != "nt": environ["LANG"] = locale.setlocale(locale.LC_ALL, "en_US.UTF-8") else: environ["LANG"] = "en_US.utf8" locale.setlocale(locale.LC_ALL, "english") except locale.Error: pass
def fetch_cover(self): """ Method to ask source fetch the cover from its source into location at `self.cover_path`. If this method succeeds in putting the image from its source into `self.cover_path`, `fetch-success` signal shall be emitted and `fetch-failure` otherwise. Return value of this function doesn't have any meaning whatsoever. """ self.fail("This source is incapable of fetching covers") def fail(self, message): """ Shorthand method for emitting `fetch-failure` signals. Most common use pattern would be: return self.fail("Failure message") """ self.emit("fetch-failure", message) cover_dir = path.join(xdg_get_cache_home(), "quodlibet", "covers") try: makedirs(cover_dir) except OSError: pass