aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPriit Laes <plaes@plaes.org>2010-06-30 15:05:51 +0300
committerPriit Laes <plaes@plaes.org>2010-06-30 15:05:51 +0300
commit5e2d291fe5f42ce413b774b6c27162cb7907a77d (patch)
treef47816b781e982f2b5d64def3a51cd70b008694d
parentAdded TODO list (diff)
downloadgsoc2010-grumpy-5e2d291fe5f42ce413b774b6c27162cb7907a77d.tar.gz
gsoc2010-grumpy-5e2d291fe5f42ce413b774b6c27162cb7907a77d.tar.bz2
gsoc2010-grumpy-5e2d291fe5f42ce413b774b6c27162cb7907a77d.zip
Add support for package removal
-rw-r--r--TODO2
-rw-r--r--grumpy/models.py3
-rwxr-xr-xutils/grumpy_sync.py45
3 files changed, 37 insertions, 13 deletions
diff --git a/TODO b/TODO
index 220fcaa..66646cd 100644
--- a/TODO
+++ b/TODO
@@ -4,7 +4,7 @@ Todo list
Sync utility (manual checks):
* category add
* category delete
- * package delete
+ * package delete OK
* package move
* package update:
* dev add OK
diff --git a/grumpy/models.py b/grumpy/models.py
index 6619008..425a117 100644
--- a/grumpy/models.py
+++ b/grumpy/models.py
@@ -111,7 +111,8 @@ class Package(Base):
homepage = Column('homepage', String)
mtime = Column('mtime', DateTime)
- ebuilds = relationship(Ebuild)
+ ebuilds = relationship(Ebuild, backref='ebuilds', \
+ cascade='all, delete-orphan')
devs = relationship(Developer, secondary=package_developers, \
backref='packages')
herds = relationship(Herd, secondary=package_herds, backref='packages')
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))