示例#1
0
    def set_config_setting(self, key, value, sender=None):
        self._check_permission(sender, PK_ACTION_TWEAK)
        log.debug('set_config_setting: %s to %s' % (key, value))
        cs = ConfigSetting(key)
        cs.set_value(value)

        return value == cs.get_value()
    def test_config_settings(self):
        # draw grid
        draw_grid_setting_key = "%s::%s#%s" % (self.unity_greeter_override_path, 'com.canonical.unity-greeter', 'draw-grid')

        self.draw_grid_setting = ConfigSetting(draw_grid_setting_key, type=bool)
        self.assertEqual(True, self.draw_grid_setting.get_value())
        self.draw_grid_setting.set_value(False)
        self.assertEqual(False, self.draw_grid_setting.get_value())

        #try again the fuzz type
        self.draw_grid_setting = ConfigSetting(draw_grid_setting_key)
        self.assertEqual(False, self.draw_grid_setting.get_value())
        self.draw_grid_setting.set_value(True)
        self.assertEqual(True, self.draw_grid_setting.get_value())

        #play sound
        play_sound_key = self.get_key('play-ready-sound')
        self.play_sound_setting = ConfigSetting(play_sound_key)
        self.assertEqual(False, self.play_sound_setting.get_value())

        #background
        background_setting = ConfigSetting(self.get_key('background'), type=str)
        self.assertEqual('/usr/share/backgrounds/The_Forbidden_City_by_Daniel_Mathis.jpg', background_setting.get_value())
        #try again the fuzz type for str
        background_setting = ConfigSetting(self.get_key('background'))
        self.assertEqual("/usr/share/backgrounds/The_Forbidden_City_by_Daniel_Mathis.jpg", background_setting.get_value())
示例#3
0
    def set_config_setting(self, key, value, sender=None):
        self._check_permission(sender, PK_ACTION_TWEAK)
        log.debug('set_config_setting: %s to %s' % (key, value))
        cs = ConfigSetting(key)
        cs.set_value(value)

        if cs.is_override_schema():
            os.system('glib-compile-schemas /usr/share/glib-2.0/schemas/')

        return value == cs.get_value()
class TestConfigSettings(unittest.TestCase):
    def setUp(self):
        self.unity_greeter_override_file = tempfile.NamedTemporaryFile(
            delete=False)
        self.unity_greeter_override_file.write(
            "[com.canonical.unity-greeter]\n"
            "draw-grid = true\n"
            "play-ready-sound = false\n"
            "background = '/usr/share/backgrounds/The_Forbidden_City_by_Daniel_Mathis.jpg'\n"
        )
        self.unity_greeter_override_file.close()
        self.unity_greeter_override_path = self.unity_greeter_override_file.name

    def test_config_settings(self):
        # draw grid
        draw_grid_setting_key = "%s::%s#%s" % (
            self.unity_greeter_override_path, 'com.canonical.unity-greeter',
            'draw-grid')

        self.draw_grid_setting = ConfigSetting(draw_grid_setting_key,
                                               type=bool)
        self.assertEqual(True, self.draw_grid_setting.get_value())
        self.draw_grid_setting.set_value(False)
        self.assertEqual(False, self.draw_grid_setting.get_value())

        #try again the fuzz type
        self.draw_grid_setting = ConfigSetting(draw_grid_setting_key)
        self.assertEqual(False, self.draw_grid_setting.get_value())
        self.draw_grid_setting.set_value(True)
        self.assertEqual(True, self.draw_grid_setting.get_value())

        #play sound
        play_sound_key = self.get_key('play-ready-sound')
        self.play_sound_setting = ConfigSetting(play_sound_key)
        self.assertEqual(False, self.play_sound_setting.get_value())

        #background
        background_setting = ConfigSetting(self.get_key('background'),
                                           type=str)
        self.assertEqual(
            '/usr/share/backgrounds/The_Forbidden_City_by_Daniel_Mathis.jpg',
            background_setting.get_value())
        #try again the fuzz type for str
        background_setting = ConfigSetting(self.get_key('background'))
        self.assertEqual(
            "/usr/share/backgrounds/The_Forbidden_City_by_Daniel_Mathis.jpg",
            background_setting.get_value())

    def get_key(self, key):
        return "%s::%s#%s" % (self.unity_greeter_override_path,
                              'com.canonical.unity-greeter', key)
示例#5
0
    def _parse_theme(self):
        names = self._tarfile.getnames()
        for name in names:
            if 'index.theme' in name:
                #TODO support multi themes, in the future, it's better to only install from deb
                self._index_file = name
                break

        if self._index_file:
            log.debug("the index file is; %s" % self._index_file)
            self._tarfile.extract(self._index_file, '/tmp')
            cs = ConfigSetting('/tmp/%s::Icon Theme#name' % self._index_file)
            self.theme_name = cs.get_value()

            if '/' in self._index_file and not './' in self._index_file:
                self._to_extract_dir = os.path.dirname(self._index_file)
                log.debug("Because of index file: %s, the extra dir will be: %s" % (self._index_file, self._to_extract_dir))
                self.install_name = os.path.basename(os.path.dirname(self._index_file))
            else:
                #TODO improve
                self.install_name = os.path.basename(self._path).split('.')[0]
示例#6
0
    def set_config_setting(self, key, value, sender=None):
        self._check_permission(sender, PK_ACTION_TWEAK)
        log.debug('set_config_setting: %s to %s' % (key, value))
        cs = ConfigSetting(key)
        cs.set_value(value)

        if cs.is_override_schema():
            os.system('glib-compile-schemas /usr/share/glib-2.0/schemas/')

        return value == cs.get_value()
class TestConfigSettings(unittest.TestCase):
    def setUp(self):
        self.unity_greeter_override_file = tempfile.NamedTemporaryFile(delete=False)
        self.unity_greeter_override_file.write("[com.canonical.unity-greeter]\n"
        "draw-grid = true\n"
        "play-ready-sound = false\n"
        "background = '/usr/share/backgrounds/The_Forbidden_City_by_Daniel_Mathis.jpg'\n")
        self.unity_greeter_override_file.close()
        self.unity_greeter_override_path = self.unity_greeter_override_file.name

    def test_config_settings(self):
        # draw grid
        draw_grid_setting_key = "%s::%s#%s" % (self.unity_greeter_override_path, 'com.canonical.unity-greeter', 'draw-grid')

        self.draw_grid_setting = ConfigSetting(draw_grid_setting_key, type=bool)
        self.assertEqual(True, self.draw_grid_setting.get_value())
        self.draw_grid_setting.set_value(False)
        self.assertEqual(False, self.draw_grid_setting.get_value())

        #try again the fuzz type
        self.draw_grid_setting = ConfigSetting(draw_grid_setting_key)
        self.assertEqual(False, self.draw_grid_setting.get_value())
        self.draw_grid_setting.set_value(True)
        self.assertEqual(True, self.draw_grid_setting.get_value())

        #play sound
        play_sound_key = self.get_key('play-ready-sound')
        self.play_sound_setting = ConfigSetting(play_sound_key)
        self.assertEqual(False, self.play_sound_setting.get_value())

        #background
        background_setting = ConfigSetting(self.get_key('background'), type=str)
        self.assertEqual('/usr/share/backgrounds/The_Forbidden_City_by_Daniel_Mathis.jpg', background_setting.get_value())
        #try again the fuzz type for str
        background_setting = ConfigSetting(self.get_key('background'))
        self.assertEqual("/usr/share/backgrounds/The_Forbidden_City_by_Daniel_Mathis.jpg", background_setting.get_value())

    def get_key(self, key):
        return "%s::%s#%s" % (self.unity_greeter_override_path, 'com.canonical.unity-greeter', key)
示例#8
0
    def __init__(self, **kwargs):
        key = kwargs['key']
        backend = kwargs['backend']
        default = kwargs['default']
        type = kwargs['type']

        if backend == 'gconf':
            self._setting = GconfSetting(key=key, default=default, type=type)
        elif backend == 'gsettings':
            self._setting = GSetting(key=key, default=default, type=type)
        elif backend == 'config':
            self._setting = ConfigSetting(key=key, type=type)
        elif backend == 'compiz':
            self._setting = CompizSetting(key=key)
        elif backend == 'systemconfig':
            self._setting = SystemConfigSetting(key=key, default=default, type=type)

        if hasattr(self._setting, 'connect_notify') and \
                hasattr(self, 'on_value_changed'):
            log.debug("Connect the setting notify to on_value_changed: %s" % key)
            self.get_setting().connect_notify(self.on_value_changed)
    def test_config_settings(self):
        # draw grid
        draw_grid_setting_key = "%s::%s#%s" % (
            self.unity_greeter_override_path, 'com.canonical.unity-greeter',
            'draw-grid')

        self.draw_grid_setting = ConfigSetting(draw_grid_setting_key,
                                               type=bool)
        self.assertEqual(True, self.draw_grid_setting.get_value())
        self.draw_grid_setting.set_value(False)
        self.assertEqual(False, self.draw_grid_setting.get_value())

        #try again the fuzz type
        self.draw_grid_setting = ConfigSetting(draw_grid_setting_key)
        self.assertEqual(False, self.draw_grid_setting.get_value())
        self.draw_grid_setting.set_value(True)
        self.assertEqual(True, self.draw_grid_setting.get_value())

        #play sound
        play_sound_key = self.get_key('play-ready-sound')
        self.play_sound_setting = ConfigSetting(play_sound_key)
        self.assertEqual(False, self.play_sound_setting.get_value())

        #background
        background_setting = ConfigSetting(self.get_key('background'),
                                           type=str)
        self.assertEqual(
            '/usr/share/backgrounds/The_Forbidden_City_by_Daniel_Mathis.jpg',
            background_setting.get_value())
        #try again the fuzz type for str
        background_setting = ConfigSetting(self.get_key('background'))
        self.assertEqual(
            "/usr/share/backgrounds/The_Forbidden_City_by_Daniel_Mathis.jpg",
            background_setting.get_value())