diff options
author | 2010-08-03 15:56:58 +0300 | |
---|---|---|
committer | 2010-08-03 16:01:55 +0300 | |
commit | 74aed053adb980f5db78891c9c32004579cbc461 (patch) | |
tree | 3099885781733e6aa95332d3919874ecc13c1200 /grumpy | |
parent | Implement package removal (diff) | |
download | gsoc2010-grumpy-74aed053adb980f5db78891c9c32004579cbc461.tar.gz gsoc2010-grumpy-74aed053adb980f5db78891c9c32004579cbc461.tar.bz2 gsoc2010-grumpy-74aed053adb980f5db78891c9c32004579cbc461.zip |
Re-implement herds management for package
Diffstat (limited to 'grumpy')
-rw-r--r-- | grumpy/models.py | 27 | ||||
-rw-r--r-- | grumpy/testsuite/pkgmodel.py | 25 |
2 files changed, 46 insertions, 6 deletions
diff --git a/grumpy/models.py b/grumpy/models.py index 6fc2d49..1c582e4 100644 --- a/grumpy/models.py +++ b/grumpy/models.py @@ -134,6 +134,9 @@ class Herd(db.Model): def __init__(self, name): self.name = name + def __repr__(self): + return '<%s> - %s' % (self.__class__.__name__, self.name) + class Package(db.Model): """Represents packages in the system""" @@ -166,12 +169,32 @@ class Package(db.Model): self.mtime = datetime.fromtimestamp(mtime) # shared pkg data (from metadata.xml) self.ldesc = ebuild_src.longdescription - self.devs = [] # TODO - self.herds = [] # TODO + self.devs = [] + self.herds = self._parse_herds(ebuild_src) def __repr__(self): return '<%s> - %s' % (self.__class__.__name__, self.key) + def _parse_herds(self, ebuild_src): + """Update package herds.""" + herds = [] + for herd in ebuild_src.herds: + if not herd or herd.strip() is None: + herd = 'fix-me' + herds.append(herd.strip()) + herds = set(herds) + if not herds: + return [] + # Sync herds with database + out = [] + for herd in Herd.query.filter(Herd.name.in_(herds)).all(): + if herd.name in herds: + out.append(herd) + herds.remove(herd.name) + for herd in herds: + out.append(Herd(herd)) + return out + def sync(self, ebuild_src, mtime=time.time()): """Update package values from ebuild_src.""" self.__init__(ebuild_src, mtime) diff --git a/grumpy/testsuite/pkgmodel.py b/grumpy/testsuite/pkgmodel.py index 740d67a..9492423 100644 --- a/grumpy/testsuite/pkgmodel.py +++ b/grumpy/testsuite/pkgmodel.py @@ -10,7 +10,7 @@ """ from . import GrumpyTestCase -from grumpy.models import Category, Ebuild, Package +from grumpy.models import Category, Ebuild, Herd, Package import copy, time, unittest @@ -26,7 +26,8 @@ class PkgModelTestCase(GrumpyTestCase): 'HOMEPAGE': 'http://example.org/testpkg-app-misc', \ 'KEYWORDS':'x86 amd64', \ 'IUSE':'test +positive flags -negative split-flag'} - sdata = {'longdescription': 'this is longdescription'} + sdata = {'longdescription': 'this is longdescription', \ + 'herds': (None, '', 'kala', 'test')} p1 = self.get_pkg('%s/testpkg-1.0-r3' % C1, sdata, copy.copy(data)) data['KEYWORDS'] = 'x86 ~amd64' p2 = self.get_pkg('%s/testpkg-1.0-r4' % C1, sdata, copy.copy(data)) @@ -49,7 +50,7 @@ class PkgModelTestCase(GrumpyTestCase): ## Create and test packages c[0].packages[p1.key] = Package(p1) - c[0].packages[p2.key] = Package(p2) + self.db.session.commit() c[1].packages[p3.key] = Package(p3) self.db.session.commit() assert Package.query.count() == 2 @@ -62,7 +63,8 @@ class PkgModelTestCase(GrumpyTestCase): assert p.homepage == 'http://example.org/testpkg-app-misc' assert p.category.name == C1 assert len(p.category.packages) == 1 - # TODO: herds, maintainers + assert len(p.herds) == 3 + # TODO: maintainers p = Package.query.filter_by(key='%s/testpkg' % C2).first() assert p.pkg == 'testpkg' @@ -71,6 +73,18 @@ class PkgModelTestCase(GrumpyTestCase): assert p.homepage == 'http://example.org/testpkg-app-test' assert p.category.name == C2 assert len(p.category.packages) == 1 + assert len(p.herds) == 3 + + # Test changes in herds + sdata['herds'] = () + px = self.get_pkg('%s/testpkg-1.0-r3' % C1, sdata, copy.copy(data)) + c[0].packages[px.key].sync(px) + + self.db.session.commit() + p = Package.query.filter_by(key='%s/testpkg' % C1).first() + assert p.pkg == 'testpkg' + assert p.category.name == C1 + assert len(p.herds) == 0 # Test Category -> package lookup for p in (p1, p2, p3): @@ -133,6 +147,9 @@ class PkgModelTestCase(GrumpyTestCase): assert Package.query.count() == 0 assert Ebuild.query.count() == 0 + # Herds should be still in db + assert Herd.query.count() == 3 + def suite(): suite = unittest.TestSuite() suite.addTest(unittest.makeSuite(PkgModelTestCase)) |