Attachments you submit will be routed for moderation. If you have an account, please
log in first.
Ticket #1211: 0001-let-the-logger-do-the-formatting.patch
|
File 0001-let-the-logger-do-the-formatting.patch, 14.2 KB
(added by sascha_silbe, 4 years ago)
|
|
let the logger do the formatting
|
-
From e555903564cffb1a206606d9e7c8848e3bc99efa Mon Sep 17 00:00:00 2001
From: Sascha Silbe <sascha@silbe.org>
Date: Wed, 19 Aug 2009 16:00:22 +0200
Subject: [PATCH] let the logger do the formatting
---
src/carquinyol/datastore.py | 41 +++++++++++++++++++----------------------
src/carquinyol/filestore.py | 20 ++++++++++----------
src/carquinyol/indexstore.py | 3 +--
src/carquinyol/migration.py | 10 ++++------
src/carquinyol/optimizer.py | 14 +++++++-------
5 files changed, 41 insertions(+), 47 deletions(-)
diff --git a/src/carquinyol/datastore.py b/src/carquinyol/datastore.py
index 41b16b5..dc2e167 100644
|
a
|
b
|
|
| 71 | 71 | try: |
| 72 | 72 | self._index_store.open_index() |
| 73 | 73 | except Exception: |
| 74 | | logging.error('Failed to open index, will rebuild\n%s' \ |
| 75 | | % traceback.format_exc()) |
| | 74 | logging.exception('Failed to open index, will rebuild') |
| 76 | 75 | layout_manager.index_updated = False |
| 77 | 76 | self._index_store.remove_index() |
| 78 | 77 | self._index_store.open_index() |
| … |
… |
|
| 87 | 86 | |
| 88 | 87 | def _rebuild_index(self): |
| 89 | 88 | uids = layoutmanager.get_instance().find_all() |
| 90 | | logging.debug('Going to update the index with uids %r' % uids) |
| | 89 | logging.debug('Going to update the index with uids %r', uids) |
| 91 | 90 | gobject.idle_add(lambda: self.__rebuild_index_cb(uids), |
| 92 | 91 | priority=gobject.PRIORITY_LOW) |
| 93 | 92 | |
| … |
… |
|
| 95 | 94 | if uids: |
| 96 | 95 | uid = uids.pop() |
| 97 | 96 | |
| 98 | | logging.debug('Updating entry %r in index. %d to go.' % \ |
| 99 | | (uid, len(uids))) |
| | 97 | logging.debug('Updating entry %r in index. %d to go.', uid, |
| | 98 | len(uids)) |
| 100 | 99 | |
| 101 | 100 | if not self._index_store.contains(uid): |
| 102 | 101 | try: |
| 103 | 102 | props = self._metadata_store.retrieve(uid) |
| 104 | 103 | self._index_store.store(uid, props) |
| 105 | 104 | except Exception: |
| 106 | | logging.error('Error processing %r\n%s.' \ |
| 107 | | % (uid, traceback.format_exc())) |
| | 105 | logging.exception('Error processing %r', uid) |
| 108 | 106 | |
| 109 | 107 | if not uids: |
| 110 | 108 | logging.debug('Finished updating index.') |
| … |
… |
|
| 114 | 112 | return True |
| 115 | 113 | |
| 116 | 114 | def _create_completion_cb(self, async_cb, async_err_cb, uid, exc=None): |
| 117 | | logger.debug("_create_completion_cb(%r, %r, %r, %r)" % \ |
| 118 | | (async_cb, async_err_cb, uid, exc)) |
| | 115 | logger.debug('_create_completion_cb(%r, %r, %r, %r)', async_cb, |
| | 116 | async_err_cb, uid, exc) |
| 119 | 117 | if exc is not None: |
| 120 | 118 | async_err_cb(exc) |
| 121 | 119 | return |
| 122 | 120 | |
| 123 | 121 | self.Created(uid) |
| 124 | 122 | self._optimizer.optimize(uid) |
| 125 | | logger.debug("created %s" % uid) |
| | 123 | logger.debug('created %s', uid) |
| 126 | 124 | async_cb(uid) |
| 127 | 125 | |
| 128 | 126 | @dbus.service.method(DS_DBUS_INTERFACE, |
| … |
… |
|
| 133 | 131 | def create(self, props, file_path, transfer_ownership, |
| 134 | 132 | async_cb, async_err_cb): |
| 135 | 133 | uid = str(uuid.uuid4()) |
| 136 | | logging.debug('datastore.create %r' % uid) |
| | 134 | logging.debug('datastore.create %r', uid) |
| 137 | 135 | |
| 138 | 136 | if not props.get('timestamp', ''): |
| 139 | 137 | props['timestamp'] = int(time.time()) |
| … |
… |
|
| 151 | 149 | pass |
| 152 | 150 | |
| 153 | 151 | def _update_completion_cb(self, async_cb, async_err_cb, uid, exc=None): |
| 154 | | logger.debug("_update_completion_cb() called with %r / %r, exc %r" % \ |
| 155 | | (async_cb, async_err_cb, exc)) |
| | 152 | logger.debug('_update_completion_cb() called with %r / %r, exc %r', |
| | 153 | async_cb, async_err_cb, exc) |
| 156 | 154 | if exc is not None: |
| 157 | 155 | async_err_cb(exc) |
| 158 | 156 | return |
| 159 | 157 | |
| 160 | 158 | self.Updated(uid) |
| 161 | 159 | self._optimizer.optimize(uid) |
| 162 | | logger.debug("updated %s" % uid) |
| | 160 | logger.debug('updated %s', uid) |
| 163 | 161 | async_cb() |
| 164 | 162 | |
| 165 | 163 | @dbus.service.method(DS_DBUS_INTERFACE, |
| … |
… |
|
| 169 | 167 | byte_arrays=True) |
| 170 | 168 | def update(self, uid, props, file_path, transfer_ownership, |
| 171 | 169 | async_cb, async_err_cb): |
| 172 | | logging.debug('datastore.update %r' % uid) |
| | 170 | logging.debug('datastore.update %r', uid) |
| 173 | 171 | |
| 174 | 172 | if not props.get('timestamp', ''): |
| 175 | 173 | props['timestamp'] = int(time.time()) |
| … |
… |
|
| 194 | 192 | in_signature='a{sv}as', |
| 195 | 193 | out_signature='aa{sv}u') |
| 196 | 194 | def find(self, query, properties): |
| 197 | | logging.debug('datastore.find %r' % query) |
| | 195 | logging.debug('datastore.find %r', query) |
| 198 | 196 | t = time.time() |
| 199 | 197 | |
| 200 | 198 | if layoutmanager.get_instance().index_updated: |
| 201 | 199 | try: |
| 202 | 200 | uids, count = self._index_store.find(query) |
| 203 | 201 | except Exception: |
| 204 | | logging.error('Failed to query index, will rebuild\n%s' \ |
| 205 | | % traceback.format_exc()) |
| | 202 | logging.exception('Failed to query index, will rebuild') |
| 206 | 203 | layoutmanager.get_instance().index_updated = False |
| 207 | 204 | self._index_store.close_index() |
| 208 | 205 | self._index_store.remove_index() |
| … |
… |
|
| 231 | 228 | metadata = self._metadata_store.retrieve(uid, properties) |
| 232 | 229 | entries.append(metadata) |
| 233 | 230 | |
| 234 | | logger.debug('find(): %r' % (time.time() - t)) |
| | 231 | logger.debug('find(): %r', time.time() - t) |
| 235 | 232 | |
| 236 | 233 | return entries, count |
| 237 | 234 | |
| … |
… |
|
| 255 | 252 | out_signature='s', |
| 256 | 253 | sender_keyword='sender') |
| 257 | 254 | def get_filename(self, uid, sender=None): |
| 258 | | logging.debug('datastore.get_filename %r' % uid) |
| | 255 | logging.debug('datastore.get_filename %r', uid) |
| 259 | 256 | user_id = dbus.Bus().get_unix_user(sender) |
| 260 | 257 | extension = self._get_extension(uid) |
| 261 | 258 | return self._file_store.retrieve(uid, user_id, extension) |
| … |
… |
|
| 270 | 267 | in_signature='s', |
| 271 | 268 | out_signature='a{sv}') |
| 272 | 269 | def get_properties(self, uid): |
| 273 | | logging.debug('datastore.get_properties %r' % uid) |
| | 270 | logging.debug('datastore.get_properties %r', uid) |
| 274 | 271 | metadata = self._metadata_store.retrieve(uid) |
| 275 | 272 | return metadata |
| 276 | 273 | |
| … |
… |
|
| 302 | 299 | os.removedirs(entry_path) |
| 303 | 300 | |
| 304 | 301 | self.Deleted(uid) |
| 305 | | logger.debug("deleted %s" % uid) |
| | 302 | logger.debug('deleted %s', uid) |
| 306 | 303 | |
| 307 | 304 | @dbus.service.signal(DS_DBUS_INTERFACE, signature="s") |
| 308 | 305 | def Deleted(self, uid): |
-
diff --git a/src/carquinyol/filestore.py b/src/carquinyol/filestore.py
index 0e018bd..71d6344 100644
|
a
|
b
|
|
| 45 | 45 | raise ValueError('No file at %r' % file_path) |
| 46 | 46 | if transfer_ownership: |
| 47 | 47 | try: |
| 48 | | logging.debug('FileStore moving from %r to %r' % \ |
| 49 | | (file_path, destination_path)) |
| | 48 | logging.debug('FileStore moving from %r to %r', file_path, |
| | 49 | destination_path) |
| 50 | 50 | os.rename(file_path, destination_path) |
| 51 | 51 | completion_cb() |
| 52 | 52 | except OSError, e: |
| … |
… |
|
| 72 | 72 | """Start copying a file asynchronously. |
| 73 | 73 | |
| 74 | 74 | """ |
| 75 | | logging.debug('FileStore copying from %r to %r' % \ |
| 76 | | (file_path, destination_path)) |
| | 75 | logging.debug('FileStore copying from %r to %r', file_path, |
| | 76 | destination_path) |
| 77 | 77 | async_copy = AsyncCopy(file_path, destination_path, completion_cb) |
| 78 | 78 | async_copy.start() |
| 79 | 79 | |
| … |
… |
|
| 85 | 85 | """ |
| 86 | 86 | file_path = layoutmanager.get_instance().get_data_path(uid) |
| 87 | 87 | if not os.path.exists(file_path): |
| 88 | | logging.debug('Entry %r doesnt have any file' % uid) |
| | 88 | logging.debug('Entry %r doesnt have any file', uid) |
| 89 | 89 | return '' |
| 90 | 90 | |
| 91 | 91 | use_instance_dir = os.path.exists('/etc/olpc-security') and \ |
| … |
… |
|
| 158 | 158 | existing_file = layoutmanager.get_instance().get_data_path(existing_uid) |
| 159 | 159 | new_file = layoutmanager.get_instance().get_data_path(new_uid) |
| 160 | 160 | |
| 161 | | logging.debug('removing %r' % new_file) |
| | 161 | logging.debug('removing %r', new_file) |
| 162 | 162 | os.remove(new_file) |
| 163 | 163 | |
| 164 | | logging.debug('hard linking %r -> %r' % (new_file, existing_file)) |
| | 164 | logging.debug('hard linking %r -> %r', new_file, existing_file) |
| 165 | 165 | os.link(existing_file, new_file) |
| 166 | 166 | |
| 167 | 167 | |
| … |
… |
|
| 193 | 193 | # error writing data to file? |
| 194 | 194 | if count < len(data): |
| 195 | 195 | logging.error('AC: Error writing %s -> %s: wrote less than ' |
| 196 | | 'expected' % (self.src, self.dest)) |
| | 196 | 'expected', self.src, self.dest) |
| 197 | 197 | self._cleanup() |
| 198 | 198 | self.completion(RuntimeError( |
| 199 | 199 | 'Error writing data to destination file')) |
| … |
… |
|
| 207 | 207 | self.completion(None) |
| 208 | 208 | return False |
| 209 | 209 | except Exception, err: |
| 210 | | logging.error("AC: Error copying %s -> %s: %r" % \ |
| 211 | | (self.src, self.dest, err)) |
| | 210 | logging.error('AC: Error copying %s -> %s: %r', self.src, self. |
| | 211 | dest, err) |
| 212 | 212 | self._cleanup() |
| 213 | 213 | self.completion(err) |
| 214 | 214 | return False |
-
diff --git a/src/carquinyol/indexstore.py b/src/carquinyol/indexstore.py
index 06a41e0..6a70aee 100644
|
a
|
b
|
|
| 304 | 304 | |
| 305 | 305 | def _flush(self, force=False): |
| 306 | 306 | """Called after any database mutation""" |
| 307 | | logging.debug('IndexStore.flush: %r %r' % |
| 308 | | (force, self._pending_writes)) |
| | 307 | logging.debug('IndexStore.flush: %r %r', force, self._pending_writes) |
| 309 | 308 | |
| 310 | 309 | if self._flush_timeout is not None: |
| 311 | 310 | gobject.source_remove(self._flush_timeout) |
-
diff --git a/src/carquinyol/migration.py b/src/carquinyol/migration.py
index ed82558..95ee391 100644
|
a
|
b
|
|
| 43 | 43 | if ext != '.metadata': |
| 44 | 44 | continue |
| 45 | 45 | |
| 46 | | logging.debug('Migrating entry %r' % uid) |
| | 46 | logging.debug('Migrating entry %r', uid) |
| 47 | 47 | try: |
| 48 | 48 | _migrate_metadata(root_path, old_root_path, uid) |
| 49 | 49 | _migrate_file(root_path, old_root_path, uid) |
| 50 | 50 | _migrate_preview(root_path, old_root_path, uid) |
| 51 | 51 | except Exception: |
| 52 | | logging.error('Error while migrating entry %r: %s\n' % \ |
| 53 | | (uid, traceback.format_exc())) |
| | 52 | logging.exception('Error while migrating entry %r', uid) |
| 54 | 53 | |
| 55 | 54 | # Just be paranoid, it's cheap. |
| 56 | 55 | if old_root_path.endswith('datastore/store'): |
| … |
… |
|
| 86 | 85 | finally: |
| 87 | 86 | f.close() |
| 88 | 87 | except Exception: |
| 89 | | logging.error( |
| 90 | | 'Error while migrating property %s of entry %s: %s\n' % \ |
| 91 | | (key, uid, traceback.format_exc())) |
| | 88 | logging.exception( |
| | 89 | 'Error while migrating property %s of entry %s', key, uid) |
| 92 | 90 | |
| 93 | 91 | |
| 94 | 92 | 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
|
b
|
|
| 42 | 42 | |
| 43 | 43 | queue_path = layoutmanager.get_instance().get_queue_path() |
| 44 | 44 | open(os.path.join(queue_path, uid), 'w').close() |
| 45 | | logging.debug('optimize %r' % os.path.join(queue_path, uid)) |
| | 45 | logging.debug('optimize %r', os.path.join(queue_path, uid)) |
| 46 | 46 | |
| 47 | 47 | if self._enqueue_checksum_id is None: |
| 48 | 48 | self._enqueue_checksum_id = \ |
| … |
… |
|
| 62 | 62 | checksum_entry_path = os.path.join(checksum_path, uid) |
| 63 | 63 | |
| 64 | 64 | if os.path.exists(checksum_entry_path): |
| 65 | | logging.debug('remove %r' % checksum_entry_path) |
| | 65 | logging.debug('remove %r', checksum_entry_path) |
| 66 | 66 | os.remove(checksum_entry_path) |
| 67 | 67 | |
| 68 | 68 | if os.path.exists(checksum_path): |
| 69 | 69 | try: |
| 70 | 70 | os.rmdir(checksum_path) |
| 71 | | logging.debug('removed %r' % checksum_path) |
| | 71 | logging.debug('removed %r', checksum_path) |
| 72 | 72 | except OSError, e: |
| 73 | 73 | if e.errno != errno.ENOTEMPTY: |
| 74 | 74 | raise |
| … |
… |
|
| 96 | 96 | """ |
| 97 | 97 | checksums_dir = layoutmanager.get_instance().get_checksums_dir() |
| 98 | 98 | checksum_path = os.path.join(checksums_dir, checksum) |
| 99 | | logging.debug('create dir %r' % checksum_path) |
| | 99 | logging.debug('create dir %r', checksum_path) |
| 100 | 100 | os.mkdir(checksum_path) |
| 101 | 101 | |
| 102 | 102 | def _add_checksum_entry(self, uid, checksum): |
| … |
… |
|
| 106 | 106 | checksums_dir = layoutmanager.get_instance().get_checksums_dir() |
| 107 | 107 | checksum_path = os.path.join(checksums_dir, checksum) |
| 108 | 108 | |
| 109 | | logging.debug('touch %r' % os.path.join(checksum_path, uid)) |
| | 109 | logging.debug('touch %r', os.path.join(checksum_path, uid)) |
| 110 | 110 | open(os.path.join(checksum_path, uid), 'w').close() |
| 111 | 111 | |
| 112 | 112 | def _already_linked(self, uid, checksum): |
| … |
… |
|
| 128 | 128 | queue = os.listdir(queue_path) |
| 129 | 129 | if queue: |
| 130 | 130 | uid = queue[0] |
| 131 | | logging.debug('_process_entry_cb processing %r' % uid) |
| | 131 | logging.debug('_process_entry_cb processing %r', uid) |
| 132 | 132 | |
| 133 | 133 | file_in_entry_path = self._file_store.get_file_path(uid) |
| 134 | 134 | if not os.path.exists(file_in_entry_path): |
| 135 | | logging.info('non-existent entry in queue: %r' % uid) |
| | 135 | logging.info('non-existent entry in queue: %r', uid) |
| 136 | 136 | else: |
| 137 | 137 | checksum = self._calculate_md5sum(file_in_entry_path) |
| 138 | 138 | self._metadata_store.set_property(uid, 'checksum', checksum) |
Download in other formats: