Ejemplo n.º 1
0
    def test_system_data_dirs_posix(self):
        if is_win:
            return

        os.environ["XDG_DATA_DIRS"] = "/xyz"
        self.failUnlessEqual(xdg_get_system_data_dirs()[0], "/xyz")
        del os.environ["XDG_DATA_DIRS"]
        dirs = xdg_get_system_data_dirs()
        self.failUnlessEqual(dirs[0], "/usr/local/share/")
        self.failUnlessEqual(dirs[1], "/usr/share/")
Ejemplo n.º 2
0
    def test_system_data_dirs_posix(self):
        if is_win:
            return

        os.environ["XDG_DATA_DIRS"] = "/xyz"
        self.failUnlessEqual(xdg_get_system_data_dirs()[0], "/xyz")
        del os.environ["XDG_DATA_DIRS"]
        dirs = xdg_get_system_data_dirs()
        self.failUnlessEqual(dirs[0], "/usr/local/share/")
        self.failUnlessEqual(dirs[1], "/usr/share/")
Ejemplo n.º 3
0
def get_mpi_dir():
    """Path to the media-player-info directory or None"""

    for dir_ in xdg_get_system_data_dirs():
        mpi_path = os.path.join(dir_, "media-player-info")
        if os.path.isdir(mpi_path):
            return mpi_path
Ejemplo n.º 4
0
    def __get_themes(self):
        # deprecated, but there is no public replacement
        with warnings.catch_warnings():
            warnings.simplefilter("ignore")
            theme_dir = Gtk.rc_get_theme_dir()

        theme_dirs = [theme_dir, os.path.join(get_home_dir(), ".themes")]
        theme_dirs += [
            os.path.join(d, "themes") for d in xdg_get_system_data_dirs()
        ]

        themes = set()
        for theme_dir in set(theme_dirs):
            try:
                subdirs = os.listdir(theme_dir)
            except OSError:
                continue
            for dir_ in subdirs:
                gtk_dir = os.path.join(theme_dir, dir_, "gtk-3.0")
                if os.path.isdir(gtk_dir):
                    themes.add(dir_)

        try:
            resource_themes = Gio.resources_enumerate_children(
                "/org/gtk/libgtk/theme", 0)
        except GLib.GError:
            pass
        else:
            themes.update([t.rstrip("/") for t in resource_themes])

        return themes
Ejemplo n.º 5
0
def get_mpi_dir():
    """Path to the media-player-info directory or None"""

    for dir_ in xdg_get_system_data_dirs():
        mpi_path = os.path.join(dir_, "media-player-info")
        if os.path.isdir(mpi_path):
            return mpi_path
Ejemplo n.º 6
0
    def __get_themes(self):
        # deprecated, but there is no public replacement
        with warnings.catch_warnings():
            warnings.simplefilter("ignore")
            theme_dir = Gtk.rc_get_theme_dir()

        theme_dirs = [theme_dir, os.path.join(get_home_dir(), ".themes")]
        theme_dirs += [
            os.path.join(d, "themes") for d in xdg_get_system_data_dirs()]

        themes = set()
        for theme_dir in set(theme_dirs):
            try:
                subdirs = os.listdir(theme_dir)
            except OSError:
                continue
            for dir_ in subdirs:
                gtk_dir = os.path.join(theme_dir, dir_, "gtk-3.0")
                if os.path.isdir(gtk_dir):
                    themes.add(dir_)

        try:
            resource_themes = Gio.resources_enumerate_children(
                "/org/gtk/libgtk/theme", 0)
        except GLib.GError:
            pass
        else:
            themes.update([t.rstrip("/") for t in resource_themes])

        return themes
Ejemplo n.º 7
0
def get_gs_provider_files():
    """Return all installed search provider files for GNOME Shell"""

    ini_files = []
    for d in xdg_get_system_data_dirs():
        path = os.path.join(d, "gnome-shell", "search-providers")
        try:
            for entry in os.listdir(path):
                if entry.endswith(".ini"):
                    ini_files.append(os.path.join(path, entry))
        except EnvironmentError:
            pass
    return ini_files
Ejemplo n.º 8
0
def get_gs_provider_files():
    """Return all installed search provider files for GNOME Shell"""

    ini_files = []
    for d in xdg_get_system_data_dirs():
        path = os.path.join(d, "gnome-shell", "search-providers")
        try:
            for entry in os.listdir(path):
                if entry.endswith(".ini"):
                    ini_files.append(os.path.join(path, entry))
        except EnvironmentError:
            pass
    return ini_files
Ejemplo n.º 9
0
def iter_locale_dirs():
    dirs = list(xdg_get_system_data_dirs())
    # this is the one python gettext uses by default, use as a fallback
    dirs.append(os.path.join(sys.base_prefix, "share"))

    done = set()
    for path in dirs:
        locale_dir = os.path.join(path, "locale")
        if locale_dir in done:
            continue
        done.add(locale_dir)
        if os.path.isdir(locale_dir):
            yield locale_dir
Ejemplo n.º 10
0
def iter_locale_dirs():
    dirs = list(xdg_get_system_data_dirs())
    # this is the one python gettext uses by default, use as a fallback
    dirs.append(os.path.join(sys.base_prefix, "share"))

    done = set()
    for path in dirs:
        locale_dir = os.path.join(path, "locale")
        if locale_dir in done:
            continue
        done.add(locale_dir)
        if os.path.isdir(locale_dir):
            yield locale_dir
Ejemplo n.º 11
0
    def __get_themes(self):
        # deprecated, but there is no public replacement
        with warnings.catch_warnings():
            warnings.simplefilter("ignore")
            theme_dir = Gtk.rc_get_theme_dir()

        theme_dirs = [theme_dir, os.path.join(get_home_dir(), ".themes")]
        theme_dirs += [
            os.path.join(d, "themes") for d in xdg_get_system_data_dirs()
        ]

        def is_valid_teme_dir(path):
            """If the path contains a theme for the running gtk version"""

            major = qltk.gtk_version[0]
            minor = qltk.gtk_version[1]
            names = ["gtk-%d.%d" % (major, m) for m in range(minor, -1, -1)]
            for name in names:
                if os.path.isdir(os.path.join(path, name)):
                    return True
            return False

        themes = set()
        for theme_dir in set(theme_dirs):
            try:
                subdirs = os.listdir(theme_dir)
            except OSError:
                continue
            for dir_ in subdirs:
                if is_valid_teme_dir(os.path.join(theme_dir, dir_)):
                    themes.add(dir_)

        try:
            resource_themes = Gio.resources_enumerate_children(
                "/org/gtk/libgtk/theme", 0)
        except GLib.GError:
            pass
        else:
            themes.update([t.rstrip("/") for t in resource_themes])

        return themes
Ejemplo n.º 12
0
 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())
Ejemplo n.º 13
0
 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())
Ejemplo n.º 14
0
 def __get_mpi_dir(self):
     for dir in xdg_get_system_data_dirs():
         path = os.path.join(dir, "media-player-info")
         if os.path.isdir(path):
             return path