From babce9fc50b557a529e675e2dc8140b73b417a63 Mon Sep 17 00:00:00 2001 From: Sascha Silbe Date: Wed, 19 Aug 2009 14:00:22 +0000 Subject: let the logger do the formatting --- diff --git a/src/carquinyol/datastore.py b/src/carquinyol/datastore.py index 41b16b5..dc2e167 100644 --- a/src/carquinyol/datastore.py +++ b/src/carquinyol/datastore.py @@ -71,8 +71,7 @@ class DataStore(dbus.service.Object): try: self._index_store.open_index() except Exception: - logging.error('Failed to open index, will rebuild\n%s' \ - % traceback.format_exc()) + logging.exception('Failed to open index, will rebuild') layout_manager.index_updated = False self._index_store.remove_index() self._index_store.open_index() @@ -87,7 +86,7 @@ class DataStore(dbus.service.Object): def _rebuild_index(self): uids = layoutmanager.get_instance().find_all() - logging.debug('Going to update the index with uids %r' % uids) + logging.debug('Going to update the index with uids %r', uids) gobject.idle_add(lambda: self.__rebuild_index_cb(uids), priority=gobject.PRIORITY_LOW) @@ -95,16 +94,15 @@ class DataStore(dbus.service.Object): if uids: uid = uids.pop() - logging.debug('Updating entry %r in index. %d to go.' % \ - (uid, len(uids))) + logging.debug('Updating entry %r in index. %d to go.', uid, + len(uids)) if not self._index_store.contains(uid): try: props = self._metadata_store.retrieve(uid) self._index_store.store(uid, props) except Exception: - logging.error('Error processing %r\n%s.' \ - % (uid, traceback.format_exc())) + logging.exception('Error processing %r', uid) if not uids: logging.debug('Finished updating index.') @@ -114,15 +112,15 @@ class DataStore(dbus.service.Object): return True def _create_completion_cb(self, async_cb, async_err_cb, uid, exc=None): - logger.debug("_create_completion_cb(%r, %r, %r, %r)" % \ - (async_cb, async_err_cb, uid, exc)) + logger.debug('_create_completion_cb(%r, %r, %r, %r)', async_cb, + async_err_cb, uid, exc) if exc is not None: async_err_cb(exc) return self.Created(uid) self._optimizer.optimize(uid) - logger.debug("created %s" % uid) + logger.debug('created %s', uid) async_cb(uid) @dbus.service.method(DS_DBUS_INTERFACE, @@ -133,7 +131,7 @@ class DataStore(dbus.service.Object): def create(self, props, file_path, transfer_ownership, async_cb, async_err_cb): uid = str(uuid.uuid4()) - logging.debug('datastore.create %r' % uid) + logging.debug('datastore.create %r', uid) if not props.get('timestamp', ''): props['timestamp'] = int(time.time()) @@ -151,15 +149,15 @@ class DataStore(dbus.service.Object): pass def _update_completion_cb(self, async_cb, async_err_cb, uid, exc=None): - logger.debug("_update_completion_cb() called with %r / %r, exc %r" % \ - (async_cb, async_err_cb, exc)) + logger.debug('_update_completion_cb() called with %r / %r, exc %r', + async_cb, async_err_cb, exc) if exc is not None: async_err_cb(exc) return self.Updated(uid) self._optimizer.optimize(uid) - logger.debug("updated %s" % uid) + logger.debug('updated %s', uid) async_cb() @dbus.service.method(DS_DBUS_INTERFACE, @@ -169,7 +167,7 @@ class DataStore(dbus.service.Object): byte_arrays=True) def update(self, uid, props, file_path, transfer_ownership, async_cb, async_err_cb): - logging.debug('datastore.update %r' % uid) + logging.debug('datastore.update %r', uid) if not props.get('timestamp', ''): props['timestamp'] = int(time.time()) @@ -194,15 +192,14 @@ class DataStore(dbus.service.Object): in_signature='a{sv}as', out_signature='aa{sv}u') def find(self, query, properties): - logging.debug('datastore.find %r' % query) + logging.debug('datastore.find %r', query) t = time.time() if layoutmanager.get_instance().index_updated: try: uids, count = self._index_store.find(query) except Exception: - logging.error('Failed to query index, will rebuild\n%s' \ - % traceback.format_exc()) + logging.exception('Failed to query index, will rebuild') layoutmanager.get_instance().index_updated = False self._index_store.close_index() self._index_store.remove_index() @@ -231,7 +228,7 @@ class DataStore(dbus.service.Object): metadata = self._metadata_store.retrieve(uid, properties) entries.append(metadata) - logger.debug('find(): %r' % (time.time() - t)) + logger.debug('find(): %r', time.time() - t) return entries, count @@ -255,7 +252,7 @@ class DataStore(dbus.service.Object): out_signature='s', sender_keyword='sender') def get_filename(self, uid, sender=None): - logging.debug('datastore.get_filename %r' % uid) + logging.debug('datastore.get_filename %r', uid) user_id = dbus.Bus().get_unix_user(sender) extension = self._get_extension(uid) return self._file_store.retrieve(uid, user_id, extension) @@ -270,7 +267,7 @@ class DataStore(dbus.service.Object): in_signature='s', out_signature='a{sv}') def get_properties(self, uid): - logging.debug('datastore.get_properties %r' % uid) + logging.debug('datastore.get_properties %r', uid) metadata = self._metadata_store.retrieve(uid) return metadata @@ -302,7 +299,7 @@ class DataStore(dbus.service.Object): os.removedirs(entry_path) self.Deleted(uid) - logger.debug("deleted %s" % uid) + logger.debug('deleted %s', uid) @dbus.service.signal(DS_DBUS_INTERFACE, signature="s") def Deleted(self, uid): diff --git a/src/carquinyol/filestore.py b/src/carquinyol/filestore.py index 0e018bd..71d6344 100644 --- a/src/carquinyol/filestore.py +++ b/src/carquinyol/filestore.py @@ -45,8 +45,8 @@ class FileStore(object): raise ValueError('No file at %r' % file_path) if transfer_ownership: try: - logging.debug('FileStore moving from %r to %r' % \ - (file_path, destination_path)) + logging.debug('FileStore moving from %r to %r', file_path, + destination_path) os.rename(file_path, destination_path) completion_cb() except OSError, e: @@ -72,8 +72,8 @@ class FileStore(object): """Start copying a file asynchronously. """ - logging.debug('FileStore copying from %r to %r' % \ - (file_path, destination_path)) + logging.debug('FileStore copying from %r to %r', file_path, + destination_path) async_copy = AsyncCopy(file_path, destination_path, completion_cb) async_copy.start() @@ -85,7 +85,7 @@ class FileStore(object): """ file_path = layoutmanager.get_instance().get_data_path(uid) if not os.path.exists(file_path): - logging.debug('Entry %r doesnt have any file' % uid) + logging.debug('Entry %r doesnt have any file', uid) return '' use_instance_dir = os.path.exists('/etc/olpc-security') and \ @@ -158,10 +158,10 @@ class FileStore(object): existing_file = layoutmanager.get_instance().get_data_path(existing_uid) new_file = layoutmanager.get_instance().get_data_path(new_uid) - logging.debug('removing %r' % new_file) + logging.debug('removing %r', new_file) os.remove(new_file) - logging.debug('hard linking %r -> %r' % (new_file, existing_file)) + logging.debug('hard linking %r -> %r', new_file, existing_file) os.link(existing_file, new_file) @@ -193,7 +193,7 @@ class AsyncCopy(object): # error writing data to file? if count < len(data): logging.error('AC: Error writing %s -> %s: wrote less than ' - 'expected' % (self.src, self.dest)) + 'expected', self.src, self.dest) self._cleanup() self.completion(RuntimeError( 'Error writing data to destination file')) @@ -207,8 +207,8 @@ class AsyncCopy(object): self.completion(None) return False except Exception, err: - logging.error("AC: Error copying %s -> %s: %r" % \ - (self.src, self.dest, err)) + logging.error('AC: Error copying %s -> %s: %r', self.src, self. + dest, err) self._cleanup() self.completion(err) return False diff --git a/src/carquinyol/indexstore.py b/src/carquinyol/indexstore.py index 06a41e0..6a70aee 100644 --- a/src/carquinyol/indexstore.py +++ b/src/carquinyol/indexstore.py @@ -304,8 +304,7 @@ class IndexStore(object): def _flush(self, force=False): """Called after any database mutation""" - logging.debug('IndexStore.flush: %r %r' % - (force, self._pending_writes)) + logging.debug('IndexStore.flush: %r %r', force, self._pending_writes) if self._flush_timeout is not None: gobject.source_remove(self._flush_timeout) diff --git a/src/carquinyol/migration.py b/src/carquinyol/migration.py index ed82558..95ee391 100644 --- a/src/carquinyol/migration.py +++ b/src/carquinyol/migration.py @@ -43,14 +43,13 @@ def migrate_from_0(): if ext != '.metadata': continue - logging.debug('Migrating entry %r' % uid) + logging.debug('Migrating entry %r', uid) try: _migrate_metadata(root_path, old_root_path, uid) _migrate_file(root_path, old_root_path, uid) _migrate_preview(root_path, old_root_path, uid) except Exception: - logging.error('Error while migrating entry %r: %s\n' % \ - (uid, traceback.format_exc())) + logging.exception('Error while migrating entry %r', uid) # Just be paranoid, it's cheap. if old_root_path.endswith('datastore/store'): @@ -86,9 +85,8 @@ def _migrate_metadata(root_path, old_root_path, uid): finally: f.close() except Exception: - logging.error( - 'Error while migrating property %s of entry %s: %s\n' % \ - (key, uid, traceback.format_exc())) + logging.exception( + 'Error while migrating property %s of entry %s', key, uid) def _migrate_file(root_path, old_root_path, uid): diff --git a/src/carquinyol/optimizer.py b/src/carquinyol/optimizer.py index 6cb1374..2b6ce29 100644 --- a/src/carquinyol/optimizer.py +++ b/src/carquinyol/optimizer.py @@ -42,7 +42,7 @@ class Optimizer(object): queue_path = layoutmanager.get_instance().get_queue_path() open(os.path.join(queue_path, uid), 'w').close() - logging.debug('optimize %r' % os.path.join(queue_path, uid)) + logging.debug('optimize %r', os.path.join(queue_path, uid)) if self._enqueue_checksum_id is None: self._enqueue_checksum_id = \ @@ -62,13 +62,13 @@ class Optimizer(object): checksum_entry_path = os.path.join(checksum_path, uid) if os.path.exists(checksum_entry_path): - logging.debug('remove %r' % checksum_entry_path) + logging.debug('remove %r', checksum_entry_path) os.remove(checksum_entry_path) if os.path.exists(checksum_path): try: os.rmdir(checksum_path) - logging.debug('removed %r' % checksum_path) + logging.debug('removed %r', checksum_path) except OSError, e: if e.errno != errno.ENOTEMPTY: raise @@ -96,7 +96,7 @@ class Optimizer(object): """ checksums_dir = layoutmanager.get_instance().get_checksums_dir() checksum_path = os.path.join(checksums_dir, checksum) - logging.debug('create dir %r' % checksum_path) + logging.debug('create dir %r', checksum_path) os.mkdir(checksum_path) def _add_checksum_entry(self, uid, checksum): @@ -106,7 +106,7 @@ class Optimizer(object): checksums_dir = layoutmanager.get_instance().get_checksums_dir() checksum_path = os.path.join(checksums_dir, checksum) - logging.debug('touch %r' % os.path.join(checksum_path, uid)) + logging.debug('touch %r', os.path.join(checksum_path, uid)) open(os.path.join(checksum_path, uid), 'w').close() def _already_linked(self, uid, checksum): @@ -128,11 +128,11 @@ class Optimizer(object): queue = os.listdir(queue_path) if queue: uid = queue[0] - logging.debug('_process_entry_cb processing %r' % uid) + logging.debug('_process_entry_cb processing %r', uid) file_in_entry_path = self._file_store.get_file_path(uid) if not os.path.exists(file_in_entry_path): - logging.info('non-existent entry in queue: %r' % uid) + logging.info('non-existent entry in queue: %r', uid) else: checksum = self._calculate_md5sum(file_in_entry_path) self._metadata_store.set_property(uid, 'checksum', checksum) -- cgit v0.9.1