Beispiel #1
0
 def __init__(self):
     self.__filename = get_config_filename('favorites')
     self.__parser = SafeConfigParser()
     self.__parser.read(self.__filename)
     self.__current_uri = None
     self.__top_score = 0
     self.__update_id = 0
Beispiel #2
0
        def find_config_file(basename):
            filename = get_config_filename(basename)

            if os.path.isfile(filename):
                return filename

            for libdir in sys.path:
                prefix = os.path.commonprefix([__file__, libdir])

                if not prefix or prefix != libdir:
                    continue

                libdir_parent, libdir_name = os.path.split(libdir)

                if 'site-packages' == libdir_name:
                    prefix = os.path.join(libdir_parent, '..', '..')
                    filename = os.path.join(prefix, 'share', 'webradio', basename)

                    if os.path.isfile(filename):
                        return filename

                for filename in [
                        os.path.join(libdir, 'data', basename),
                        os.path.join(libdir_parent, 'data', basename)]:
                    if os.path.isfile(filename):
                        return filename

            return None
Beispiel #3
0
 def __init__(self):
     self.__filename = get_config_filename('favorites')
     self.__parser = SafeConfigParser()
     self.__parser.read(self.__filename)
     self.__current_uri = None
     self.__top_score = 0
     self.__update_id = 0
Beispiel #4
0
        def find_config_file(basename):
            filename = get_config_filename(basename)

            if os.path.isfile(filename):
                return filename

            for libdir in sys.path:
                prefix = os.path.commonprefix([__file__, libdir])

                if not prefix or prefix != libdir:
                    continue

                libdir_parent, libdir_name = os.path.split(libdir)

                if 'site-packages' == libdir_name:
                    prefix = os.path.join(libdir_parent, '..', '..')
                    filename = os.path.join(prefix, 'share', 'webradio',
                                            basename)

                    if os.path.isfile(filename):
                        return filename

                for filename in [
                        os.path.join(libdir, 'data', basename),
                        os.path.join(libdir_parent, 'data', basename)
                ]:
                    if os.path.isfile(filename):
                        return filename

            return None
Beispiel #5
0
        def read_wishlist():
            filename = get_config_filename("wishlist")
            wishlist = []

            try:
                text = file(filename).read().strip()
                wishlist = text and text.split("\n") or []

            except IOError:
                pass

            return dict(zip(wishlist, range(len(wishlist))))
Beispiel #6
0
        def read_wishlist():
            filename = get_config_filename('wishlist')
            wishlist = []

            try:
                text = file(filename).read().strip()
                wishlist = text and text.split('\n') or []

            except IOError:
                pass

            return dict(zip(wishlist, range(len(wishlist))))
Beispiel #7
0
        def favorite_button_clicked_cb(button):
            if not self.__current_title:
                return

            if button.get_active():
                self.__wishlist[self.__current_title] = True

            else:
                self.__wishlist.pop(self.__current_title, False)

            wishlist_text = "\n".join(self.__wishlist.keys()) + "\n"
            filename = get_config_filename("wishlist")
            file(filename, "w").write(wishlist_text)
Beispiel #8
0
        def favorite_button_clicked_cb(button):
            if not self.__current_title:
                return

            if button.get_active():
                self.__wishlist[self.__current_title] = True

            else:
                self.__wishlist.pop(self.__current_title, False)

            wishlist_text = '\n'.join(self.__wishlist.keys()) + '\n'
            filename = get_config_filename('wishlist')
            file(filename, 'w').write(wishlist_text)
Beispiel #9
0
class Configuration(object):
    def __init__(self):
        self.__parser = SafeConfigParser()
        self.__parser.add_section('WebRadio')

        self.read()

    def read(self, target=None):
        if target is None:
            target = self.filename

        self.__parser.read(target)

    def write(self, target=None):
        if target is None:
            target = self.filename

        if isinstance(target, str):
            confdir = os.path.dirname(target)

            if not os.path.isdir(confdir):
                os.makedirs(os.path.dirname(target))

            target = file(target, 'w')

        self.__parser.write(target)

    def _get(self, section, key, default=None):
        if not section:
            section = 'WebRadio'
        if self.__parser.has_option(section, key):
            return self.__parser.get(section, key)

        return default

    def _set(self, section, key, value):
        if not section:
            section = 'WebRadio'

        return self.__parser.set(section, key, value)

    filename = property(
        fget=lambda self: get_config_filename('settings'))

    tags = property(
        fget=lambda self: self._get(None, 'tags'),
        fset=lambda self, value: self._set(None, 'tags', value))

    channel_uri = property(
        fget=lambda self: self._get(None, 'channel-uri'),
        fset=lambda self, value: self._set(None, 'channel-uri', value))