small fixes to Record
authorGreg Price <price@mit.edu>
Fri, 27 Feb 2009 04:09:28 +0000 (23:09 -0500)
committerGreg Price <price@mit.edu>
Fri, 27 Feb 2009 04:09:28 +0000 (23:09 -0500)
svn path=/trunk/packages/invirt-database/; revision=2191

debian/changelog
python/database/owner.py
python/database/record.py

index 21d5a6a..c96b33a 100644 (file)
@@ -1,3 +1,14 @@
+invirt-database (0.1.8) unstable; urgency=low
+
+  [Peter Iannucci]
+  * Added Record superclass for models, handling __repr__ consistently.
+
+  [Greg Price]
+  * use self.c rather than self.__dict__ for SQLAlchemy fields
+  * make Record._ignore, Owner.get* classmethods
+
+ -- Greg Price <price@mit.edu>  Thu, 26 Feb 2009 22:38:02 -0500
+
 invirt-database (0.1.7) unstable; urgency=low
 
   * Disk quotas are measured in gibibytes.
index adb176c..43e7ca4 100755 (executable)
@@ -15,26 +15,23 @@ class Owner(NullableRecord):
     _format = dict([(_k,_unitFormatter(_v[1])) for _k,_v in _f.items()])
     _identity_field = 'owner_id'
 
-    def getMemoryQuotas(owner):
-        owner_info = Owner.query().filter_by(owner_id=owner).first()
+    @classmethod
+    def getMemoryQuotas(cls, owner):
+        owner_info = cls.query().filter_by(owner_id=owner).first()
         if owner_info == None:
-            owner_info = Owner(owner_id=owner)
+            owner_info = cls(owner_id=owner)
         return (owner_info.get('ram_quota_total'), owner_info.get('ram_quota_single'))
-    getMemoryQuotas = staticmethod(getMemoryQuotas)
 
-    def getDiskQuotas(owner):
-        owner_info = Owner.query().filter_by(owner_id=owner).first()
+    @classmethod
+    def getDiskQuotas(cls, owner):
+        owner_info = cls.query().filter_by(owner_id=owner).first()
         if owner_info == None:
-            owner_info = Owner(owner_id=owner)
+            owner_info = cls(owner_id=owner)
         return (owner_info.get('disk_quota_total'), owner_info.get('disk_quota_single'))
-    getDiskQuotas = staticmethod(getDiskQuotas)
 
-    def getVMQuotas(owner):
-        owner_info = Owner.query().filter_by(owner_id=owner).first()
+    @classmethod
+    def getVMQuotas(cls, owner):
+        owner_info = cls.query().filter_by(owner_id=owner).first()
         if owner_info == None:
-            owner_info = Owner(owner_id=owner)
+            owner_info = cls(owner_id=owner)
         return (owner_info.get('vms_quota_total'), owner_info.get('vms_quota_active'))
-    getVMQuotas = staticmethod(getVMQuotas)
-
-    def _ignore(self):
-        return super(Owner, self)._ignore() + ['getMemoryQuotas', 'getDiskQuotas', 'getVMQuotas']
index b1b46bb..4962322 100755 (executable)
@@ -1,10 +1,12 @@
 class Record(object):
     _identity_field = None
+
     def get(self, field):
         try:
             return self.__getattribute__(field)
         except:
             return None
+
     def _formatField(self, field):
         v = self.get(field)
         if callable(v):
@@ -16,10 +18,16 @@ class Record(object):
                 return '[%d x %s]'%(len(v), type(v[0]))
         else:
             return repr(v)
+
+    @classmethod
+    def _ignore(cls):
+        return [cls._identity_field]
+
     def _fields(self):
         ignore = self._ignore()
-        keys = sorted(self.__class__.__dict__.keys())
-        return [(k,self._formatField(k)) for k in keys if k[0]!="_" and k not in ignore]
+        keys = sorted(self.c.keys())
+        return [(k,self._formatField(k)) for k in keys if k not in ignore]
+
     def __repr__(self):
         classname = self.__class__.__name__
 
@@ -34,8 +42,6 @@ class Record(object):
             payload = ": "+payload
 
         return "<%s%s%s>" % (classname, identity, payload)
-    def _ignore(self):
-        return [self._identity_field, 'c', 'query', 'get']
 
 class FormattableRecord(Record):
     _format = {}