diff options
author | Priit Laes <plaes@plaes.org> | 2010-08-02 00:53:10 +0300 |
---|---|---|
committer | Priit Laes <plaes@plaes.org> | 2010-08-02 00:57:48 +0300 |
commit | 964ad9491d4c517a44486d3b3ab7aeb558d3c886 (patch) | |
tree | 5332c3fb18f664c39c94fc50be77700bb6bb431b | |
parent | Simplify Category -> Package mapping (diff) | |
download | gsoc2010-grumpy-964ad9491d4c517a44486d3b3ab7aeb558d3c886.tar.gz gsoc2010-grumpy-964ad9491d4c517a44486d3b3ab7aeb558d3c886.tar.bz2 gsoc2010-grumpy-964ad9491d4c517a44486d3b3ab7aeb558d3c886.zip |
Use ebuild_src.key instead of custom 'package/category' implementation
-rw-r--r-- | grumpy/models.py | 16 | ||||
-rw-r--r-- | grumpy/testsuite/pkgmodel.py | 28 |
2 files changed, 29 insertions, 15 deletions
diff --git a/grumpy/models.py b/grumpy/models.py index cf33adb..6f57957 100644 --- a/grumpy/models.py +++ b/grumpy/models.py @@ -38,13 +38,13 @@ class Category(db.Model): packages = db.relationship("Package", backref='category', \ cascade='all, delete, delete-orphan', \ - collection_class=column_mapped_collection(db.text('packages.pkg'))) + collection_class=column_mapped_collection(db.text('packages.key'))) def __init__(self, name): self.name = name def __repr__(self): - return '<%s> "%s"' % (self.__class__.__name__, self.category) + return '<%s> "%s"' % (self.__class__.__name__, self.name) class Developer(db.Model): """Represents developers in the system""" @@ -162,26 +162,28 @@ class Package(db.Model): __tablename__ = 'packages' id = db.Column('id', db.Integer, primary_key=True) + key = db.Column('key', db.String, nullable=False, unique=True) pkg = db.Column('pkg', db.String, nullable=False) - pkg_cat = db.Column('pkg_cat', db.String, nullable=False, unique=True) desc = db.Column('desc', db.String) ldesc = db.Column('ldesc', db.String) homepage = db.Column('homepage', db.String) mtime = db.Column('mtime', db.DateTime) cat_id = db.Column('cat_id', db.Integer, db.ForeignKey('categories.id')) - ebuilds = db.relationship(Ebuild, backref='package', \ - cascade='all, delete, delete-orphan') qaissues = db.relationship("PkgIssue", backref='qa_issues', \ cascade='all, delete-orphan') devs = db.relationship(Developer, secondary=package_developers, \ backref='packages') herds = db.relationship(Herd, secondary=package_herds, backref='packages') + ebuilds = db.relationship(Ebuild, backref='package', \ + cascade='all, delete, delete-orphan', \ + collection_class=column_mapped_collection(Ebuild.pcv)) + def __init__(self, ebuild_src, mtime=time.time()): + self.key = ebuild_src.key self.pkg = ebuild_src.package self.desc = ebuild_src.description - self.pkg_cat = "%s/%s" % (self.pkg, ebuild_src.category) self.homepage = ebuild_src.homepage self.mtime = datetime.fromtimestamp(mtime) # shared pkg data (from metadata.xml) @@ -190,7 +192,7 @@ class Package(db.Model): self.herds = [] # TODO def __repr__(self): - return '<%s> - %s' % (self.__class__.__name__, self.pkg_cat) + return '<%s> - %s' % (self.__class__.__name__, self.key) # def rename(self, newcat, newpkg): # """Rename package and its ebuilds""" diff --git a/grumpy/testsuite/pkgmodel.py b/grumpy/testsuite/pkgmodel.py index a24b146..8c4e33c 100644 --- a/grumpy/testsuite/pkgmodel.py +++ b/grumpy/testsuite/pkgmodel.py @@ -34,11 +34,11 @@ class PkgModelTestCase(GrumpyTestCase): # app-test/testpkg C2 = 'app-test' data = {'EAPI': '0', 'SLOT': '1.0', \ - 'DESCRIPTION': 'This is a also a simple description', \ + 'DESCRIPTION': 'short description', \ 'HOMEPAGE': 'http://example.org/testpkg-app-test', \ 'KEYWORDS':'x86 ~amd64', \ 'IUSE':'test +positive flags -negative split-flag'} - p3 = self.get_pkg('%s/testpkg-1.0-r3' % C2, sdata, data) + p3 = self.get_pkg('%s/testpkg-1.0-r3' % C2, sdata, copy.copy(data)) with self.app.test_request_context(): ## Create and test categories @@ -48,23 +48,35 @@ class PkgModelTestCase(GrumpyTestCase): assert Category.query.count() == 2 ## Create and test packages - c[0].packages[p1.package] = Package(p1) - c[0].packages[p2.package] = Package(p2) - c[1].packages[p3.package] = Package(p3) + c[0].packages[p1.key] = Package(p1) + c[0].packages[p2.key] = Package(p2) + c[1].packages[p3.key] = Package(p3) self.db.session.commit() assert Package.query.count() == 2 # TODO: assert p.category vs package.category.name - p = Package.query.filter_by(pkg_cat='testpkg/%s' % C1).first() + p = Package.query.filter_by(key='%s/testpkg' % C1).first() assert p.pkg == 'testpkg' assert p.desc == 'this is description' assert p.ldesc == 'this is longdescription' assert p.homepage == 'http://example.org/testpkg-app-misc' assert p.category.name == C1 + assert len(p.category.packages) == 1 # TODO: herds, maintainers - # Create and test ebuilds - # TODO: ... + p = Package.query.filter_by(key='%s/testpkg' % C2).first() + assert p.pkg == 'testpkg' + assert p.desc == 'short description' + assert p.ldesc == 'this is longdescription' + assert p.homepage == 'http://example.org/testpkg-app-test' + assert p.category.name == C2 + assert len(p.category.packages) == 1 + + # Test Category -> package lookup + for p in (p1, p2, p3): + c = Category.query.filter_by(name=p.category).first() + assert c != None + assert c.packages[p.key].key == p.key def make_packages_and_ebuild(self, categories): # Create package... |