From: "Slava Bacherikov" <slava@bacherikov.org.ua>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/gentoo-packages:master commit in: gpackages/apps/packages/, gpackages/apps/packages/management/commands/
Date: Sun, 3 Jun 2012 13:19:35 +0000 (UTC) [thread overview]
Message-ID: <1338729395.565c26d136ad4d149b0f069172b7d07011d594b3.bacher09@gentoo> (raw)
commit: 565c26d136ad4d149b0f069172b7d07011d594b3
Author: Slava Bacherikov <slava <AT> bacher09 <DOT> org>
AuthorDate: Sun Jun 3 13:16:35 2012 +0000
Commit: Slava Bacherikov <slava <AT> bacherikov <DOT> org <DOT> ua>
CommitDate: Sun Jun 3 13:16:35 2012 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/gentoo-packages.git;a=commit;h=565c26d1
Add herds and maintainers to scanning.
---
.../packages/management/commands/scanpackages.py | 78 ++++++++++++++-
gpackages/apps/packages/models.py | 104 ++++++++++----------
2 files changed, 129 insertions(+), 53 deletions(-)
diff --git a/gpackages/apps/packages/management/commands/scanpackages.py b/gpackages/apps/packages/management/commands/scanpackages.py
index 2968d65..b3adb97 100644
--- a/gpackages/apps/packages/management/commands/scanpackages.py
+++ b/gpackages/apps/packages/management/commands/scanpackages.py
@@ -1,6 +1,8 @@
from django.core.management.base import BaseCommand, CommandError
from packages import models
+from collections import defaultdict
import porttree
+import herds
import datetime
import logging
@@ -77,6 +79,67 @@ def _get_items(items_list, Model, field_name, cache_var):
return items_objects
+def scan_maintainers(maintainers_dict):
+ existend_maintainers = models.MaintainerModel.objects.all()
+ mo_dict = {}
+ to_del = []
+ for maintainer_object in existend_maintainers:
+ if maintainer_object in maintainers_dict:
+ # to update ?
+ mo_dict[maintainer_object.email] = maintainer_object
+ else:
+ to_del.append(maintainer_object.pk)
+
+ to_create = []
+ for maintainer in maintainers_dict.iterkeys():
+ if maintainer.email not in mo_dict:
+ to_create.append(maintainer)
+
+ mobjects = _create_objects(models.MaintainerModel, 'maintainer', to_create)
+ _update_cache_by_queryset(mo_dict, mobjects, 'email')
+
+ return mo_dict
+
+
+def scan_herds():
+ existent_herds = models.HerdsModel.objects.all()
+ herds_object = herds.Herds()
+ herds_dict = herds_object.get_herds_indict()
+ maintainers_dict = herds_object.get_maintainers_with_hers()
+ ho_dict = {}
+ to_del = []
+ for herd_object in existent_herds:
+ if herd_object.name not in herds_dict:
+ to_del.append(herd_object.pk)
+ else:
+ # to update ?
+ ho_dict[herd_object.name] = herd_object
+
+ models.HerdsModel.objects.filter(pk__in = to_del).delete()
+
+ to_create = []
+ for herd in herds_dict.itervalues():
+ if herd.name not in ho_dict:
+ to_create.append(herd)
+
+ cobjects = _create_objects(models.HerdsModel, 'herd', to_create)
+ _update_cache_by_queryset(ho_dict, cobjects, 'name')
+
+ mo_dict = scan_maintainers(maintainers_dict)
+ #Gen data for relate with herds
+ res = defaultdict(list)
+ for mainteiner, herds_names in maintainers_dict.iteritems():
+ for herd in herds_names:
+ res[herd].append(mo_dict[mainteiner.email])
+
+ for herd_name, herd_object in ho_dict.iteritems():
+ herd_object.maintainers.clear()
+ herd_object.maintainers.add(*res[herd_name])
+
+ return ho_dict, mo_dict
+
+
+
class Command(BaseCommand):
args = ''
help = 'Will scan package tree and update info about it in database'
@@ -116,17 +179,28 @@ class Command(BaseCommand):
def get_homepages_objects(ebuild):
homepages = ebuild.homepages
return _get_items(homepages, models.HomepageModel, 'url', homepages_cache)
+
st = datetime.datetime.now()
+ herds_cache, maintainers_cache = scan_herds()
+ def get_herds_objects(package):
+ herds = package.metadata.herds()
+ herds_objects = []
+ for herd in herds:
+ if herd in herds_cache:
+ herds_objects.append(herds_cache[herd])
+
+ return herds_objects
# Load homepages to cache
- for homepage in models.HomepageModel.objects.all():
- homepages_cache[homepage.url] = homepage
+ #for homepage in models.HomepageModel.objects.all():
+ #homepages_cache[homepage.url] = homepage
for category in self.porttree.iter_categories():
category_object, categor_created = models.CategoryModel.objects.get_or_create(category = category)
for package in category.iter_packages():
print package
package_object, package_created = models.PackageModel.objects.get_or_create(package = package, category = category_object)
+ package_object.herds.add(*get_herds_objects(package))
for ebuild in package.iter_ebuilds():
ebuild_object = models.EbuildModel()
ebuild_object.init_by_ebuild(ebuild)
diff --git a/gpackages/apps/packages/models.py b/gpackages/apps/packages/models.py
index 2ad8faa..d3ff5f6 100644
--- a/gpackages/apps/packages/models.py
+++ b/gpackages/apps/packages/models.py
@@ -42,6 +42,57 @@ class CategoryModel(models.Model):
def __unicode__(self):
return self.category
+class MaintainerModel(models.Model):
+
+ def __init__(self, *args, **kwargs):
+ #TODO: Bad code, maybe use some libraries for overload methods
+ maintainer = None
+ if 'maintainer' in kwargs:
+ maintainer = kwargs['maintainer']
+ del kwargs['maintainer']
+ super(MaintainerModel, self).__init__(*args, **kwargs)
+ if maintainer is not None:
+ self.init_by_maintainer(maintainer)
+
+ name = models.CharField(max_length = 255, blank = True, null = True)
+ email = models.EmailField(unique = True)
+ role = models.TextField(blank = True, null = True)
+
+ objects = managers.MaintainerManager()
+
+ def init_by_maintainer(self, maintainer):
+ self.name = maintainer.name
+ self.email = maintainer.email
+ self.role = maintainer.role
+
+ def __unicode__(self):
+ return ':'.join((unicode(self.name), self.email))
+
+class HerdsModel(models.Model):
+
+ def __init__(self, *args, **kwargs):
+ herd = None
+ if 'herd' in kwargs:
+ herd = kwargs['herd']
+ del kwargs['herd']
+ super(HerdsModel, self).__init__(*args, **kwargs)
+ if herd is not None:
+ self.init_by_herd(herd)
+
+ name = models.CharField(unique = True, max_length = 150)
+ email = models.EmailField()
+ description = models.TextField(blank = True, null = True)
+ maintainers = models.ManyToManyField(MaintainerModel, blank = True)
+
+ objects = managers.HerdsManager()
+
+ def init_by_herd(self, herd):
+ self.name = herd.name
+ self.email = herd.email
+ self.description = herd.description
+
+ def __unicode__(self):
+ return self.name
class PackageModel(models.Model):
def __init__(self, *args, **kwargs):
@@ -69,6 +120,8 @@ class PackageModel(models.Model):
changelog_mtime = models.DateTimeField(blank = True, null = True)
manifest_mtime = models.DateTimeField(blank = True, null = True)
mtime = models.DateTimeField(blank = True, null = True)
+
+ herds = models.ManyToManyField(HerdsModel, blank = True)
# Different versions can have different licenses, or homepages.
objects = managers.PackageManager()
@@ -220,54 +273,3 @@ class Keyword(models.Model):
unique_together = ('ebuild', 'arch')
-class MaintainerModel(models.Model):
-
- def __init__(self, *args, **kwargs):
- #TODO: Bad code, maybe use some libraries for overload methods
- maintainer = None
- if 'maintainer' in kwargs:
- maintainer = kwargs['maintainer']
- del kwargs['maintainer']
- super(MaintainerModel, self).__init__(*args, **kwargs)
- if maintainer is not None:
- self.init_by_maintainer(maintainer)
-
- name = models.CharField(max_length = 255, blank = True, null = True)
- email = models.EmailField(unique = True)
- role = models.TextField(blank = True, null = True)
-
- objects = managers.MaintainerManager()
-
- def init_by_maintainer(self, maintainer):
- self.name = maintainer.name
- self.email = maintainer.email
- self.role = maintainer.role
-
- def __unicode__(self):
- return ':'.join((unicode(self.name), self.email))
-
-class HerdsModel(models.Model):
-
- def __init__(self, *args, **kwargs):
- herd = None
- if 'herd' in kwargs:
- herd = kwargs['herd']
- del kwargs['herd']
- super(HerdsModel, self).__init__(*args, **kwargs)
- if herd is not None:
- self.init_by_herd(herd)
-
- name = models.CharField(unique = True, max_length = 150)
- email = models.EmailField()
- description = models.TextField(blank = True, null = True)
- maintainers = models.ManyToManyField(MaintainerModel, blank = True)
-
- objects = managers.HerdsManager()
-
- def init_by_herd(self, herd):
- self.name = herd.name
- self.email = herd.email
- self.description = herd.description
-
- def __unicode__(self):
- return self.name
next reply other threads:[~2012-06-03 13:19 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-06-03 13:19 Slava Bacherikov [this message]
-- strict thread matches above, loose matches on Subject: below --
2012-08-26 23:00 [gentoo-commits] proj/gentoo-packages:master commit in: gpackages/apps/packages/, gpackages/apps/packages/management/commands/ Slava Bacherikov
2012-08-22 17:55 Slava Bacherikov
2012-07-18 23:03 Slava Bacherikov
2012-07-17 9:42 Slava Bacherikov
2012-07-06 23:09 Slava Bacherikov
2012-07-05 23:27 Slava Bacherikov
2012-06-19 0:12 Slava Bacherikov
2012-06-18 23:00 Slava Bacherikov
2012-06-13 22:15 Slava Bacherikov
2012-06-10 22:23 Slava Bacherikov
2012-06-10 17:51 Slava Bacherikov
2012-06-09 18:19 Slava Bacherikov
2012-06-09 18:19 Slava Bacherikov
2012-06-04 20:09 Slava Bacherikov
2012-06-04 20:09 Slava Bacherikov
2012-06-04 20:09 Slava Bacherikov
2012-06-04 20:09 Slava Bacherikov
2012-06-03 16:19 Slava Bacherikov
2012-06-01 21:28 Slava Bacherikov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1338729395.565c26d136ad4d149b0f069172b7d07011d594b3.bacher09@gentoo \
--to=slava@bacherikov.org.ua \
--cc=gentoo-commits@lists.gentoo.org \
--cc=gentoo-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox