aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'grumpy/models.py')
-rw-r--r--grumpy/models.py27
1 files changed, 25 insertions, 2 deletions
diff --git a/grumpy/models.py b/grumpy/models.py
index 6fc2d49..1c582e4 100644
--- a/grumpy/models.py
+++ b/grumpy/models.py
@@ -134,6 +134,9 @@ class Herd(db.Model):
def __init__(self, name):
self.name = name
+ def __repr__(self):
+ return '<%s> - %s' % (self.__class__.__name__, self.name)
+
class Package(db.Model):
"""Represents packages in the system"""
@@ -166,12 +169,32 @@ class Package(db.Model):
self.mtime = datetime.fromtimestamp(mtime)
# shared pkg data (from metadata.xml)
self.ldesc = ebuild_src.longdescription
- self.devs = [] # TODO
- self.herds = [] # TODO
+ self.devs = []
+ self.herds = self._parse_herds(ebuild_src)
def __repr__(self):
return '<%s> - %s' % (self.__class__.__name__, self.key)
+ def _parse_herds(self, ebuild_src):
+ """Update package herds."""
+ herds = []
+ for herd in ebuild_src.herds:
+ if not herd or herd.strip() is None:
+ herd = 'fix-me'
+ herds.append(herd.strip())
+ herds = set(herds)
+ if not herds:
+ return []
+ # Sync herds with database
+ out = []
+ for herd in Herd.query.filter(Herd.name.in_(herds)).all():
+ if herd.name in herds:
+ out.append(herd)
+ herds.remove(herd.name)
+ for herd in herds:
+ out.append(Herd(herd))
+ return out
+
def sync(self, ebuild_src, mtime=time.time()):
"""Update package values from ebuild_src."""
self.__init__(ebuild_src, mtime)