aboutsummaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
authorPriit Laes <plaes@plaes.org>2010-07-02 08:58:54 +0300
committerPriit Laes <plaes@plaes.org>2010-07-02 09:05:39 +0300
commitbee7dba54dafe2aa3dae7cf95b2b907f8d037662 (patch)
treeeb9d22f55ecd4c6a6b55241348b138328c79172a /utils
parentReturn None instead of empty dictionary in initial sync case (diff)
downloadgsoc2010-grumpy-bee7dba54dafe2aa3dae7cf95b2b907f8d037662.tar.gz
gsoc2010-grumpy-bee7dba54dafe2aa3dae7cf95b2b907f8d037662.tar.bz2
gsoc2010-grumpy-bee7dba54dafe2aa3dae7cf95b2b907f8d037662.zip
Fall back to initial sync case when no previous updates found
Diffstat (limited to 'utils')
-rwxr-xr-xutils/grumpy_sync.py21
1 files changed, 14 insertions, 7 deletions
diff --git a/utils/grumpy_sync.py b/utils/grumpy_sync.py
index 160bbb9..6dfb7e7 100755
--- a/utils/grumpy_sync.py
+++ b/utils/grumpy_sync.py
@@ -20,6 +20,8 @@ from grumpy.database import session
from grumpy.models import (Base, Category, Developer, Ebuild, Herd, \
Package, Setting)
+UPDATE_DB_KEY = 'updates_info'
+
def main(path, initial_sync):
# pkgcore part to fetch all the ebuild information
conf = load_config()
@@ -38,6 +40,15 @@ def main(path, initial_sync):
get_key = lambda name: tuple(reversed(name.split('-')))
moves = {}
+ # Fetch existing setting data from database...
+ prev_updates = Setting.query.filter_by(name=UPDATE_DB_KEY).first()
+ # Not an initial sync...
+ if not prev_updates:
+ # No previous updates found, fall back to initial sync case
+ initial_sync = True
+ else:
+ print prev_updates.data
+ raise NotImplementedError
if initial_sync:
# We take the latest move file, and store its contents in db
update_file = sorted(os.listdir(movedir), key=get_key)[-1]
@@ -46,20 +57,16 @@ def main(path, initial_sync):
line = line.split()
if line[0] == 'move':
moves[line[1]] = line[2]
- # Fetch existing setting data from database...
- updates = Setting.query.filter_by(name='updates_info').first()
- if updates:
+ if prev_updates:
# ...and delete if it exists
- session.delete(updates)
+ session.delete(prev_updates)
session.flush()
data = dict(file=update_file, moves=moves, \
mtime=int(os.stat(update_path).st_mtime))
- session.add(Setting('updates_info', data))
+ session.add(Setting(UPDATE_DB_KEY, data))
session.commit()
# Initial sync does not need to deal with moves
return
- # Not an initial sync...
- raise NotImplementedError
pkg_moves = parse_moves()