[wiican/gnome3porting: 3/3] [m/manager] Mapping visibility and sort preferences stored as string due GConf set_list is not imple
- From: J. FÃlix OntaÃÃn <felixonta src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [wiican/gnome3porting: 3/3] [m/manager] Mapping visibility and sort preferences stored as string due GConf set_list is not imple
- Date: Sun, 19 Aug 2012 23:24:44 +0000 (UTC)
commit 85ac00ba7e5342be63b32483e0c6f61cce9366af
Author: J. FÃlix OntaÃÃn <fontanon emergya es>
Date: Wed Aug 15 23:53:23 2012 +0200
[m/manager] Mapping visibility and sort preferences stored as string due GConf set_list is not implemented
wiican/mapping/manager.py | 48 ++++++++++++++++++++++++++++----------------
wiican/utils.py | 24 +++++++++-------------
2 files changed, 40 insertions(+), 32 deletions(-)
---
diff --git a/wiican/mapping/manager.py b/wiican/mapping/manager.py
index b72634d..db2ad32 100644
--- a/wiican/mapping/manager.py
+++ b/wiican/mapping/manager.py
@@ -32,7 +32,7 @@ from wiican.utils import Singleton, GConfStore
from wiican.mapping.mapping import Mapping
from wiican.defs import GCONF_KEY, MAPPINGS_HOME_DIR, MAPPINGS_BASE_DIR, \
INIT_PACKAGES
-
+
class MappingManager(Singleton, GConfStore):
"""
Handles one-shot mapping manager instance (singleton).
@@ -43,12 +43,16 @@ class MappingManager(Singleton, GConfStore):
The MappingManager object offers some python dict methods allowing to get/set
attributes, iteration, deletion and check size (number of mappings managed).
"""
-
- defaults = {'default_mapping': '', 'mapping_sort': [], 'mapping_visible': set([])}
-
+
+ defaults = {
+ 'default_mapping': '',
+ 'mapping_sort': [],
+ 'mapping_visible': set([])
+ }
+
def __init__(self):
"""Gets the single mapping manager instance"""
-
+
Singleton.__init__(self)
GConfStore.__init__(self, GCONF_KEY)
@@ -60,18 +64,26 @@ class MappingManager(Singleton, GConfStore):
self.__mapping_bag = {}
self.loadconf(only_defaults=True)
- self.options['mapping_visible'] = set(self.options['mapping_visible'])
+
+ #TODO: Hacking 'till GConf set_list method is implemented
+ if self.options['mapping_sort']:
+ self.options['mapping_sort'] = \
+ [str(x) for x in self.options['mapping_sort'].split(' ')]
+
+ if self.options['mapping_visible']:
+ self.options['mapping_visible'] = \
+ set([str(x) for x in self.options['mapping_visible'].split(' ')])
def scan_mappings(self):
"""
Scan mappings from default system and user data directories.
Auto-import the initial wiican mapping packages into user data dir if it
doesn't exists.
-
+
Mappings are distinguished by dirname. If a system mapping has the same
dirname as the user data dir, the system mapping it's ignored.
"""
-
+
def load_mapping(mappings, dirname, fnames):
if Mapping.info_filename in fnames and Mapping.mapping_filename in fnames:
mapping_id = os.path.splitext(os.path.basename(dirname))[0]
@@ -139,13 +151,13 @@ class MappingManager(Singleton, GConfStore):
for f in os.listdir(mapping_tmp_path):
package_file.add(os.path.join(mapping_tmp_path, f), arcname=f)
-
+
package_file.close()
shutil.rmtree(mapping_tmp_path)
-
+
def add_new_mapping(self, mapping):
"""Add a mapping to be controlled by mapping manager"""
-
+
mapping_id = self.__gen_unique_mapping_id()
mapping_path = os.path.join(self.home_path, mapping_id)
mapping.write(mapping_path)
@@ -157,7 +169,7 @@ class MappingManager(Singleton, GConfStore):
def write_mapping(self, mapping):
"""Write a mapping to disk"""
-
+
if os.path.dirname(mapping.get_path()) in self.system_paths:
return self.add_new_mapping(copy.copy(mapping))
else:
@@ -166,10 +178,10 @@ class MappingManager(Singleton, GConfStore):
def swap_mapping_order(self, mapping_id1, mapping_id2, after=False):
"""Swaps mapping_id2 before mapping_id1"""
-
+
if not mapping_id1 in self.__mapping_bag:
raise MappingManagerError, _('Mapping not found:') + ' ' + mapping_id1
-
+
if not mapping_id2 in self.__mapping_bag:
raise MappingManagerError, _('Mapping not found:') + ' ' + mapping_id2
@@ -188,12 +200,12 @@ class MappingManager(Singleton, GConfStore):
def is_system_mapping(self, mapping_id):
"""Check if the mapping (identified by mapping_id) it's a system mapping"""
-
+
if not mapping_id in self.__mapping_bag:
raise MappingManagerError, _('Mapping not found:') + ' ' + mapping_id
return os.path.dirname(self.__mapping_bag[mapping_id].get_path()) in self.system_paths
-
+
def is_visible(self, mapping_id):
"""Check if the mapping (identified by mapping_id) it's marked as visible"""
@@ -201,7 +213,7 @@ class MappingManager(Singleton, GConfStore):
raise MappingManagerError, _('Mapping not found:') + ' ' + mapping_id
return mapping_id in self.options['mapping_visible']
-
+
def set_visible(self, mapping_id, visible):
"""Mark a mapping (identified by mapping_id) as visible or invisible"""
@@ -240,7 +252,7 @@ class MappingManager(Singleton, GConfStore):
if os.path.exists(os.path.join(self.home_path, mapping_id)):
mapping_id = str(random.randint(1,999999))
else: break
-
+
return mapping_id
def __delitem__(self, mapping_id):
diff --git a/wiican/utils.py b/wiican/utils.py
index dbd3148..763427e 100644
--- a/wiican/utils.py
+++ b/wiican/utils.py
@@ -91,26 +91,22 @@ class GConfStore(object):
self.options[entry.key.split('/')[-1]] = casts[gval.type](gval)
def saveconf(self):
+ #TODO: Hacking 'till GConf set_list method is implemented
+ def gconf_client_serialize_list(client, app_key, itemlist):
+ itemlist_serialized = ' '.join([str(item) for item in itemlist])
+ GConf.Client.set_string(client, app_key, itemlist_serialized)
+
casts = {types.BooleanType: GConf.Client.set_bool,
types.IntType: GConf.Client.set_int,
types.FloatType: GConf.Client.set_float,
- types.StringType: GConf.Client.set_string}
- # This will be disabled until set_list method is implemented
- """
- types.ListType: GConf.Client.set_list,
- types.TupleType: GConf.Client.set_list,
- set: GConf.Client.set_list}
- """
+ types.StringType: GConf.Client.set_string,
+ types.ListType: gconf_client_serialize_list,
+ types.TupleType: gconf_client_serialize_list,
+ set: gconf_client_serialize_list}
#TODO: To clear the gconf dir before save, is it convenient?
for name, value in self.options.items():
- if type(value) in (list, tuple, set):
- string_value = [str(item) for item in value]
- casts[type(value)](self.__client, self.__app_key + '/' + name,
- GConf.ValueType.STRING, string_value)
- else:
- casts[type(value)](self.__client, self.__app_key + '/' + name,
- value)
+ casts[type(value)](self.__client, self.__app_key + '/' + name, value)
class GConfStoreError(exceptions.Exception):
pass
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]