aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPriit Laes <plaes@plaes.org>2010-07-01 23:45:52 +0300
committerPriit Laes <plaes@plaes.org>2010-07-01 23:50:39 +0300
commitcca918d15b3e4b72723fe2e5b0a425c89479aac3 (patch)
tree8b5660a670c5b75e809c4168b9cd74f7e42c0b8c
parentPort to OptionParser (diff)
downloadgsoc2010-grumpy-cca918d15b3e4b72723fe2e5b0a425c89479aac3.tar.gz
gsoc2010-grumpy-cca918d15b3e4b72723fe2e5b0a425c89479aac3.tar.bz2
gsoc2010-grumpy-cca918d15b3e4b72723fe2e5b0a425c89479aac3.zip
Made --initial-sync option working
-rwxr-xr-xutils/grumpy_sync.py54
1 files changed, 37 insertions, 17 deletions
diff --git a/utils/grumpy_sync.py b/utils/grumpy_sync.py
index 3de226f..b632580 100755
--- a/utils/grumpy_sync.py
+++ b/utils/grumpy_sync.py
@@ -20,7 +20,7 @@ from grumpy.database import session
from grumpy.models import (Base, Category, Developer, Ebuild, Herd, \
Package, Setting)
-def main(path):
+def main(path, initial_sync):
# pkgcore part to fetch all the ebuild information
conf = load_config()
eclass_cache = conf.eclass_cache['eclass stack']
@@ -28,6 +28,40 @@ def main(path):
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 = {}
+ 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]
+ # Fetch existing setting data from database...
+ updates = Setting.query.filter_by(name='updates_info').first()
+ if updates:
+ # ...and delete if it exists
+ session.delete(updates)
+ session.flush()
+ data = dict(moves=moves, mtime=int(os.stat(update_path).st_mtime))
+ session.add(Setting('updates_info', data))
+ session.commit()
+ # Initial sync does not need to deal with moves
+ return {}
+ # Not an initial sync...
+ raise NotImplementedError
+
+ pkg_moves = parse_moves()
+
def extract_version(pkg, cpv):
"""..."""
return cpv[len(pkg)+1:-7]
@@ -152,20 +186,6 @@ def main(path):
session.commit()
- # Handle package moves
- dir = os.path.join(path, 'profiles', 'updates')
- moves = {}
- if os.path.isdir(dir):
- def get_key(fname):
- return tuple(reversed(fname.split('-')))
-
- for update_file in sorted(os.listdir(dir), key=get_key):
- for line in iter_read_bash(os.path.join(dir, update_file)):
- line = line.split()
- if line[0] != 'move':
- continue
- moves[line[1]] = line[2]
-
# Compare list of categories in portage vs database
cat_sql = [c.cat for c in Category.query.all()]
cats = repo.categories.keys()
@@ -187,7 +207,7 @@ def main(path):
for pkg in [i for i in old if i not in new]:
# Handle package move or deletion
- if "%s/%s" % (cat, pkg) in moves.keys():
+ if pkg_moves and "%s/%s" % (cat, pkg) in pkg_moves.keys():
print "DEBUG: package has been moved:", pkg
raise NotImplementedError
else:
@@ -208,4 +228,4 @@ if __name__ == '__main__':
if len(args) != 1:
parser.error("please provide path to portagedir as first argument")
sys.exit(1)
- main(args[0])
+ main(args[0], opts.initial)