diff options
author | Vincent Untz <vuntz@gnome.org> | 2010-07-07 16:28:10 +0200 |
---|---|---|
committer | Vincent Untz <vuntz@gnome.org> | 2010-07-07 16:28:10 +0200 |
commit | 4b069e2e109c9ac4e5c7b39da7fd3c10ea9544e8 (patch) | |
tree | b5c2f6a5a8c61c643dd4500ce25c42996162a0b2 | |
parent | c7a66451a18f425905ef467027a2b875523929a6 (diff) | |
download | gconf-4b069e2e109c9ac4e5c7b39da7fd3c10ea9544e8.tar.gz |
[gsettings] Accept gconf schemas without default values
We use a 'neutral' default value in this case (0, empty string, false).
Also, check that int and float default values are valid.
-rwxr-xr-x | gsettings/gsettings-schema-convert | 40 |
1 files changed, 34 insertions, 6 deletions
diff --git a/gsettings/gsettings-schema-convert b/gsettings/gsettings-schema-convert index 38bd13b9..5bdd5009 100755 --- a/gsettings/gsettings-schema-convert +++ b/gsettings/gsettings-schema-convert @@ -761,12 +761,37 @@ def map_gconf_type_to_variant_type(gconftype, gconfsubtype): def fix_value_for_simple_gconf_type(gconftype, gconfvalue): + '''If there is no value, then we choose a 'neutral' value (false, 0, empty + string). + ''' if gconftype == 'string': if not gconfvalue: return '\'\'' - else: - return '\'' + gconfvalue.replace('\'', '\\\'') + '\'' + return '\'' + gconfvalue.replace('\'', '\\\'') + '\'' + elif gconftype == 'int': + if not gconfvalue: + return '0' + + try: + int(gconfvalue) + except ValueError: + raise GSettingsSchemaConvertException() + + return gconfvalue + elif gconftype == 'float': + if not gconfvalue: + return '0.0' + + try: + float(gconfvalue) + except ValueError: + raise GSettingsSchemaConvertException() + + return gconfvalue elif gconftype == 'bool': + if not gconfvalue: + return 'false' + value = gconfvalue.lower() # gconf schemas can have 0/1 for false/true if value == '0': @@ -813,9 +838,9 @@ class GConfSchema: except: try: self.default = node.find('default').text - self.localized = None except: - raise GSettingsSchemaConvertException('No default value for key \'%s\'. A default value is always required in GSettings schemas.' % self.applyto or self.key) + self.default = '' + self.localized = None self.typed_default = None self.short = self._get_value_with_locale(node, locale_node, 'short') @@ -826,11 +851,14 @@ class GConfSchema: if self.long: self.long = self._oneline(self.long) - # Fix the default to be parsable by GVariant + # Fix the default value to be parsable by GVariant if self.type == 'list': l = self.default.strip() if not (l[0] == '[' and l[-1] == ']'): - raise GSettingsSchemaConvertException('Cannot parse default list value \'%s\' for key \'%s\'.' % (self.default, self.applyto or self.key)) + if not l: + l = '[]' + else: + raise GSettingsSchemaConvertException('Cannot parse default list value \'%s\' for key \'%s\'.' % (self.default, self.applyto or self.key)) values = l[1:-1].strip() if not values: self.default = '[]' |