diff options
author | Priit Laes <plaes@plaes.org> | 2010-07-31 13:49:51 +0300 |
---|---|---|
committer | Priit Laes <plaes@plaes.org> | 2010-07-31 13:49:51 +0300 |
commit | 74a34f41ba2567d54a75351d7abb8b27359017a7 (patch) | |
tree | c217bc0bb9fdc5bb30571bea0074419fe4656600 /grumpy | |
parent | Test for user owning the Favorite (diff) | |
download | gsoc2010-grumpy-74a34f41ba2567d54a75351d7abb8b27359017a7.tar.gz gsoc2010-grumpy-74a34f41ba2567d54a75351d7abb8b27359017a7.tar.bz2 gsoc2010-grumpy-74a34f41ba2567d54a75351d7abb8b27359017a7.zip |
Init Ebuild directly using pkgcore's ebuild_src
Diffstat (limited to 'grumpy')
-rw-r--r-- | grumpy/models.py | 60 | ||||
-rw-r--r-- | grumpy/testsuite/__init__.py | 7 | ||||
-rw-r--r-- | grumpy/testsuite/favorites.py | 6 | ||||
-rw-r--r-- | grumpy/testsuite/pkgmodel.py | 19 |
4 files changed, 68 insertions, 24 deletions
diff --git a/grumpy/models.py b/grumpy/models.py index f88f1f8..679a1b5 100644 --- a/grumpy/models.py +++ b/grumpy/models.py @@ -57,34 +57,56 @@ class Ebuild(db.Model): __tablename__ = 'ebuilds' id = db.Column('id', db.Integer, primary_key=True) - cpv = db.Column('cpv', db.String, nullable=False, unique=True) + pcv = db.Column('pcv', db.String, nullable=False, unique=True) eapi = db.Column('eapi', db.Integer, nullable=False) # Regular USE flags iuse = db.Column('iuse', db.String) - # Forced USE flags (+use) - fiuse = db.Column('fiuse', db.String) + # Forced USE flags ('-use' and '+use') + iuse_neg = db.Column('iuse_neg', db.String) + iuse_pos = db.Column('iuse_pos', db.String) keywords = db.Column('keywords', db.String) slot = db.Column('slot', db.String) + revision = db.Column('revision', db.Integer) version = db.Column('version', db.String, nullable=False) - _package = db.Column('package_id', db.Integer, db.ForeignKey('packages.id')) + package_id = db.Column('package_id', db.Integer, db.ForeignKey('packages.id')) # TODO: depend, rdepend, licenses # TODO: extra info? - package = db.relationship("Package") - - def __init__(self, package, version, eapi, slot, keywords, \ - iuse, fiuse): - self.package = package - self.version = version - self.cpv = "%s/%s-%s" % (package.pkg, package.cat, self.version) - self.eapi = eapi - self.slot = slot - self.iuse = ','.join(iuse) - self.fiuse = ','.join(fiuse) - self.keywords = ','.join(keywords) + def __init__(self, ebuild): + """Initialize ebuild using pkgcore's ebuild class as an argument.""" + self.version = ebuild.version + self.revision = ebuild.revision + self.slot = ebuild.slot + self.eapi = ebuild.eapi + self.keywords = self._parse_keywords(ebuild) + self.iuse = self._parse_iuse(ebuild) + self.iuse_pos = self._parse_iuse_pos(ebuild) + self.iuse_neg = self._parse_iuse_neg(ebuild) + self.pcv = self._parse_pcv(ebuild) + + def _parse_iuse(self, ebuild_src): + """Returns list of USE flags from ebuild_src.""" + return ','.join([f for f in ebuild_src.iuse if f[0] not in ('+','-')]) + + def _parse_iuse_neg(self, ebuild_src): + """Returns list of forced USE flags (+use) from ebuild_src.""" + return ','.join([kw[1:] for kw in ebuild_src.iuse if kw[0] == '-']) + + def _parse_iuse_pos(self, ebuild_src): + """Returns list of forced USE flags (+use) from ebuild_src.""" + return ','.join([kw[1:] for kw in ebuild_src.iuse if kw[0] == '+']) + + def _parse_keywords(self, ebuild_src): + """Returns list of keywords from pkgcore's Ebuild.""" + return ','.join(ebuild_src.keywords) + + def _parse_pcv(self, ebuild_src): + """Returns ebuild's unique 'atom' - 'package/category-fullversion'.""" + p = ebuild_src + return "%s/%s-%s" % (p.package, p.category, p.fullver) def __repr__(self): - return '<%s> - %s' % (self.__class__.__name__, self.cpv) + return '<%s> - %s' % (self.__class__.__name__, self.pcv) class Favorite(db.Model): """Represents packages that user can add in their watch list.""" @@ -133,8 +155,8 @@ class Package(db.Model): homepage = db.Column('homepage', db.String) mtime = db.Column('mtime', db.DateTime) - ebuilds = db.relationship(Ebuild, backref='ebuilds', \ - cascade='all, delete-orphan') + 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, \ diff --git a/grumpy/testsuite/__init__.py b/grumpy/testsuite/__init__.py index 92290d0..4884a04 100644 --- a/grumpy/testsuite/__init__.py +++ b/grumpy/testsuite/__init__.py @@ -12,9 +12,16 @@ import unittest from grumpy import app from grumpy.models import db +from pkgcore.ebuild import ebuild_src class GrumpyTestCase(unittest.TestCase): + def get_pkg(self, cpv, data={}): + o = ebuild_src.base(*([] + [None, cpv])) + if data is not None: + object.__setattr__(o, 'data', data) + return o + def setUp(self): app.config['SQLALCHEMY_ENGINE'] = 'sqlite://' app.config['TESTING'] = True diff --git a/grumpy/testsuite/favorites.py b/grumpy/testsuite/favorites.py index 94e9d9f..9c701aa 100644 --- a/grumpy/testsuite/favorites.py +++ b/grumpy/testsuite/favorites.py @@ -29,12 +29,12 @@ class FavoritesTestCase(GrumpyTestCase): p.append(Package('sys-misc', 'testpkg', 'Test Package', \ 'Long Description', 'http://example.com/test', \ time.time())) - p[0].ebuilds.append(Ebuild(p[0], '1.0', 2, 0, 'x86,amd64', 'doc', '')) - p[0].ebuilds.append(Ebuild(p[0], '1.1', 2, 0, '~x86,~amd64', 'doc', '')) + p[0].ebuilds.append(Ebuild(self.get_pkg('sys-misc/testpkg-1.0'))) + p[0].ebuilds.append(Ebuild(self.get_pkg('sys-misc/testpkg-1.1'))) p.append(Package('sys-devel', 'testpkg', 'Test Package 2', \ 'Long Description 2', 'http://example.com/test2', \ time.time())) - p[1].ebuilds.append(Ebuild(p[1], '0.1', 2, 0, 'x86,amd64', 'doc', '')) + p[1].ebuilds.append(Ebuild(self.get_pkg('sys-devel/testpkg-0.1'))) self.db.session.add_all(p) self.db.session.commit() return p diff --git a/grumpy/testsuite/pkgmodel.py b/grumpy/testsuite/pkgmodel.py index 49ae354..c59ecd4 100644 --- a/grumpy/testsuite/pkgmodel.py +++ b/grumpy/testsuite/pkgmodel.py @@ -29,11 +29,26 @@ class PkgModelTestCase(GrumpyTestCase): 'Long Description', 'http://example.com/test', \ time.time()) # ...and two ebuilds - p.ebuilds.append(Ebuild(p, '1.0-r3', 2, 0, 'x86,~amd64', 'doc', '')) - p.ebuilds.append(Ebuild(p, '1.0-r4', 2, 0, '~x86,~amd64', 'doc', '')) + data = {'EAPI': '0', 'SLOT': '1.1', \ + 'KEYWORDS':'x86 amd64', \ + 'IUSE':'test +positive flags -negative split-flag'} + p.ebuilds.append(Ebuild(self.get_pkg('app-misc/testpkg-1.0-r3', data))) + p.ebuilds.append(Ebuild(self.get_pkg('app-misc/testpkg-1.0-r4', data))) self.db.session.add(p) self.db.session.commit() + def test_ebuild_parsing(self): + with self.app.test_request_context(): + self.make_package_and_ebuilds() + e = Ebuild.query.first() + assert e.iuse == 'test,flags,split-flag' + assert e.iuse_neg == 'negative' + assert e.iuse_pos == 'positive' + assert e.keywords == 'x86,amd64' + assert e.eapi == 0 + assert e.slot == '1.1' + assert e.pcv == 'testpkg/app-misc-1.0-r3' + def test_category_and_package_model(self): with self.app.test_request_context(): self.make_categories() |