Add a parameter to datastore.find() for filtering out unwanted metadata properties.

This commit is contained in:
Tomeu Vizoso 2007-09-10 18:03:40 +02:00
parent e9449d0ab0
commit 79237f3114
2 changed files with 20 additions and 10 deletions

View File

@ -158,7 +158,7 @@ class DSObject(object):
def destroy(self): def destroy(self):
if self._destroyed: if self._destroyed:
logging.warning('This DSObject has already been destroyed!.') logging.warning('This DSObject has already been destroyed!.')
import pdb;pdb.set_trace() import traceback;traceback.print_stack()
return return
self._destroyed = True self._destroyed = True
if self._file_path and self._owns_file: if self._file_path and self._owns_file:
@ -199,17 +199,27 @@ def write(ds_object, update_mtime=True, transfer_ownership=False, reply_handler=
properties['mtime'] = datetime.now().isoformat() properties['mtime'] = datetime.now().isoformat()
properties['timestamp'] = int(time.time()) properties['timestamp'] = int(time.time())
if ds_object._file_path is None:
file_path = ''
else:
file_path = ds_object._file_path
# FIXME: this func will be sync for creates regardless of the handlers
# supplied. This is very bad API, need to decide what to do here.
if ds_object.object_id: if ds_object.object_id:
dbus_helpers.update(ds_object.object_id, dbus_helpers.update(ds_object.object_id,
properties, properties,
ds_object.file_path, file_path,
transfer_ownership, transfer_ownership,
reply_handler=reply_handler, reply_handler=reply_handler,
error_handler=error_handler, error_handler=error_handler,
timeout=timeout) timeout=timeout)
else: else:
if reply_handler or error_handler:
logging.warning('datastore.write() cannot currently be called async' \
' for creates, see https://dev.laptop.org/ticket/3071')
ds_object.object_id = dbus_helpers.create(properties, ds_object.object_id = dbus_helpers.create(properties,
ds_object.file_path, file_path,
transfer_ownership) transfer_ownership)
# TODO: register the object for updates # TODO: register the object for updates
logging.debug('Written object %s to the datastore.' % ds_object.object_id) logging.debug('Written object %s to the datastore.' % ds_object.object_id)
@ -218,8 +228,8 @@ def delete(object_id):
logging.debug('datastore.delete') logging.debug('datastore.delete')
dbus_helpers.delete(object_id) dbus_helpers.delete(object_id)
def find(query, sorting=None, limit=None, offset=None, reply_handler=None, def find(query, sorting=None, limit=None, offset=None, properties=[],
error_handler=None): reply_handler=None, error_handler=None):
query = query.copy() query = query.copy()
@ -230,7 +240,7 @@ def find(query, sorting=None, limit=None, offset=None, reply_handler=None,
if offset: if offset:
query['offset'] = offset query['offset'] = offset
props_list, total_count = dbus_helpers.find(query, reply_handler, error_handler) props_list, total_count = dbus_helpers.find(query, properties, reply_handler, error_handler)
objects = [] objects = []
for props in props_list: for props in props_list:

View File

@ -74,13 +74,13 @@ def get_filename(uid):
logging.debug('dbus_helpers.get_filename: %s, %s' % (uid, filename)) logging.debug('dbus_helpers.get_filename: %s, %s' % (uid, filename))
return filename return filename
def find(query, reply_handler, error_handler): def find(query, properties, reply_handler, error_handler):
logging.debug('dbus_helpers.find: %r' % query) logging.debug('dbus_helpers.find: %r' % query)
if reply_handler and error_handler: if reply_handler and error_handler:
return _get_data_store().find(query, reply_handler=reply_handler, return _get_data_store().find(query, properties,
error_handler=error_handler) reply_handler=reply_handler, error_handler=error_handler)
else: else:
return _get_data_store().find(query) return _get_data_store().find(query, properties)
def mount(uri, options): def mount(uri, options):
return _get_data_store().mount(uri, options) return _get_data_store().mount(uri, options)