From fb90f7b45bb3292c5f42eb265ca44cbef73c5c44 Mon Sep 17 00:00:00 2001 From: Priit Laes Date: Fri, 2 Jul 2010 16:34:38 +0300 Subject: Handle updates to the package update file and update settings after sync --- utils/grumpy_sync.py | 86 +++++++++++++++++++++++++++++----------------------- 1 file changed, 48 insertions(+), 38 deletions(-) (limited to 'utils/grumpy_sync.py') diff --git a/utils/grumpy_sync.py b/utils/grumpy_sync.py index 6dfb7e7..3a4da26 100755 --- a/utils/grumpy_sync.py +++ b/utils/grumpy_sync.py @@ -17,7 +17,7 @@ sys.path.insert(0, path) del path from grumpy.database import session -from grumpy.models import (Base, Category, Developer, Ebuild, Herd, \ +from grumpy.models import (Category, Developer, Ebuild, Herd, \ Package, Setting) UPDATE_DB_KEY = 'updates_info' @@ -30,45 +30,41 @@ def main(path, initial_sync): repo = repository.UnconfiguredTree(path, cache=cache, \ eclass_cache=eclass_cache) - def parse_moves(): - movedir = os.path.join(path, 'profiles', 'updates') - if not os.path.isdir(movedir): - print "Missing package moves directory: '%s'" % movedir - return {} - - # Sort update files according to date - 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 + movedir = os.path.join(path, 'profiles', 'updates') + if not os.path.isdir(movedir): + print "Missing package moves directory: '%s'" % movedir + return {} + + # Sort update files according to date + get_key = lambda name: tuple(reversed(name.split('-'))) + + pkg_moves = {} + move_files = sorted(os.listdir(movedir), key=get_key) + update_file = move_files[-1] + update_path = os.path.join(movedir, update_file) + # Fetch existing setting data from database... + prev_updates = Setting.query.filter_by(name=UPDATE_DB_KEY).first() + if prev_updates: + # Check for filename and mtime + update_data = prev_updates.data + if update_data['file'] == update_file: + if update_data['mtime'] == int(os.stat(update_path).st_mtime): + # update_file has not been changed, so fall through + pkg_moves = None + else: + # Fetch new move rules + for line in iter_read_bash(update_path): + line = line.split() + if line[0] == 'move' and \ + line[1] not in update_data['moves'].keys(): + pkg_moves[line[1]] = line[2] + # Do it after sync has completed successfully... + #x['moves'] = copy(moves) + #x['mtime'] = mtime else: - print prev_updates.data + # New file has appeared.. + print "New file(s) in the list!" 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] - update_path = os.path.join(movedir, update_file) - for line in iter_read_bash(update_path): - line = line.split() - if line[0] == 'move': - moves[line[1]] = line[2] - if prev_updates: - # ...and delete if it exists - session.delete(prev_updates) - session.flush() - data = dict(file=update_file, moves=moves, \ - mtime=int(os.stat(update_path).st_mtime)) - session.add(Setting(UPDATE_DB_KEY, data)) - session.commit() - # Initial sync does not need to deal with moves - return - - pkg_moves = parse_moves() def extract_version(pkg, cpv): """...""" @@ -228,6 +224,20 @@ def main(path, initial_sync): files = [f for f in os.listdir(dir) if fnmatch(f, '*.ebuild')] package_update(cat, pkg, files, int(os.stat(dir).st_mtime)) + # Parse latest moves file and store its info in database + if prev_updates: + session.delete(prev_updates) + session.flush() + moves = {} + for line in iter_read_bash(update_path): + line = line.split() + if line[0] == 'move': + moves[line[1]] = line[2] + data = dict(file=update_file, moves=moves, \ + mtime=int(os.stat(update_path).st_mtime)) + session.add(Setting(UPDATE_DB_KEY, data)) + session.commit() + if __name__ == '__main__': parser = OptionParser(usage="usage: %prog [options] portagedir") parser.add_option("-i", "--initial-sync", action="store_true", \ -- cgit v1.2.3-65-gdbad