Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomeu Vizoso <tomeu@tomeuvizoso.net>2008-12-01 18:01:56 (GMT)
committer Tomeu Vizoso <tomeu@tomeuvizoso.net>2008-12-01 18:01:56 (GMT)
commitd5c5e2eec1580c07ead23eb4b6706f5e317b3eda (patch)
tree8ba7ec631282fbc4ead293ad99b373af9f0122d0
parent27d87449c5ebf2d9587873b5d1b47cd423090a3e (diff)
Make sure entries have the mountpoint property
-rw-r--r--src/jarabe/journal/model.py78
1 files changed, 43 insertions, 35 deletions
diff --git a/src/jarabe/journal/model.py b/src/jarabe/journal/model.py
index 5d2b5e1..ec5317e 100644
--- a/src/jarabe/journal/model.py
+++ b/src/jarabe/journal/model.py
@@ -95,14 +95,54 @@ class ResultSet(object):
length = property(get_length)
+ def _get_all_files(self, dir_path):
+ files = []
+ for entry in os.listdir(dir_path):
+ full_path = os.path.join(dir_path, entry)
+ if os.path.isdir(full_path):
+ files.extend(self._get_all_files(full_path))
+ elif os.path.isfile(full_path):
+ stat = os.stat(full_path)
+ files.append((full_path, stat.st_mtime))
+ return files
+
+ def _query_mount_point(self, mount_point, query):
+ t = time.time()
+
+ files = self._get_all_files(mount_point)
+ offset = int(query.get('offset', 0))
+ limit = int(query.get('limit', len(files)))
+
+ total_count = len(files)
+ files.sort(lambda a, b: int(b[1] - a[1]))
+ files = files[offset:offset + limit]
+
+ result = []
+ for file_path, timestamp_ in files:
+ metadata = _get_file_metadata(file_path)
+ result.append(metadata)
+
+ logging.debug('_query_mount_point took %f s.' % (time.time() - t))
+
+ return result, total_count
+
def _find(self, query):
mount_points = query.get('mountpoints', ['/'])
if mount_points is None or len(mount_points) != 1:
raise ValueError('Exactly one mount point must be specified')
+
if mount_points[0] == '/':
- return _get_datastore().find(query, PROPERTIES, byte_arrays=True)
+ data_store = _get_datastore()
+ entries, total_count = _get_datastore().find(query, PROPERTIES,
+ byte_arrays=True)
else:
- return _query_mount_point(mount_points[0], query)
+ entries, total_count = self._query_mount_point(mount_points[0],
+ query)
+
+ for entry in entries:
+ entry['mountpoint'] = mount_points[0]
+
+ return entries, total_count
def seek(self, position):
self._position = position
@@ -206,38 +246,6 @@ def _get_file_metadata(path):
'activity_id': '',
'icon-color': client.get_string('/desktop/sugar/user/color')}
-def _get_all_files(dir_path):
- files = []
- for entry in os.listdir(dir_path):
- full_path = os.path.join(dir_path, entry)
- if os.path.isdir(full_path):
- files.extend(_get_all_files(full_path))
- elif os.path.isfile(full_path):
- stat = os.stat(full_path)
- files.append((full_path, stat.st_mtime))
- return files
-
-def _query_mount_point(mount_point, query):
- t = time.time()
-
- files = _get_all_files(mount_point)
- offset = int(query.get('offset', 0))
- limit = int(query.get('limit', len(files)))
-
- total_count = len(files)
- files.sort(lambda a, b: int(b[1] - a[1]))
- files = files[offset:offset + limit]
-
- result = []
- for file_path, timestamp_ in files:
- metadata = _get_file_metadata(file_path)
- metadata['mountpoint'] = mount_point
- result.append(metadata)
-
- logging.debug('_query_mount_point took %f s.' % (time.time() - t))
-
- return result, total_count
-
_datastore = None
def _get_datastore():
global _datastore
@@ -327,7 +335,7 @@ def write(metadata, file_path='', update_mtime=True):
file_path,
True)
else:
- pass
+ raise NotImplementedError(metadata['mountpoint'])
return object_id