From 03a1c9956224c948efe8e89e8cfb8043eafe88b1 Mon Sep 17 00:00:00 2001 From: Pat Riehecky Date: Apr 14 2017 21:16:01 +0000 Subject: Ever forward on django --- diff --git a/python-Updateinfo.spec b/python-Updateinfo.spec index be3efbe..d18adf2 100644 --- a/python-Updateinfo.spec +++ b/python-Updateinfo.spec @@ -3,6 +3,7 @@ Summary: Classes for making the yum updateinfo.xml. Name: %{?scl_prefix}python-Updateinfo +Provides: %{?scl_prefix}python2-Updateinfo Version: 0.2.0 Release: 9.sl%{rhel} Source0: %{pkg_name}.tar.gz @@ -12,6 +13,7 @@ BuildRoot: %{_tmppath}/%{pkg_name}-%{version}-%{release}-buildroot Prefix: %{_prefix} BuildArch: noarch Url: http://www.scientificlinux.org/ + Requires: %{?scl_prefix}python %{?scl_prefix}python-hashlib %{?scl_prefix}python-argparse Requires: %{?scl_prefix}PyYAML %{?scl_prefix}python-lxml @@ -21,7 +23,8 @@ Requires: %{?scl_prefix}python-futures # creatrepo provides modifyrepo which is what we really need Requires: createrepo -BuildRequires: %{?scl_prefix}python >= 2.4 %{?scl_prefix}python-setuptools +BuildRequires: %{?scl_prefix}python %{?scl_prefix}python-setuptools + # All these are for the testing.... BuildRequires: %{?scl_prefix}python-hashlib %{?scl_prefix}python-argparse BuildRequires: %{?scl_prefix}python-futures @@ -48,7 +51,7 @@ Summary: A portable application for Django Group: Development/Libraries BuildArch: noarch Requires: %{?scl_prefix}python-Updateinfo -Requires: %{?scl_prefix}python-django >= 1.7 +Requires: %{?scl_prefix}python-django >= 1.8 %description -n %{?scl_prefix}python-Updateinfo-django A portable Django application for managing updateinfo objects. @@ -60,12 +63,12 @@ It should be highly compatible with the non-Django version. %build %{?scl:scl enable %{scl} "} -python setup.py build +%py_build %{?scl:"} %install %{?scl:scl enable %{scl} "} -python setup.py install -O1 --root=$RPM_BUILD_ROOT --record=INSTALLED_FILES +%py_install %{?scl:"} mkdir -p $RPM_BUILD_ROOT/usr/share/doc/python-Updateinfo/ cp -pr docs/* $RPM_BUILD_ROOT/usr/share/doc/python-Updateinfo/ @@ -74,7 +77,7 @@ cp -pr docs/* $RPM_BUILD_ROOT/usr/share/doc/python-Updateinfo/ %{?scl:scl enable %{scl} "} PYTHONPATH=. export PYTHONPATH -python updateinfo/tests/ +%{__python} updateinfo/tests/ %{?scl:"} diff --git a/updateinfo/updateinfo_for_django/models/collection.py b/updateinfo/updateinfo_for_django/models/collection.py index bb44571..80071b8 100644 --- a/updateinfo/updateinfo_for_django/models/collection.py +++ b/updateinfo/updateinfo_for_django/models/collection.py @@ -4,7 +4,7 @@ ''' from __future__ import unicode_literals from __future__ import absolute_import -from django.db import models +from django.db import models, transaction from django.utils.encoding import python_2_unicode_compatible from django.core.exceptions import ObjectDoesNotExist @@ -76,7 +76,10 @@ class Collection(UpdateinfoCollection, models.Model): def save(self, *args, **kwargs): '''Make sure to update attached packages on a save''' - models.Model.save(self, *args, **kwargs) # Call the "real" save() method on this model. + super(Collection, self).save(self, *args, **kwargs) # Call the "real" save() method on this model. + + ### XXX FIXME + ### Can I do this with signals? So it is cleaner?, django.db.models.signals.m2m_changed for filename in self: try: # If a package was added to a collection and saved between @@ -109,6 +112,8 @@ class Collection(UpdateinfoCollection, models.Model): ''' For simply adding a package ''' + ### XXX FIXME + ### Should I use '.add' here? need to figure out how that works if not isinstance(value, self.Package): raise TypeError('I can only add ' + str(type(self.Package)) + ' type objects, not ' + str(type(value))) diff --git a/updateinfo/updateinfo_for_django/models/package.py b/updateinfo/updateinfo_for_django/models/package.py index ae7ad28..b9db7fe 100644 --- a/updateinfo/updateinfo_for_django/models/package.py +++ b/updateinfo/updateinfo_for_django/models/package.py @@ -4,7 +4,7 @@ ''' from __future__ import unicode_literals from __future__ import absolute_import -from django.db import models +from django.db import models, transaction from django.utils.encoding import python_2_unicode_compatible from django.core.exceptions import ObjectDoesNotExist @@ -93,9 +93,15 @@ class Package(UpdateinfoPackage, models.Model): '''Make sure to populate the derrived filename''' # calculate the filename and store the result self.filename = self.filename # this is not a mistaken line - models.Model.save(self, *args, **kwargs) # Call the "real" save() method. - self.sums._package = self - self.sums.save(*args, **kwargs) + + with transaction.atomic(): + super(Package, self).save(self, *args, **kwargs) # Call the "real" save() method on this model. + + ### XXX FIXME + ### Can I do this with signals? + self.sums._package = self # I don't remember what this line is for + + self.sums.save(*args, **kwargs) @property def arch(self): diff --git a/updateinfo/updateinfo_for_django/models/reference.py b/updateinfo/updateinfo_for_django/models/reference.py index 13bc4b6..ee983e6 100644 --- a/updateinfo/updateinfo_for_django/models/reference.py +++ b/updateinfo/updateinfo_for_django/models/reference.py @@ -4,7 +4,7 @@ ''' from __future__ import unicode_literals from __future__ import absolute_import -from django.db import models +from django.db import models, transaction from django.utils.encoding import python_2_unicode_compatible from django.core.validators import URLValidator from django.core.exceptions import ObjectDoesNotExist diff --git a/updateinfo/updateinfo_for_django/models/referencestore.py b/updateinfo/updateinfo_for_django/models/referencestore.py index 5113ed8..9738cf4 100644 --- a/updateinfo/updateinfo_for_django/models/referencestore.py +++ b/updateinfo/updateinfo_for_django/models/referencestore.py @@ -39,6 +39,8 @@ class ReferenceStore(UpdateinfoReferenceStore): def __setitem__(self, key, value): ''' For simply adding a reference ''' + ### XXX FIXME + ### Should I use '.add' here? need to figure out how that works if not isinstance(value, type(self.Reference())): raise TypeError('I can only add ' + str(type(self.Reference())) + ' type objects, not ' + str(type(value))) @@ -86,9 +88,15 @@ class ReferenceStore(UpdateinfoReferenceStore): def save(self, *args, **kwargs): '''Make sure to update attached references on a save''' + + ### XXX FIXME + # Can I do this with signals? + + # First safe the reference for ref in self: self[ref].save(*args, **kwargs) + # Then add the linkage for ref in self: self[ref]._update.add(self._parent()) self[ref].save(*args, **kwargs) diff --git a/updateinfo/updateinfo_for_django/models/update.py b/updateinfo/updateinfo_for_django/models/update.py index b287907..e1294b5 100644 --- a/updateinfo/updateinfo_for_django/models/update.py +++ b/updateinfo/updateinfo_for_django/models/update.py @@ -4,7 +4,7 @@ ''' from __future__ import unicode_literals from __future__ import absolute_import -from django.db import models +from django.db import models, transaction from django.utils.encoding import python_2_unicode_compatible from django.core.exceptions import ObjectDoesNotExist @@ -71,7 +71,10 @@ class Update(UpdateinfoUpdate, models.Model): if self._status == None: raise ValueError('Cannot assign None: "status" does not allow null values.') - models.Model.save(self, *args, **kwargs) # Call the "real" save() method on this model. + super(Update, self).save(self, *args, **kwargs) # Call the "real" save() method on this model. + + ### XXX FIXME + ### This should be done with signals self.collections.save(*args, **kwargs) self.references.save(*args, **kwargs) diff --git a/updateinfo/updateinfo_for_django/tests/test_update.py b/updateinfo/updateinfo_for_django/tests/test_update.py index bf847b0..5a14c09 100644 --- a/updateinfo/updateinfo_for_django/tests/test_update.py +++ b/updateinfo/updateinfo_for_django/tests/test_update.py @@ -223,6 +223,7 @@ class UpdateinfoCompatUpdateModelTests(TestCase, UpdateinfoUpdateTests): # this is here to make sure manytomany works as expected self.ref_two_for_test().save() + ##XXX FIXME testentry.save() testobj = self.Update.objects.get(_updateid='1') @@ -263,7 +264,10 @@ class UpdateinfoCompatUpdateModelTests(TestCase, UpdateinfoUpdateTests): testentry.save() + ##XXX FIXME testobj = self.Update.objects.get(_updateid='1') + import subprocess + subprocess.check_call(['cp', '/home/riehecky/code/mydjangosite/mydjangosite/test.db', '/tmp/saved.db']) result = False if testobj.collections == testobj.collections: @@ -295,6 +299,7 @@ class UpdateinfoCompatUpdateModelTests(TestCase, UpdateinfoUpdateTests): testentry.collections.add(self.coll_two_for_test()) testentry.references.add(self.ref_two_for_test()) + ##XXX FIXME testentry.save() testobj = self.Update.objects.get(_updateid='1') @@ -329,9 +334,17 @@ class UpdateinfoCompatUpdateModelTests(TestCase, UpdateinfoUpdateTests): testentry.collections.add(self.coll_two_for_test()) testentry.references.add(self.ref_two_for_test()) + ##XXX FIXME testentry.save() testobj = self.Update.objects.get(_updateid='1') + + ##XXX FIXME + print('----') + print("->Where are my collections?") + print(testobj.xml) + print('----') + result = False if testobj.collections['iop']['aaasdf-jkl-gh.noarch.rpm'].sums['md5'] == 'd41d8cd98f00b204e9800998ecf8427e': result = True @@ -343,19 +356,25 @@ class UpdateModelTestsNoFixture(TestCase): Updateinfo = Updateinfo def test_load_sample_epel(self): '''Can we parse the epel sample into the database?''' - uinfo = self.Updateinfo() - _fd = open('/usr/share/doc/python-Updateinfo/samples/EPEL6-updateinfo.xml', 'r') - uinfo.xml = _fd.read() - _fd.close() - uinfo.save() + if os.path.exists('/usr/share/doc/python-Updateinfo/samples/EPEL6-updateinfo.xml'): + uinfo = self.Updateinfo() + _fd = open('/usr/share/doc/python-Updateinfo/samples/EPEL6-updateinfo.xml', 'r') + uinfo.xml = _fd.read() + _fd.close() + uinfo.save() + else: + raise unittest.SkipTest('Sample data not found in /usr/share/doc/') def test_load_sample_fedora(self): '''Can we parse the Fedora sample into the database?''' - uinfo = self.Updateinfo() - _fd = open('/usr/share/doc/python-Updateinfo/samples/Fedora-updateinfo.xml', 'r') - uinfo.xml = _fd.read() - _fd.close() - uinfo.save() + if os.path.exists('/usr/share/doc/python-Updateinfo/samples/Fedora-updateinfo.xml'): + uinfo = self.Updateinfo() + _fd = open('/usr/share/doc/python-Updateinfo/samples/Fedora-updateinfo.xml', 'r') + uinfo.xml = _fd.read() + _fd.close() + uinfo.save() + else: + raise unittest.SkipTest('Sample data not found in /usr/share/doc/') class UpdateModelTestsAddonsFixture(TestCase): fixtures = ['addons.json'] @@ -379,8 +398,6 @@ class UpdateModelTestsAddonsFixture(TestCase): '''How is our initial update as yaml''' uone = self.Update.objects.get(pk=1) - result = False - txt = '''title: Sl_Contrib_Template updateid: SL_contrib_template-1.0-0.el6 issued_date: 2013-03-08 00:00:00 @@ -417,6 +434,7 @@ updatefrom: riehecky@fnal.gov status: stable ''' + result = False if uone.yaml == txt: result = True @@ -429,9 +447,16 @@ status: stable result = False txt = ''' -PUT XML HERE!!!! +without collections my XML is bad ''' + ##XXX FIXME + print('----') + print("without collections my XML is bad") + print(uone.xml) + import subprocess + subprocess.check_call(['cp', '/home/riehecky/code/mydjangosite/mydjangosite/test.db', '/tmp/fixture.db']) + print('----') if uone.xml == txt: result = True