diff options
author | 2010-08-10 23:02:19 +0300 | |
---|---|---|
committer | 2010-08-10 23:05:34 +0300 | |
commit | cc7f6ae5d6c79e410d77c65e38a025059f2762dd (patch) | |
tree | b0403fc0ccde791f886a87622d30ff86ed06dced | |
parent | Move package creation functionality to base class (diff) | |
download | gsoc2010-grumpy-cc7f6ae5d6c79e410d77c65e38a025059f2762dd.tar.gz gsoc2010-grumpy-cc7f6ae5d6c79e410d77c65e38a025059f2762dd.tar.bz2 gsoc2010-grumpy-cc7f6ae5d6c79e410d77c65e38a025059f2762dd.zip |
Implement package rename
-rw-r--r-- | grumpy/models.py | 26 | ||||
-rw-r--r-- | grumpy/testsuite/__init__.py | 6 | ||||
-rw-r--r-- | grumpy/testsuite/pkgmodel.py | 23 |
3 files changed, 44 insertions, 11 deletions
diff --git a/grumpy/models.py b/grumpy/models.py index 49b58ee..31127a0 100644 --- a/grumpy/models.py +++ b/grumpy/models.py @@ -85,6 +85,11 @@ class Ebuild(db.Model): """Update ebuild values from ebuild_src.""" self.__init__(ebuild_src) + def rename(self, key): + self.cpv = "%s-%s" % (self.package.key, self.version) + if self.revision > 0: + self.cpv = "%s-r%d" % (self.cpv, self.revision) + 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 ('+','-')]) @@ -213,19 +218,22 @@ class Package(db.Model): out.append(Herd(herd)) return out + def rename(self, key): + """Rename a package and all its ebuilds""" + # Look up or create new category + cat = key.split('/')[0] + c = Category.query.filter_by(name=cat).first() + if not c: + c = Category(cat) + self.key = key + self.category = c + for ebuild in self.ebuilds.values(): + ebuild.rename(key) + def sync(self, ebuild_src, mtime=time.time()): """Update package values from ebuild_src.""" self.__init__(ebuild_src, mtime) -# def rename(self, newcat, newpkg): -# """Rename package and its ebuilds""" -# cp = "%s/%s" % (newpkg, newcat) -# self.cat = newcat -# self.pkg = newpkg -# self.cp = cp -# for ebuild in self.ebuilds: -# ebuild.cpv = "%s-%s" % (cp, ebuild.version) - class Category(db.Model): """Represents portage categories""" diff --git a/grumpy/testsuite/__init__.py b/grumpy/testsuite/__init__.py index 67242c6..162b03d 100644 --- a/grumpy/testsuite/__init__.py +++ b/grumpy/testsuite/__init__.py @@ -13,7 +13,7 @@ import copy, unittest from pkgcore.ebuild import ebuild_src, repo_objs from grumpy import app -from grumpy.models import db, Category, Package +from grumpy.models import db, Category, Ebuild, Package class GrumpyTestCase(unittest.TestCase): @@ -24,7 +24,9 @@ class GrumpyTestCase(unittest.TestCase): if not c: c = Category(cat) self.db.session.add(c) - c.packages[package.key] = Package(package) + p = Package(package) + c.packages[package.key] = p + p.ebuilds[package.cpvstr] = Ebuild(package) self.db.session.commit() def get_pkg(self, cpv, pkg_data={}, data={}): diff --git a/grumpy/testsuite/pkgmodel.py b/grumpy/testsuite/pkgmodel.py index bd9f26b..4154141 100644 --- a/grumpy/testsuite/pkgmodel.py +++ b/grumpy/testsuite/pkgmodel.py @@ -156,6 +156,29 @@ class PkgModelTestCase(GrumpyTestCase): assert Herd.query.count() == 3 assert Developer.query.count() == 2 + def test_package_rename(self): + data = {} + info = {'maintainers' : (), 'herds': ()} + with self.app.test_request_context(): + self.make_package(self.get_pkg('sys-apps/action-1.0-r2', {}, {})) + assert Category.query.count() == 1 + assert Package.query.count() == 1 + assert Ebuild.query.count() == 1 + + p = Package.query.filter_by(key='sys-apps/action').first() + assert p != None + p.rename('sys-fail/kala') + self.db.session.commit() + assert Category.query.count() == 2 + assert Package.query.count() == 1 + assert Ebuild.query.count() == 1 + p = Package.query.filter_by(key='sys-apps/action').first() + assert p == None + p = Package.query.filter_by(key='sys-fail/kala').first() + assert p != None + e = Ebuild.query.first() + assert e.cpv == 'sys-fail/kala-1.0-r2' + def suite(): suite = unittest.TestSuite() suite.addTest(unittest.makeSuite(PkgModelTestCase)) |