From 82858a507553015b2fb1e8fa7adbb72882b3afb9 Mon Sep 17 00:00:00 2001 Message-Id: <82858a507553015b2fb1e8fa7adbb72882b3afb9.1278225682.git.andresambrois@gmail.com> In-Reply-To: References: From: =?UTF-8?q?Andr=C3=A9s=20Ambrois?= Date: Fri, 2 Jul 2010 03:35:47 -0300 Subject: [PATCH v2 2/7] Add migration code from DS v0 for the filesize property MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Andrés Ambrois --- src/carquinyol/migration.py | 9 ++++++++- 1 files changed, 8 insertions(+), 1 deletions(-) diff --git a/src/carquinyol/migration.py b/src/carquinyol/migration.py index 95ee391..228467c 100644 --- a/src/carquinyol/migration.py +++ b/src/carquinyol/migration.py @@ -45,8 +45,8 @@ def migrate_from_0(): logging.debug('Migrating entry %r', uid) try: - _migrate_metadata(root_path, old_root_path, uid) _migrate_file(root_path, old_root_path, uid) + _migrate_metadata(root_path, old_root_path, uid) _migrate_preview(root_path, old_root_path, uid) except Exception: logging.exception('Error while migrating entry %r', uid) @@ -73,6 +73,13 @@ def _migrate_metadata(root_path, old_root_path, uid): metadata['timestamp'] = \ time.mktime(time.strptime(metadata['mtime'], DATE_FORMAT)) + file_path = layoutmanager.get_instance().get_data_path(uid) + if 'filesize' not in metadata: + if os.path.exists(file_path): + metadata['filesize'] = int(os.stat(file_path).st_size) + else: + metadata['filesize'] = 0 + for key, value in metadata.items(): try: f = open(os.path.join(metadata_path, key), 'w') -- 1.7.0.4