[Sugar-devel] [RFC PATCH 2/2] Implement migration for the two new properties (filesize and ctime). Increment CURRENT_LAYOUT_VERSION.
Andrés Ambrois
andresambrois at gmail.com
Sat May 1 14:52:46 EDT 2010
Signed-off-by: Andrés Ambrois <andresambrois at gmail.com>
---
src/carquinyol/layoutmanager.py | 2 +-
src/carquinyol/migration.py | 21 +++++++++++++++++----
2 files changed, 18 insertions(+), 5 deletions(-)
diff --git a/src/carquinyol/layoutmanager.py b/src/carquinyol/layoutmanager.py
index 8402b6d..aee5efb 100644
--- a/src/carquinyol/layoutmanager.py
+++ b/src/carquinyol/layoutmanager.py
@@ -18,7 +18,7 @@ import os
import logging
MAX_QUERY_LIMIT = 40960
-CURRENT_LAYOUT_VERSION = 4
+CURRENT_LAYOUT_VERSION = 5
class LayoutManager(object):
"""Provide the logic about how entries are stored inside the datastore
diff --git a/src/carquinyol/migration.py b/src/carquinyol/migration.py
index 95ee391..36c7d57 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)
@@ -69,9 +69,22 @@ def _migrate_metadata(root_path, old_root_path, uid):
if 'uid' not in metadata:
metadata['uid'] = uid
- if 'timestamp' not in metadata and 'mtime' in metadata:
- metadata['timestamp'] = \
- time.mktime(time.strptime(metadata['mtime'], DATE_FORMAT))
+ if 'timestamp' not in metadata:
+ if 'mtime' in metadata:
+ metadata['timestamp'] = \
+ time.mktime(time.strptime(metadata['mtime'], DATE_FORMAT))
+ else:
+ metadata['timestamp'] = int(os.stat(old_metadata_path).st_mtime)
+
+ if 'ctime' not in metadata:
+ metadata['ctime'] = int(os.stat(old_metadata_path).st_ctime)
+
+ 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:
--
1.6.3.3
More information about the Sugar-devel
mailing list