aboutsummaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
Diffstat (limited to 'utils')
-rwxr-xr-xutils/grumpy_sync.py45
1 files changed, 34 insertions, 11 deletions
diff --git a/utils/grumpy_sync.py b/utils/grumpy_sync.py
index aa54ace..ed506a1 100755
--- a/utils/grumpy_sync.py
+++ b/utils/grumpy_sync.py
@@ -12,8 +12,11 @@ from sqlalchemy import create_engine
from sqlalchemy.orm import scoped_session, sessionmaker
from sqlalchemy.orm.exc import NoResultFound
+from snakeoil.fileutils import iter_read_bash
+
path = os.path.join(os.path.dirname(__file__), os.path.pardir)
sys.path.insert(0, path)
+del path
from grumpy.models import Base, Category, Developer, Ebuild, Herd, Package
@@ -48,11 +51,6 @@ def main(path):
print "DEBUG: updating package %s/%s" % (cat, pkg)
- # No ebuilds for package?
- if len(files) == 0:
- # TODO, need to check whether there's been pkgmove
- raise NotImplementedError
-
pack = repo[(cat, pkg, extract_version(pkg, files[0]))]
# Update or create new package
@@ -160,6 +158,20 @@ 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()
@@ -173,13 +185,24 @@ def main(path):
# Traverse portage
for cat in cats:
catdir = os.path.join(path, cat)
- pkgs = os.listdir(catdir)
- # TODO
- # handle package moves (when one isn't in tree and when one is..)
- for pkg in pkgs:
+
+ # Get list of existing packages in this category
+ old = [p.pkg for p in Package.query.filter_by(cat=cat).all()]
+ new = [d for d in os.listdir(catdir) \
+ if os.path.isdir(os.path.join(catdir, d))]
+
+ 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():
+ print "DEBUG: package has been moved:", pkg
+ raise NotImplementedError
+ else:
+ print "DEBUG: package has been (re)moved:", pkg
+ package = Package.query.filter_by(cat=cat).filter_by(pkg=pkg).one()
+ session.delete(package)
+ session.commit()
+ for pkg in new:
dir = os.path.join(catdir, pkg)
- if not os.path.isdir(dir):
- continue
files = [f for f in os.listdir(dir) if fnmatch(f, '*.ebuild')]
package_update(cat, pkg, files, int(os.stat(dir).st_mtime))