public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] proj/gentoo-packages:master commit in: gpackages/apps/packages/, gpackages/libs/
@ 2012-06-05 15:49 Slava Bacherikov
  0 siblings, 0 replies; 12+ messages in thread
From: Slava Bacherikov @ 2012-06-05 15:49 UTC (permalink / raw
  To: gentoo-commits

commit:     1c4a2de7b4a6ae5f718e707c407ece8ecff87b04
Author:     Slava Bacherikov <slava <AT> bacher09 <DOT> org>
AuthorDate: Tue Jun  5 12:44:49 2012 +0000
Commit:     Slava Bacherikov <slava <AT> bacherikov <DOT> org <DOT> ua>
CommitDate: Tue Jun  5 12:44:49 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/gentoo-packages.git;a=commit;h=1c4a2de7

Updating some info

---
 gpackages/apps/packages/scan.py |   19 +++++++++++++------
 gpackages/libs/herds.py         |    5 ++++-
 2 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/gpackages/apps/packages/scan.py b/gpackages/apps/packages/scan.py
index d4b4601..8deb289 100644
--- a/gpackages/apps/packages/scan.py
+++ b/gpackages/apps/packages/scan.py
@@ -23,6 +23,8 @@ def _get_from_database(Model, field_name, request_items):
 
 def _update_cache_by_queryset(cache, queryset, field_name):
     geted_items = set()
+    if queryset is None:
+        return None
     for item in queryset:
         cache[getattr(item, field_name)] = item
         geted_items.add(getattr(item, field_name))
@@ -77,20 +79,23 @@ def _get_items(items_list, Model, field_name, cache_var):
 
 def scan_maintainers(maintainers_dict):
     existend_maintainers = models.MaintainerModel.objects.all()
+    main_dict = {}
     mo_dict = {}
-    to_del = []
+    #to_del = []
+    _update_cache_by_queryset(main_dict, maintainers_dict.keys(), 'email')
     for maintainer_object in existend_maintainers:
-        if maintainer_object in maintainers_dict:
-            maintainer_cmp = maintainers_dict[maintainer_object]
+        if maintainer_object.email in main_dict:
+            maintainer_cmp = main_dict[maintainer_object.email]
             # need update ?
             if maintainer_object.check_or_need_update(maintainer_cmp):
                 # updating
                 maintainer_object.update_by_maintainer(maintainer_cmp)
                 maintainer_object.save(force_update = True)
             mo_dict[maintainer_object.email] = maintainer_object
-        else:
-            to_del.append(maintainer_object.pk)
-
+        #else:
+            #to_del.append(maintainer_object.pk)
+    #print to_del
+    #print mo_dict
     to_create = []
     for maintainer in maintainers_dict.iterkeys():
         if maintainer.email not in mo_dict:
@@ -265,6 +270,8 @@ def scanpackages():
                 if package_object.check_or_need_update(package):
                     # need update
                     pass
+                else:
+                    continue
             package_object.herds.add(*get_herds_objects(package))
             package_object.maintainers.add(*get_maintainers_objects(package))
             for ebuild in package.iter_ebuilds():

diff --git a/gpackages/libs/herds.py b/gpackages/libs/herds.py
index 7626d03..e665166 100644
--- a/gpackages/libs/herds.py
+++ b/gpackages/libs/herds.py
@@ -46,7 +46,10 @@ class Maintainer(AbstractXmlObject, ToStrMixin):
             self._email = self._email.lower()
 
     def __eq__(self, other):
-        return self.email == other.email
+        if isinstance(other, Maintainer):
+            return self.email == other.email
+        else:
+            return self.email == unicode(other)
 
     def __ne__(self, other):
         return self.email != other.email



^ permalink raw reply related	[flat|nested] 12+ messages in thread
* [gentoo-commits] proj/gentoo-packages:master commit in: gpackages/apps/packages/, gpackages/libs/
@ 2012-06-18 21:26 Slava Bacherikov
  0 siblings, 0 replies; 12+ messages in thread
From: Slava Bacherikov @ 2012-06-18 21:26 UTC (permalink / raw
  To: gentoo-commits

commit:     280b86959ff7a179802ede7f04b9d23881ab151a
Author:     Slava Bacherikov <slava <AT> bacher09 <DOT> org>
AuthorDate: Mon Jun 18 16:38:20 2012 +0000
Commit:     Slava Bacherikov <slava <AT> bacherikov <DOT> org <DOT> ua>
CommitDate: Mon Jun 18 16:38:20 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/gentoo-packages.git;a=commit;h=280b8695

Collect more info about repository

---
 gpackages/apps/packages/managers.py |   10 +++++++++-
 gpackages/apps/packages/models.py   |   33 +++++++++++++++++++++++++++++++++
 gpackages/apps/packages/scan.py     |    2 +-
 gpackages/libs/porttree.py          |    7 +++++++
 4 files changed, 50 insertions(+), 2 deletions(-)

diff --git a/gpackages/apps/packages/managers.py b/gpackages/apps/packages/managers.py
index ca1561c..45033d8 100644
--- a/gpackages/apps/packages/managers.py
+++ b/gpackages/apps/packages/managers.py
@@ -112,7 +112,15 @@ class VirtualPackageMixin(object):
 
         return super(VirtualPackageMixin, self).filter(*args, **kwargs)
 
+class RepositoryMixin(object):
+    def filter(self, *args, **kwargs):
+        repo = get_from_kwargs_and_del('repo', kwargs)
+        if repo is not None:
+            kwargs['name'] = repo.name
+        return super(RepositoryMixin, self).filter(*args, **kwargs)
+
 
 _gen_all_query_and_manager('Mixin', 'QuerySet', 'Manager',
                            PackageMixin, KeywordMixin, EbuildMixin, HerdsMixin,
-                           MaintainerMixin, VirtualPackageMixin)
+                           MaintainerMixin, VirtualPackageMixin,
+                           RepositoryMixin)

diff --git a/gpackages/apps/packages/models.py b/gpackages/apps/packages/models.py
index c2b62ac..6d96b42 100644
--- a/gpackages/apps/packages/models.py
+++ b/gpackages/apps/packages/models.py
@@ -29,8 +29,41 @@ class ArchesModel(models.Model):
         return self.name
 
 class RepositoryModel(AbstractDateTimeModel):
+    QUALITY_CHOICES = ( (0, 'stable'),
+                        (1, 'testing'),
+                        (2, 'experimental'),
+                      )
+
+    def __init__(self, *args, **kwargs):
+        repo = get_from_kwargs_and_del('repo', kwargs)
+        super(RepositoryModel, self).__init__(*args, **kwargs)
+
+        if repo is not None:
+            self.init_by_repo(repo)
+
     name = models.CharField(unique = True, max_length = 60)
+
+    # Additional info
     description = models.TextField(blank = True, null = True)
+    owner_name = models.CharField(max_length = 65 , blank = True, null = True)
+    owner_email = models.EmailField(blank = True, null = True)
+    homepage = models.URLField(blank = True, null = True)
+    official = models.BooleanField(default = False)
+    quality = models.PositiveSmallIntegerField(choices = QUALITY_CHOICES)
+
+    objects = managers.RepositoryManager()
+
+    def init_by_repo(self, repo):
+        self.name = repo.name
+        self.update_metadata(repo)
+
+    def update_metadata(self, repo):
+        self.description = repo.metadata.description
+        self.owner_name = repo.metadata.owner_name
+        self.owner_email = repo.metadata.owner_email
+        self.homepage = repo.metadata.homepage
+        self.official = repo.metadata.official
+        self.quality = repo.metadata.int_quality
 
     def __unicode__(self):
         return self.name

diff --git a/gpackages/apps/packages/scan.py b/gpackages/apps/packages/scan.py
index d716380..6d14237 100644
--- a/gpackages/apps/packages/scan.py
+++ b/gpackages/apps/packages/scan.py
@@ -310,7 +310,7 @@ class Scanner(object):
         self.output("Scaning repository '%s'\n", repo.name, 3)
 
         repo_obj, repo_created = models.RepositoryModel \
-            .objects.get_or_create(name = repo.name)
+            .objects.get_or_create(repo = repo)
 
         if not repo_created:
             #Update modification time

diff --git a/gpackages/libs/porttree.py b/gpackages/libs/porttree.py
index 995ef91..75812ab 100644
--- a/gpackages/libs/porttree.py
+++ b/gpackages/libs/porttree.py
@@ -20,6 +20,9 @@ from my_etree import etree
 # Validators
 from validators import validate_url, validate_url, ValidationError
 
+# Repo info
+from repo_info import TreeMetadata
+
 __all__ = ('Portage','PortTree', 'Category', 'Package', 'Ebuild')
 
 BINDB = portage.db[portage.root]["bintree"].dbapi
@@ -257,6 +260,10 @@ class PortTree(ToStrMixin):
         return self.porttree
 
     @cached_property
+    def metadata(self):
+        return TreeMetadata(self.name)
+
+    @cached_property
     def use_desc(self):
         return _get_info_by_func(get_uses_info,
                                  self.porttree_path,



^ permalink raw reply related	[flat|nested] 12+ messages in thread
* [gentoo-commits] proj/gentoo-packages:master commit in: gpackages/apps/packages/, gpackages/libs/
@ 2012-06-12 18:34 Slava Bacherikov
  0 siblings, 0 replies; 12+ messages in thread
From: Slava Bacherikov @ 2012-06-12 18:34 UTC (permalink / raw
  To: gentoo-commits

commit:     067e99853e10caa2137e3b6fd04162e585e50148
Author:     Slava Bacherikov <slava <AT> bacher09 <DOT> org>
AuthorDate: Tue Jun 12 18:34:20 2012 +0000
Commit:     Slava Bacherikov <slava <AT> bacherikov <DOT> org <DOT> ua>
CommitDate: Tue Jun 12 18:34:20 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/gentoo-packages.git;a=commit;h=067e9985

Repair use descriptions

---
 gpackages/apps/packages/managers.py |   16 +++++-
 gpackages/apps/packages/models.py   |    4 +-
 gpackages/apps/packages/scan.py     |  103 +++++++++++++++++++----------------
 gpackages/libs/use_info.py          |    6 +-
 4 files changed, 76 insertions(+), 53 deletions(-)

diff --git a/gpackages/apps/packages/managers.py b/gpackages/apps/packages/managers.py
index 2ca2dc8..7d02c05 100644
--- a/gpackages/apps/packages/managers.py
+++ b/gpackages/apps/packages/managers.py
@@ -3,7 +3,6 @@ from porttree import Category, Package, Ebuild, Keyword
 import packages.models
 from generic import get_from_kwargs_and_del
 
-
 def _gen_query_and_manager(MixinClass, QueryClassName, ManagerClassName):
     QueryClass = type(QueryClassName, (MixinClass, models.query.QuerySet), {})
     ManagerClass = type(ManagerClassName, (MixinClass, models.Manager),{
@@ -100,7 +99,20 @@ class MaintainerMixin(object):#{{{
             kwargs['email'] = maintainer.email
         return super(MaintainerMixin, self).filter(*args, **kwargs)#}}}
 
+def get_name_and_category_by_cp(package):
+    return package.split('/')
+
+
+class VirtualPackageMixin(object):
+    def filter(self, **kwargs):
+        package = get_from_kwargs_and_del('package', kwargs)
+        if package is not None:
+            category, name = get_name_and_category_by_cp(package)
+            kwargs.update({'name': name, 'category__category': category})
+
+        return super(VirtualPackageMixin, self).filter(**kwargs)
+
 
 _gen_all_query_and_manager('Mixin', 'QuerySet', 'Manager',
                            PackageMixin, KeywordMixin, EbuildMixin, HerdsMixin,
-                           MaintainerMixin)
+                           MaintainerMixin, VirtualPackageMixin)

diff --git a/gpackages/apps/packages/models.py b/gpackages/apps/packages/models.py
index b91673e..e99a1a2 100644
--- a/gpackages/apps/packages/models.py
+++ b/gpackages/apps/packages/models.py
@@ -120,6 +120,8 @@ class VirtualPackageModel(models.Model):
     name = models.CharField(max_length = 254)
     category = models.ForeignKey(CategoryModel)
 
+    objects = managers.VirtualPackageManager()
+
     @property
     def cp(self):
         return "%s/%s" % (unicode(self.category), self.name)
@@ -211,7 +213,7 @@ class UseFlagModel(models.Model):
 
 class UseFlagDescriptionModel(models.Model):
     use_flag = models.ForeignKey(UseFlagModel)
-    package = models.ForeignKey(PackageModel)
+    package = models.ForeignKey(VirtualPackageModel)
     description = models.TextField()
 
     def check_or_need_update(self, description):

diff --git a/gpackages/apps/packages/scan.py b/gpackages/apps/packages/scan.py
index c725951..3417c12 100644
--- a/gpackages/apps/packages/scan.py
+++ b/gpackages/apps/packages/scan.py
@@ -6,7 +6,6 @@ from collections import defaultdict
 from generic import StrThatIgnoreCase
 import porttree
 import herds
-import use_info
 
 import anydbm
 
@@ -493,53 +492,63 @@ class Scanner(object):
                 .exclude(pk__in = existend_packages).delete()
 
 
+    def update_globals_uses_descriptions(self, use_dict):
+        existend_use_objects = models.UseFlagModel.objects.only('name') \
+            .filter(name__in = use_dict.keys())
 
-cache_dict =  None
-def update_globals_uses_descriptions():
-    # Need changes 
-    uses_g = use_info.get_uses_info()
-    existend_use_objects = models.UseFlagModel.objects.filter(name__in = uses_g.keys())
-    for use_object in existend_use_objects:
-        use_object.description = uses_g[use_object.name]
-        use_object.save(force_update = True)
-    
+        for use_object in existend_use_objects:
+            use_object.description = use_dict[use_object.name]
+            use_object.save(force_update = True)
 
-def scan_uses_description():
-    # need changes for support many repos !!!
-    uses_local = use_info.get_local_uses_info()
-    existend_use_objects = models.UseFlagModel.objects.filter(name__in = uses_local.keys())
-    existend_use_local_descr = models.UseFlagDescriptionModel.objects.all()
-    cache_uses = {}
-    _update_cache_by_queryset(cache_uses, existend_use_objects, 'name')
-    use_local_cache = defaultdict(dict)
-    for use_obj in existend_use_local_descr:
-        use_local_cache[use_obj.use_flag.name][use_obj.package.cp] = use_obj
-
-    package_cache = dict()
-    for use_flag, packages_dict in uses_local.iteritems():
-        if use_flag not in cache_uses:
-            continue
-        use_flag_object = cache_uses[use_flag]
-        to_create = []
-        for package, description in packages_dict.iteritems():
-            if package in package_cache:
-                package_object = package_cache[package]
+    def update_all_globals_uses_descriptions(self):
+        self.update_globals_uses_descriptions(portage.get_all_use_desc())
+
+    def scan_all_uses_description(self):
+        self.scan_uses_description(portage.get_all_use_local_desc())
+
+    def scan_uses_description(self, use_local_desc):
+        existent_use_objects = models.UseFlagModel.objects.filter(name__in = use_local_desc.keys())
+        existent_use_local_descr = models.UseFlagDescriptionModel.objects.all()
+        cache_uses = {}
+        _update_cache_by_queryset(cache_uses, existent_use_objects, 'name')
+
+        # Cache existent Use Local Descr
+        use_local_cache = defaultdict(dict)
+        for use_obj in existent_use_local_descr:
+            use_local_cache[use_obj.use_flag.name][use_obj.package.cp] = use_obj
+
+        package_cache = dict()
+        for use_flag, packages_dict in use_local_desc.iteritems():
+            # If this use flag not in database than create it
+            if use_flag not in cache_uses:
+                # Maybe get_or_create ?
+                use_flag_object = models.UseFlagModel.objects.create(name = use_flag)
+                # Add to cache
+                cache_uses[use_flag.lower()] = use_flag_object
             else:
-                try:
-                    package_object = models.PackageModel.objects.get(package = package)
-                except models.PackageModel.DoesNotExist:
-                    continue
+                use_flag_object = cache_uses[use_flag]
+
+            to_create = []
+            for package, description in packages_dict.iteritems():
+                if package in package_cache:
+                    package_object = package_cache[package]
                 else:
-                    package_cache[package] = package_object
-            if package not in use_local_cache[use_flag]:
-                to_create.append(
-                models.UseFlagDescriptionModel(package = package_object,
-                                               use_flag = use_flag_object,
-                                               description = description))
-            else:
-                use_desc_obj = use_local_cache[use_flag][package]
-                if use_desc_obj.check_or_need_update(description):
-                    use_desc_obj.description = description
-                    use_desc_obj.save(force_update = True)
-        models.UseFlagDescriptionModel.objects.bulk_create(to_create)
-            
+                    try:
+                        package_object = models.VirtualPackageModel.objects.get(package = package)
+                    except models.VirtualPackageModel.DoesNotExist:
+                        continue
+                    else:
+                        package_cache[package] = package_object
+
+                if package not in use_local_cache[use_flag]:
+                    to_create.append(
+                    models.UseFlagDescriptionModel(package = package_object,
+                                                   use_flag = use_flag_object,
+                                                   description = description))
+                else:
+                    use_desc_obj = use_local_cache[use_flag][package]
+                    if use_desc_obj.check_or_need_update(description):
+                        use_desc_obj.description = description
+                        use_desc_obj.save(force_update = True)
+            models.UseFlagDescriptionModel.objects.bulk_create(to_create)
+                

diff --git a/gpackages/libs/use_info.py b/gpackages/libs/use_info.py
index c89dfe6..c04f640 100644
--- a/gpackages/libs/use_info.py
+++ b/gpackages/libs/use_info.py
@@ -3,7 +3,7 @@ from collections import defaultdict
 
 __all__ = ('get_uses_info', 'get_local_uses_info')
 
-USES_RE = r'(?P<use>[^#].*) - (?P<description>.*)'
+USES_RE = r'(?P<use>[a-zA-Z0-9\-]+) - (?P<description>.*)'
 USES_DESC_RE = r'^%s$' % USES_RE
 USES_LOCAL_DESC_RE = r'^(?P<package>[^#].*):%s$' % USES_RE
 
@@ -32,7 +32,7 @@ def get_uses_info(filename = '/usr/portage/profiles/use.desc'):
         In portage public api `get_use_flag_dict`
     """
     def action(res_dict, match):
-        res_dict[match['use']] = match['description']
+        res_dict[match['use'].lower()] = match['description']
 
     return _get_info(filename, use_re, action)
 
@@ -48,6 +48,6 @@ def get_local_uses_info(filename = '/usr/portage/profiles/use.local.desc'):
         In portage public api `get_use_flag_dict`
     """
     def action(res_dict, match):
-        res_dict[match['use']][match['package']] = match['description']
+        res_dict[match['use'].lower()][match['package']] = match['description']
 
     return _get_info(filename, use_local_re, action, defaultdict(dict))



^ permalink raw reply related	[flat|nested] 12+ messages in thread
* [gentoo-commits] proj/gentoo-packages:master commit in: gpackages/apps/packages/, gpackages/libs/
@ 2012-06-12 18:34 Slava Bacherikov
  0 siblings, 0 replies; 12+ messages in thread
From: Slava Bacherikov @ 2012-06-12 18:34 UTC (permalink / raw
  To: gentoo-commits

commit:     4eb31f7e064d09f5173c16c7334811da78dcb768
Author:     Slava Bacherikov <slava <AT> bacher09 <DOT> org>
AuthorDate: Tue Jun 12 13:59:55 2012 +0000
Commit:     Slava Bacherikov <slava <AT> bacherikov <DOT> org <DOT> ua>
CommitDate: Tue Jun 12 13:59:55 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/gentoo-packages.git;a=commit;h=4eb31f7e

Save category description to database.

---
 gpackages/apps/packages/models.py |   15 +++++++++++++++
 gpackages/apps/packages/scan.py   |    8 +++++++-
 gpackages/libs/porttree.py        |   10 +++++++++-
 3 files changed, 31 insertions(+), 2 deletions(-)

diff --git a/gpackages/apps/packages/models.py b/gpackages/apps/packages/models.py
index 77519bc..b91673e 100644
--- a/gpackages/apps/packages/models.py
+++ b/gpackages/apps/packages/models.py
@@ -37,8 +37,23 @@ class RepositoryModel(models.Model):
         return self.name
 
 class CategoryModel(models.Model):
+    def __init__(self, *args, **kwargs):
+        super(CategoryModel, self).__init__(*args, **kwargs)
+
+        category = kwargs.get('category')
+        if isinstance(category, Category):  
+            self.update_by_category(category)
+
+    def update_by_category(self, category):
+        self.description = category.metadata.default_descr
+        self.metadata_hash = category.metadata_sha1
+
+    def check_or_need_update(self, category):
+        return self.metadata_hash == category.metadata_sha1
 
     category = models.CharField(unique = True, max_length = 70)
+    description = models.TextField(blank = True, null = True)
+    metadata_hash = models.CharField(max_length = 128, null = True)
     
     def __unicode__(self):
         return unicode(self.category)

diff --git a/gpackages/apps/packages/scan.py b/gpackages/apps/packages/scan.py
index 82c8a91..c725951 100644
--- a/gpackages/apps/packages/scan.py
+++ b/gpackages/apps/packages/scan.py
@@ -448,7 +448,13 @@ class Scanner(object):
         for category in porttree.iter_categories():
             existend_packages = []
             category_object, category_created = models.CategoryModel \
-                .objects.get_or_create(category = category)
+                .objects.only('category','metadata_hash') \
+                .get_or_create(category = category)
+
+            if not category_created:
+                if category_object.check_or_need_update(category):
+                    category_object.update_by_category(category)
+                    category_object.save(force_update = True)
 
             existend_categorys.append(category_object.pk)
             for package in category.iter_packages():

diff --git a/gpackages/libs/porttree.py b/gpackages/libs/porttree.py
index 933ceeb..c33c159 100644
--- a/gpackages/libs/porttree.py
+++ b/gpackages/libs/porttree.py
@@ -271,9 +271,10 @@ class PortTree(ToStrMixin):
                                  self.porttree_path,
                                  'profiles/use.local.desc')
 
-class CategoryMetadata(object):
+class CategoryMetadata(ToStrMixin):
 
     def __init__(self, metadata_path):
+        self._metadata_path = metadata_path
         self._metadata_xml = etree.parse(metadata_path)
         self._descrs = {}
         self._parse_descrs()
@@ -291,6 +292,9 @@ class CategoryMetadata(object):
     def default_descr(self):
         return self._descrs.get('en')
 
+    def __unicode__(self):
+        return unicode(self._metadata_path)
+
 
 class Category(ToStrMixin):
     "Represent category of portage tree as object"
@@ -331,6 +335,10 @@ class Category(ToStrMixin):
         return os.path.join(self.category_path, 'metadata.xml')
 
     @cached_property
+    def metadata_sha1(self):
+        return file_sha1(self.metadata_path)
+
+    @cached_property
     def metadata(self):
         return CategoryMetadata(self.metadata_path)
 



^ permalink raw reply related	[flat|nested] 12+ messages in thread
* [gentoo-commits] proj/gentoo-packages:master commit in: gpackages/apps/packages/, gpackages/libs/
@ 2012-06-12 18:34 Slava Bacherikov
  0 siblings, 0 replies; 12+ messages in thread
From: Slava Bacherikov @ 2012-06-12 18:34 UTC (permalink / raw
  To: gentoo-commits

commit:     845b3a856ce22a1b11da72b8acf3d5acc12253e1
Author:     Slava Bacherikov <slava <AT> bacher09 <DOT> org>
AuthorDate: Tue Jun 12 00:33:42 2012 +0000
Commit:     Slava Bacherikov <slava <AT> bacherikov <DOT> org <DOT> ua>
CommitDate: Tue Jun 12 00:33:42 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/gentoo-packages.git;a=commit;h=845b3a85

Add validation for homepages

---
 gpackages/apps/packages/models.py |   11 ++++++--
 gpackages/libs/generic.py         |    3 ++
 gpackages/libs/porttree.py        |   51 ++++++++++++++++++++++--------------
 3 files changed, 42 insertions(+), 23 deletions(-)

diff --git a/gpackages/apps/packages/models.py b/gpackages/apps/packages/models.py
index e9a43b4..77519bc 100644
--- a/gpackages/apps/packages/models.py
+++ b/gpackages/apps/packages/models.py
@@ -4,6 +4,11 @@ from porttree import Category, Package, Ebuild
 import managers
 from generic import get_from_kwargs_and_del
 
+from django.core.validators import URLValidator, validate_email 
+from django.core.exceptions import ValidationError
+
+validate_url = URLValidator()
+
 class AbstractDateTimeModel(models.Model):
     created_datetime = models.DateTimeField(auto_now_add = True)
     updated_datetime = models.DateTimeField(auto_now = True)
@@ -12,7 +17,7 @@ class AbstractDateTimeModel(models.Model):
         abstract = True
 
 class HomepageModel(models.Model):
-    url = models.URLField(max_length=255, unique = True)
+    url = models.URLField(max_length=255, unique = True, validators = [validate_url])
 
     def __unicode__(self):
         return self.url
@@ -47,7 +52,7 @@ class MaintainerModel(AbstractDateTimeModel):
             self.init_by_maintainer(maintainer)
         
     name = models.CharField(max_length = 255, blank = True, null = True)
-    email = models.EmailField(unique = True)
+    email = models.EmailField(unique = True, validators = [validate_email])
 
     objects = managers.MaintainerManager()
 
@@ -74,7 +79,7 @@ class HerdsModel(AbstractDateTimeModel):
             self.init_by_herd(herd)
 
     name = models.CharField(unique = True, max_length = 150)
-    email = models.EmailField()
+    email = models.EmailField(validators = [validate_email])
     description = models.TextField(blank = True, null = True)
     maintainers = models.ManyToManyField(MaintainerModel, blank = True)
 

diff --git a/gpackages/libs/generic.py b/gpackages/libs/generic.py
index f1751b0..409ec09 100644
--- a/gpackages/libs/generic.py
+++ b/gpackages/libs/generic.py
@@ -44,6 +44,9 @@ class StrThatIgnoreCase(unicode):
     def __ne__(self, other):
         return self._forcmp != unicode(other).lower()
 
+def lofstr_to_ig(list_obj):
+    return [ StrThatIgnoreCase(item) for item in list_obj]
+
 class ToStrMixin(object):
     """Abstract class for inheritence, allow add simple `__str__` and `__repr__`
     methods

diff --git a/gpackages/libs/porttree.py b/gpackages/libs/porttree.py
index b5b90d8..6beac52 100644
--- a/gpackages/libs/porttree.py
+++ b/gpackages/libs/porttree.py
@@ -10,10 +10,16 @@ from gentoolkit.package import Package as PackageInfo
 from gentoolkit.metadata import MetaData
 from gentoolkit import errors
 from generic import ToStrMixin, file_sha1, file_mtime, cached_property, \
-                    file_get_content, StrThatIgnoreCase
+                    file_get_content, StrThatIgnoreCase, lofstr_to_ig
 from use_info import get_uses_info, get_local_uses_info
 import os
 
+# Validators
+from django.core.validators import URLValidator, validate_email 
+from django.core.exceptions import ValidationError
+
+validate_url = URLValidator()
+
 __all__ = ('Portage','PortTree', 'Category', 'Package', 'Ebuild')
 
 BINDB = portage.db[portage.root]["bintree"].dbapi
@@ -473,34 +479,39 @@ class Ebuild(ToStrMixin):
                            name = 'slot')
 
     @cached_property
-    def homepages(self):
-        "List of homepages"
-        ho_list = self.homepage_val.split()
-        ret_list = []
-        for ho in ho_list:
-            ret_list.append(StrThatIgnoreCase(ho))
-        return ret_list
+    def homepages_splited(self):
+        return self.homepage_val.split()
+
+    @cached_property
+    def homepages_validated(self):
+        ret = []
+        for homepage in self.homepages_splited:
+            try:
+                validate_url(homepage)
+            except ValidationError:
+                pass
+            else:
+                ret.append(homepage)
+        return ret
+        
 
-    def get_uniq_homepages(self):
-        return frozenset(self.homepages)
+    @cached_property
+    def homepages(self):
+        "Tuple of homepages"
+        return tuple(set(lofstr_to_ig(self.homepages_validated)))
 
     @cached_property
     def homepage(self):
         "First homepage in list"
-        return self.homepages[0] if len(self.homepages)>=1 else ''
+        return self.homepages_validated[0] if len(self.homepages)>=1 else ''
 
+    @cached_property
+    def _licenses(self):
+        return filter(_license_filter, self.license.split())
 
     @cached_property
     def licenses(self):
-        "List of licenses used in ebuild"
-        license_list = filter(_license_filter, self.license.split())
-        ret_list = []
-        for lic in license_list:
-            ret_list.append(StrThatIgnoreCase(lic))
-        return ret_list
-
-    def get_uniq_licenses(self):
-        return frozenset(self.licenses)
+        return tuple(set(lofstr_to_ig(self._licenses)))
 
     sha1 = cached_property(_file_hash("ebuild_path"), name = 'sha1')
     mtime = cached_property(_file_mtime("ebuild_path"), name = 'mtime')



^ permalink raw reply related	[flat|nested] 12+ messages in thread
* [gentoo-commits] proj/gentoo-packages:master commit in: gpackages/apps/packages/, gpackages/libs/
@ 2012-06-07 22:48 Slava Bacherikov
  0 siblings, 0 replies; 12+ messages in thread
From: Slava Bacherikov @ 2012-06-07 22:48 UTC (permalink / raw
  To: gentoo-commits

commit:     6bf1b245210d63a003efa22db88244a35cf0bfe0
Author:     Slava Bacherikov <slava <AT> bacher09 <DOT> org>
AuthorDate: Thu Jun  7 18:54:24 2012 +0000
Commit:     Slava Bacherikov <slava <AT> bacherikov <DOT> org <DOT> ua>
CommitDate: Thu Jun  7 19:32:43 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/gentoo-packages.git;a=commit;h=6bf1b245

Simple code

---
 gpackages/apps/packages/managers.py |   15 +++++++--------
 gpackages/apps/packages/models.py   |   33 +++++++--------------------------
 gpackages/libs/generic.py           |   23 +++++++++++++++++++++++
 3 files changed, 37 insertions(+), 34 deletions(-)

diff --git a/gpackages/apps/packages/managers.py b/gpackages/apps/packages/managers.py
index c4ab013..ed5018c 100644
--- a/gpackages/apps/packages/managers.py
+++ b/gpackages/apps/packages/managers.py
@@ -1,6 +1,7 @@
 from django.db import models, connections, router, transaction, IntegrityError
 from porttree import Category, Package, Ebuild, Keyword
 import packages.models
+from generic import get_from_kwargs_and_del
 
 
 def _gen_query_and_manager(MixinClass, QueryClassName, ManagerClassName):
@@ -72,19 +73,17 @@ class EbuildMixin(object):#{{{
 
 class HerdsMixin(object):#{{{
     def filter(self, *args, **kwargs):
-        if 'herd__in' in kwargs:
-            herds = kwargs['herd__in']
-            del kwargs['herd__in']
-            kwargs['name__in'] = herds
+        herd__in = get_from_kwargs_and_del('herd__in',kwargs)
+        if herd__in is not None:
+            kwargs['name__in'] = herd__in
         return super(HerdsMixin, self).filter(*args, **kwargs)#}}}
 
 
 class MaintainerMixin(object):#{{{
     def filter(self, *args, **kwargs):
-        if 'maintainer__in'  in kwargs:
-            maintars = kwargs['maintainer__in']
-            del kwargs['maintainer__in']
-            kwargs['email__in'] = maintars
+        maintainer__in = get_from_kwargs_and_del('maintainer__in', kwargs)
+        if maintainer__in is not None:
+            kwargs['email__in'] = maintainer__in
         return super(MaintainerMixin, self).filter(*args, **kwargs)#}}}
 
 

diff --git a/gpackages/apps/packages/models.py b/gpackages/apps/packages/models.py
index 3b30d6f..82d3ca5 100644
--- a/gpackages/apps/packages/models.py
+++ b/gpackages/apps/packages/models.py
@@ -2,6 +2,7 @@ from django.db import models
 
 from porttree import Category, Package, Ebuild
 import managers
+from generic import get_from_kwargs_and_del
 
 class AbstractDateTimeModel(models.Model):
     created_datetime = models.DateTimeField(auto_now_add = True)
@@ -40,11 +41,7 @@ class CategoryModel(models.Model):
 class MaintainerModel(AbstractDateTimeModel):
 
     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']
+        maintainer = get_from_kwargs_and_del('maintainer', kwargs)
         super(MaintainerModel, self).__init__(*args, **kwargs)
         if maintainer is not None:
             self.init_by_maintainer(maintainer)
@@ -73,10 +70,7 @@ class MaintainerModel(AbstractDateTimeModel):
 class HerdsModel(AbstractDateTimeModel):
 
     def __init__(self, *args, **kwargs):
-        herd = None
-        if 'herd' in kwargs:
-            herd = kwargs['herd']
-            del kwargs['herd']
+        herd = get_from_kwargs_and_del('herd', kwargs)
         super(HerdsModel, self).__init__(*args, **kwargs)
         if herd is not None:
             self.init_by_herd(herd)
@@ -106,20 +100,11 @@ class HerdsModel(AbstractDateTimeModel):
 
 class PackageModel(AbstractDateTimeModel):
     def __init__(self, *args, **kwargs):
-        # TODO: Bad code, maybe use some library to overload method
-        package_object = None
-        if len(args)>=1:
-            package_object = args[0] 
+        package_object = get_from_kwargs_and_del('package', kwargs)
         
-        if 'package' in kwargs:
-            package_object = kwargs['package']
-            del kwargs['package']
-
+        super(PackageModel, self).__init__(*args, **kwargs)
         if isinstance(package_object, Package):
-            super(PackageModel, self).__init__(*args, **kwargs)
             self.init_by_package(package_object, category = kwargs.get('category'))
-        else:
-            super(PackageModel, self).__init__(*args, **kwargs)
             
         
 
@@ -221,7 +206,6 @@ class EbuildModel(AbstractDateTimeModel):
     is_deleted = models.BooleanField(default = False)
     is_masked = models.BooleanField(default = False)
 
-    #homepage = models.URLField(blank = True, null = True, max_length=255)
     homepages = models.ManyToManyField(HomepageModel, blank = True)
     description = models.TextField(blank = True, null = True)
 
@@ -233,12 +217,9 @@ class EbuildModel(AbstractDateTimeModel):
     objects = managers.EbuildManager()
 
     def __init__(self, *args, **kwargs ):
-        ebuild = None
-        if 'ebuild' in kwargs:
-            ebuild = kwargs['ebuild']
-            del kwargs['ebuild']
+        ebuild = get_from_kwargs_and_del('ebuild', kwargs)
         super(EbuildModel, self).__init__(*args, **kwargs)
-        if ebuild is not None and isinstance(ebuild, Ebuild):
+        if isinstance(ebuild, Ebuild):
             self.init_by_ebuild(ebuild)
     
     def __unicode__(self):

diff --git a/gpackages/libs/generic.py b/gpackages/libs/generic.py
index bc1cd55..0629ed6 100644
--- a/gpackages/libs/generic.py
+++ b/gpackages/libs/generic.py
@@ -1,10 +1,33 @@
 import os.path
 import hashlib
+import types
 from datetime import datetime
 
 __all__ = ('StrThatIgnoreCase', 'ToStrMixin', 'file_get_content', 'file_sha1', \
            'file_mtime', 'cached_property' )
 
+def del_from_dict(what_list, dict_todel):
+    for item in what_list:
+        if item in dict_todel:
+            del dict_todel[item]
+    #dict_todel already modified
+    return dict_todel
+
+def get_from_kwargs_and_del(list_what, kwargs):
+    ret_list = []
+    if isinstance(list_what, types.StringTypes):
+        list_what = (list_what, )
+    for item in list_what:
+        if item in kwargs:
+            ret_list.append(v)
+        else:
+            ret_list.append(None)
+    del_from_dict(ret_list, kwargs)
+    if len(ret_list)==1:
+        return ret_list[0]
+    else:
+        return ret_list
+            
 class StrThatIgnoreCase(unicode):
     __slots__ = ('_forcmp',)
 



^ permalink raw reply related	[flat|nested] 12+ messages in thread
* [gentoo-commits] proj/gentoo-packages:master commit in: gpackages/apps/packages/, gpackages/libs/
@ 2012-06-06 22:48 Slava Bacherikov
  0 siblings, 0 replies; 12+ messages in thread
From: Slava Bacherikov @ 2012-06-06 22:48 UTC (permalink / raw
  To: gentoo-commits

commit:     20ce0df8e5a4a3a08973f595a900ef6f5309b28e
Author:     Slava Bacherikov <slava <AT> bacher09 <DOT> org>
AuthorDate: Wed Jun  6 21:32:40 2012 +0000
Commit:     Slava Bacherikov <slava <AT> bacherikov <DOT> org <DOT> ua>
CommitDate: Wed Jun  6 21:32:40 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/gentoo-packages.git;a=commit;h=20ce0df8

Changes in portage layer

---
 gpackages/apps/packages/scan.py |    1 -
 gpackages/libs/generic.py       |    6 +++++-
 gpackages/libs/porttree.py      |   20 ++++++++++++++------
 3 files changed, 19 insertions(+), 8 deletions(-)

diff --git a/gpackages/apps/packages/scan.py b/gpackages/apps/packages/scan.py
index add62f1..f316900 100644
--- a/gpackages/apps/packages/scan.py
+++ b/gpackages/apps/packages/scan.py
@@ -330,7 +330,6 @@ def scanpackages(porttree, porttree_obj, delete = True, force_update = False):
             existend_packages.append(package_object.pk)
             if not package_created:
                 if package_object.check_or_need_update(package) or force_update:
-                    print package
                     # need update
                     update_package(package, package_object)
                 else:

diff --git a/gpackages/libs/generic.py b/gpackages/libs/generic.py
index c3d8d2b..bc1cd55 100644
--- a/gpackages/libs/generic.py
+++ b/gpackages/libs/generic.py
@@ -2,8 +2,12 @@ import os.path
 import hashlib
 from datetime import datetime
 
+__all__ = ('StrThatIgnoreCase', 'ToStrMixin', 'file_get_content', 'file_sha1', \
+           'file_mtime', 'cached_property' )
+
 class StrThatIgnoreCase(unicode):
-    
+    __slots__ = ('_forcmp',)
+
     def __init__(self, value):
         super(StrThatIgnoreCase, self).__init__(value)
         self._forcmp = value.lower()

diff --git a/gpackages/libs/porttree.py b/gpackages/libs/porttree.py
index 5b1dba8..dec4867 100644
--- a/gpackages/libs/porttree.py
+++ b/gpackages/libs/porttree.py
@@ -6,6 +6,7 @@ from portage.exception import PortageException, FileNotFound, InvalidAtom, \
 
 from gentoolkit.package import Package as PackageInfo
 from gentoolkit.metadata import MetaData
+from gentoolkit import errors
 from generic import ToStrMixin, file_sha1, file_mtime, cached_property, \
                     file_get_content, StrThatIgnoreCase
 from use_info import get_uses_info, get_local_uses_info
@@ -266,12 +267,9 @@ class Package(ToStrMixin):
         ebuilds = PORTDB.cp_list(self.package,
                                  mytree = self.category.porttree.porttree)
         for ebuild in ebuilds:
-            try:
-                PORTDB.aux_get(ebuild, [], mytree = self.category.porttree_path)
-            except KeyError:
-                pass
-            else:
-                yield Ebuild(self ,ebuild)
+            ebuild_obj = Ebuild(self, ebuild)
+            if ebuild_obj.is_valid:
+                yield ebuild_obj
 
     def __unicode__(self):
         return '%s' % self.package
@@ -345,6 +343,16 @@ class Ebuild(ToStrMixin):
         return self.package_object.environment("KEYWORDS", prefer_vdb = False)
 
     @property
+    def is_valid(self):
+        try:
+            self.package_object.environment("EAPI")
+        except errors.GentoolkitFatalError:
+            return False
+        else:
+            return True
+
+
+    @property
     def keywords(self):
         return list(set(self.keywords_env.split()))
     



^ permalink raw reply related	[flat|nested] 12+ messages in thread
* [gentoo-commits] proj/gentoo-packages:master commit in: gpackages/apps/packages/, gpackages/libs/
@ 2012-06-05 20:48 Slava Bacherikov
  0 siblings, 0 replies; 12+ messages in thread
From: Slava Bacherikov @ 2012-06-05 20:48 UTC (permalink / raw
  To: gentoo-commits

commit:     64493ae1a1c10570ef032a5515c8fbc072b8e65a
Author:     Slava Bacherikov <slava <AT> bacher09 <DOT> org>
AuthorDate: Tue Jun  5 20:06:25 2012 +0000
Commit:     Slava Bacherikov <slava <AT> bacherikov <DOT> org <DOT> ua>
CommitDate: Tue Jun  5 20:06:25 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/gentoo-packages.git;a=commit;h=64493ae1

Add saving description from metadata

---
 gpackages/apps/packages/models.py |    3 +++
 gpackages/libs/porttree.py        |   11 +++++++++++
 2 files changed, 14 insertions(+), 0 deletions(-)

diff --git a/gpackages/apps/packages/models.py b/gpackages/apps/packages/models.py
index fd36098..90665bd 100644
--- a/gpackages/apps/packages/models.py
+++ b/gpackages/apps/packages/models.py
@@ -146,6 +146,8 @@ class PackageModel(AbstractDateTimeModel):
 
     herds = models.ManyToManyField(HerdsModel, blank = True)
     maintainers = models.ManyToManyField(MaintainerModel, blank = True)
+
+    description = models.TextField(blank = True, null = True)
     # Different versions can have different licenses, or homepages.
     
     objects = managers.PackageManager()
@@ -183,6 +185,7 @@ class PackageModel(AbstractDateTimeModel):
         self.manifest_mtime = package.manifest_mtime
         self.manifest_hash = package.manifest_sha1
         self.metadata_hash = package.metadata_sha1
+        self.description = package.description
 
     class Meta:
         unique_together = ('name', 'category')

diff --git a/gpackages/libs/porttree.py b/gpackages/libs/porttree.py
index e4a3359..fe2c9cf 100644
--- a/gpackages/libs/porttree.py
+++ b/gpackages/libs/porttree.py
@@ -223,6 +223,17 @@ class Package(ToStrMixin):
     metadata_mtime = property(_file_mtime("metadata_path"))
 
     @cached_property
+    def descriptions(self):
+        return self.metadata.descriptions()
+
+    @property
+    def description(self):
+        if len(self.descriptions)>0:
+            return self.descriptions[0]
+        else:
+            return None
+
+    @cached_property
     def changelog(self):
         return open(self.changelog_path,'r').read()
 



^ permalink raw reply related	[flat|nested] 12+ messages in thread
* [gentoo-commits] proj/gentoo-packages:master commit in: gpackages/apps/packages/, gpackages/libs/
@ 2012-06-03 19:34 Slava Bacherikov
  0 siblings, 0 replies; 12+ messages in thread
From: Slava Bacherikov @ 2012-06-03 19:34 UTC (permalink / raw
  To: gentoo-commits

commit:     98a85554f37151983f7cd70da08889a90d0b7ab0
Author:     Slava Bacherikov <slava <AT> bacher09 <DOT> org>
AuthorDate: Sun Jun  3 16:56:26 2012 +0000
Commit:     Slava Bacherikov <slava <AT> bacherikov <DOT> org <DOT> ua>
CommitDate: Sun Jun  3 16:56:26 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/gentoo-packages.git;a=commit;h=98a85554

Save chagnelog to database.

---
 gpackages/apps/packages/models.py |    5 +++--
 gpackages/libs/porttree.py        |   12 +++++++++++-
 2 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/gpackages/apps/packages/models.py b/gpackages/apps/packages/models.py
index 0fc1dc0..cf1cf1b 100644
--- a/gpackages/apps/packages/models.py
+++ b/gpackages/apps/packages/models.py
@@ -141,6 +141,7 @@ class PackageModel(models.Model):
     def update_info(self, package):
         self.mtime = package.mtime
         self.changelog_mtime = package.changelog_mtime
+        self.changelog = package.changelog
         self.changelog_hash = package.changelog_sha1
         self.manifest_mtime = package.manifest_mtime
         self.manifest_hash = package.manifest_sha1
@@ -181,8 +182,8 @@ class EbuildModel(models.Model):
     homepages = models.ManyToManyField(HomepageModel, blank = True)
     description = models.TextField(blank = True, null = True)
 
-    eapi = models.PositiveSmallIntegerField(default = 0)
-    slot = models.PositiveSmallIntegerField(default = 0)
+    #eapi = models.PositiveSmallIntegerField(default = 0)
+    #slot = models.PositiveSmallIntegerField(default = 0)
 
     
 

diff --git a/gpackages/libs/porttree.py b/gpackages/libs/porttree.py
index 8bee3dd..e1a7dcc 100644
--- a/gpackages/libs/porttree.py
+++ b/gpackages/libs/porttree.py
@@ -161,12 +161,13 @@ class Category(ToStrMixin):
 
 class Package(ToStrMixin):
 
-    __slots__ = ('category', 'package', '_metadata')
+    __slots__ = ('category', 'package', '_metadata', '_changelog')
 
     def __init__(self, category, package):
         self.category = category
         self.package = package
         self._metadata = None
+        self._changelog = None
 
     def iter_ebuilds(self):
         ebuilds = PORTDB.cp_list(self.package, mytree=self.category.porttree.porttree)
@@ -205,6 +206,13 @@ class Package(ToStrMixin):
     changelog_mtime = property(_file_mtime("changelog_path"))
     metadata_mtime = property(_file_mtime("metadata_path"))
 
+    @property
+    def changelog(self):
+        if self._changelog is not None:
+            return self._changelog
+        self._changelog = open(self.changelog_path,'r').read()
+        return self._changelog
+
 
 class Ebuild(ToStrMixin):
 
@@ -272,6 +280,8 @@ class Ebuild(ToStrMixin):
     homepage_val = property(_ebuild_environment('HOMEPAGE'))
     license = property(_ebuild_environment('LICENSE'))
     description = property(_ebuild_environment('DESCRIPTION'))
+    eapi = property(_ebuild_environment('EAPI'))
+    slot = property(_ebuild_environment('SLOT'))
 
     @property
     def homepages(self):



^ permalink raw reply related	[flat|nested] 12+ messages in thread
* [gentoo-commits] proj/gentoo-packages:master commit in: gpackages/apps/packages/, gpackages/libs/
@ 2012-05-29 21:34 Slava Bacherikov
  0 siblings, 0 replies; 12+ messages in thread
From: Slava Bacherikov @ 2012-05-29 21:34 UTC (permalink / raw
  To: gentoo-commits

commit:     e3f7b8cb4d32e221c64ec361032d76d58a261588
Author:     Slava Bacherikov <slava <AT> bacher09 <DOT> org>
AuthorDate: Tue May 29 14:47:59 2012 +0000
Commit:     Slava Bacherikov <slava <AT> bacherikov <DOT> org <DOT> ua>
CommitDate: Tue May 29 14:47:59 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/gentoo-packages.git;a=commit;h=e3f7b8cb

Changes in keywords.

---
 gpackages/apps/packages/managers.py |    2 +-
 gpackages/apps/packages/models.py   |   17 ++++++++++++-----
 gpackages/libs/porttree.py          |   15 ++++++++++-----
 3 files changed, 23 insertions(+), 11 deletions(-)

diff --git a/gpackages/apps/packages/managers.py b/gpackages/apps/packages/managers.py
index dd9c2cb..a9b514b 100644
--- a/gpackages/apps/packages/managers.py
+++ b/gpackages/apps/packages/managers.py
@@ -35,7 +35,7 @@ class KeywordMixin(object):
         if keyword is not None:
             if isinstance(keyword, Keyword):
                 arch, created = packages.models.ArchesModel.objects.get_or_create(name = keyword.name)
-                kwargs.update({'arch': arch, 'is_stable': keyword.is_stable })
+                kwargs.update({'arch': arch, 'status': keyword.status})
             else:
                 raise ValueError("Bad keyword object")
 

diff --git a/gpackages/apps/packages/models.py b/gpackages/apps/packages/models.py
index 1d2fbe7..0ef5e8c 100644
--- a/gpackages/apps/packages/models.py
+++ b/gpackages/apps/packages/models.py
@@ -97,8 +97,8 @@ class LicensModel(models.Model):
 class EbuildModel(models.Model):
     package = models.ForeignKey(PackageModel)
     #repository = models.ForeignKey(RepositoryModel)
-    version = models.CharField(max_length = 16)
-    revision = models.CharField(max_length = 6)
+    version = models.CharField(max_length = 26)
+    revision = models.CharField(max_length = 12)
     use_flags = models.ManyToManyField(UseFlagModel)
     licenses = models.ManyToManyField(LicensModel)
     license = models.CharField(max_length = 254, blank = True )
@@ -168,14 +168,21 @@ class EbuildModel(models.Model):
             
 
 class Keyword(models.Model):
+    STATUS_CHOICES = (
+        (0, 'STABLE'),
+        (1, 'NEED TESTING'),
+        (2, 'NOT WORK')
+    )
+    status_repr = ['','~','-']
+
     ebuild = models.ForeignKey(EbuildModel)
     arch = models.ForeignKey(ArchesModel)
-    is_stable = models.BooleanField() 
+    status = models.PositiveSmallIntegerField(choices = STATUS_CHOICES)
 
     objects = managers.KeywordManager()
 
     def __unicode__(self):
-        return ('' if self.is_stable else '~' ) + str(self.arch)
+        return self.status_repr[self.status] + str(self.arch)
         
 
     def init_by_keyword(self, keyword, ebuild):
@@ -184,7 +191,7 @@ class Keyword(models.Model):
         elif isinstance(ebuild, Ebuild):
             self.ebuild, created = EbuildModel.objects.get_or_create(ebuild = ebuild)
         self.arch, created = ArchesModel.objects.get_or_create(name = keyword.name)
-        self.is_stable = keyword.is_stable
+        self.status = keyword.status
 
     class Meta:
         unique_together = ('ebuild', 'arch')

diff --git a/gpackages/libs/porttree.py b/gpackages/libs/porttree.py
index 475a642..c50b74d 100644
--- a/gpackages/libs/porttree.py
+++ b/gpackages/libs/porttree.py
@@ -53,15 +53,20 @@ class Use(ToStrMixin):
 
 
 class Keyword(ToStrMixin):
-    def __init__(self, name, is_stable = True):
-        if name[0] == '~':
+    status_repr = ['','~','-']
+    
+    def __init__(self, name, status = 0):
+        if name.startswith('~'):
+            name = name[1:]
+            status = 1
+        elif name.startswith('-'):
             name = name[1:]
-            is_stable = False
+            status = 2
         self.name = name
-        self.is_stable = is_stable
+        self.status = status
 
     def __unicode__(self):
-        return ('' if self.is_stable else '~' ) + self.name
+        return self.status_repr[self.status] + self.name
 
 
 class Portage(object):



^ permalink raw reply related	[flat|nested] 12+ messages in thread
* [gentoo-commits] proj/gentoo-packages:master commit in: gpackages/apps/packages/, gpackages/libs/
@ 2012-05-28 20:32 Slava Bacherikov
  0 siblings, 0 replies; 12+ messages in thread
From: Slava Bacherikov @ 2012-05-28 20:32 UTC (permalink / raw
  To: gentoo-commits

commit:     8a6ae647b2bf7e66d842151933817f6383e73255
Author:     Slava Bacherikov <slava <AT> bacher09 <DOT> org>
AuthorDate: Mon May 28 20:32:20 2012 +0000
Commit:     Slava Bacherikov <slava <AT> bacherikov <DOT> org <DOT> ua>
CommitDate: Mon May 28 20:32:20 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/gentoo-packages.git;a=commit;h=8a6ae647

Update models

---
 gpackages/apps/packages/managers.py |   21 ++++++++++++++++++++-
 gpackages/apps/packages/models.py   |   34 +++++++++++++++++++++++++++++++---
 gpackages/libs/porttree.py          |    4 ++--
 3 files changed, 53 insertions(+), 6 deletions(-)

diff --git a/gpackages/apps/packages/managers.py b/gpackages/apps/packages/managers.py
index f44ee34..ec3a55b 100644
--- a/gpackages/apps/packages/managers.py
+++ b/gpackages/apps/packages/managers.py
@@ -1,5 +1,5 @@
 from django.db import models
-from porttree import Category, Package
+from porttree import Category, Package, Ebuild, Keyword
 import packages.models
 
 
@@ -26,3 +26,22 @@ class PackageQuerySet(PackageMixin, models.query.QuerySet):
 class PackageManager(PackageMixin, models.Manager):
     def get_query_set(self):
         return PackageQuerySet(self.model, using=self._db)
+
+
+class KeywordMixin(object):
+    def get_or_create(self, keyword=None,  **kwargs):
+        if keyword is not None:
+            if isinstance(keyword, Keyword):
+                arch, created = packages.models.ArchesModel.objects.get_or_create(name = keyword.name)
+                kwargs.update({'arch': arch, 'is_stable': keyword.is_stable })
+            else:
+                raise ValueError("Bad keyword object")
+
+        return super(KeywordMixin, self).get_or_create(**kwargs)
+
+class KeywordQuerySet(KeywordMixin, models.query.QuerySet):
+    pass
+
+class KeywordManager(KeywordMixin, models.Manager):
+    def get_query_set(self):
+        return KeywordQuerySet(self.model, using=self._db)

diff --git a/gpackages/apps/packages/models.py b/gpackages/apps/packages/models.py
index 8e50eea..2cf377c 100644
--- a/gpackages/apps/packages/models.py
+++ b/gpackages/apps/packages/models.py
@@ -1,10 +1,13 @@
 from django.db import models
 
-from porttree import Category, Package
+from porttree import Category, Package, Ebuild
 import managers
 
 class ArchesModel(models.Model):
-    name = models.CharField(max_length = 12)
+    name = models.CharField(unique = True, max_length = 12)
+    
+    def __unicode__(self):
+        return self.name
 
 class RepositoryModel(models.Model):
     name = models.CharField(max_length = 60)
@@ -133,7 +136,17 @@ class EbuildModel(models.Model):
                 k.save()
             l.append(k)
         self.use_flags.add(*l)
-    
+
+    def init_with_keywords(self, ebuild):
+        self.init_by_ebuild(ebuild)
+        l = []
+        for keyword in ebuild.iter_keywords():
+            ko, created = Keyword.objects.get_or_create(keyword = keyword, ebuild = self)
+            if created:
+                ko.save()
+            l.append(ko)
+        self.keyword_set.add(*l)
+
     class Meta:
         unique_together = ('package', 'version', 'revision')
         
@@ -143,5 +156,20 @@ class Keyword(models.Model):
     ebuild = models.ForeignKey(EbuildModel)
     arch = models.ForeignKey(ArchesModel)
     is_stable = models.BooleanField() 
+
+    objects = managers.KeywordManager()
+
+    def __unicode__(self):
+        return ('' if self.is_stable else '~' ) + self.arch
+        
+
+    def init_by_keyword(self, keyword, ebuild):
+        if isinstance(ebuild, EbuildModel):
+            self.ebuild = ebuild
+        elif isinstance(ebuild, Ebuild):
+            self.ebuild, created = EbuildModel.objects.get_or_create(ebuild = ebuild)
+        self.arch, created = ArchesModel.objects.get_or_create(name = keyword.name)
+        self.is_stable = keyword.is_stable
+
     class Meta:
         unique_together = ('ebuild', 'arch')

diff --git a/gpackages/libs/porttree.py b/gpackages/libs/porttree.py
index a2ff2a1..96cbe0b 100644
--- a/gpackages/libs/porttree.py
+++ b/gpackages/libs/porttree.py
@@ -53,7 +53,7 @@ class Use(ToStrMixin):
 
 
 class Keyword(ToStrMixin):
-    def __init__(self, name, is_stable = False):
+    def __init__(self, name, is_stable = True):
         if name[0] == '~':
             name = name[1:]
             is_stable = False
@@ -162,7 +162,7 @@ class Ebuild(ToStrMixin):
         self.ebuild = ebuild
         self.package_object = PackageInfo(ebuild)
     
-    def iter_keyworkds(self):
+    def iter_keywords(self):
         keywords = self.package_object.environment("KEYWORDS").split()
         for keyword in keywords:
             yield Keyword(keyword)



^ permalink raw reply related	[flat|nested] 12+ messages in thread
* [gentoo-commits] proj/gentoo-packages:master commit in: gpackages/apps/packages/, gpackages/libs/
@ 2012-05-28 17:00 Slava Bacherikov
  0 siblings, 0 replies; 12+ messages in thread
From: Slava Bacherikov @ 2012-05-28 17:00 UTC (permalink / raw
  To: gentoo-commits

commit:     689267e951f72b3df1266d201ef22ff46dfb32ec
Author:     Slava Bacherikov <slava <AT> bacher09 <DOT> org>
AuthorDate: Mon May 28 13:08:14 2012 +0000
Commit:     Slava Bacherikov <slava <AT> bacherikov <DOT> org <DOT> ua>
CommitDate: Mon May 28 13:08:14 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/gentoo-packages.git;a=commit;h=689267e9

Wrtie convertion to unicode methods.

---
 gpackages/apps/packages/models.py |    2 +
 gpackages/libs/porttree.py        |   48 ++++++++++++++++++++-----------------
 2 files changed, 28 insertions(+), 22 deletions(-)

diff --git a/gpackages/apps/packages/models.py b/gpackages/apps/packages/models.py
index ce05e2c..b620dcb 100644
--- a/gpackages/apps/packages/models.py
+++ b/gpackages/apps/packages/models.py
@@ -18,6 +18,8 @@ class CategoryModel(models.Model):
             category_object = args[0]
         if 'category_object' in kwargs:
             category_object = kwargs['category_object']
+        elif 'category' in kwargs:
+            category_object = kwargs['category']
         
         if isinstance(category_object, Category):
             return super(CategoryModel, self).__init__(category = category_object.category)

diff --git a/gpackages/libs/porttree.py b/gpackages/libs/porttree.py
index 3151b78..c10995f 100644
--- a/gpackages/libs/porttree.py
+++ b/gpackages/libs/porttree.py
@@ -35,19 +35,24 @@ def file_sha1(file_path):
     return sha1
 
 
-class Use(object):
+class ToStrMixin(object):
+    def __str__(self):
+        return unicode(self).encode('utf-8')
+
+    def __repr__(self):
+        return '<%s %s>' % (type(self).__name__, self.__str__())
+
+class Use(ToStrMixin):
     def __init__(self, name):
         if name.startswith('+') or name.startswith('-'):
             name = name[1:]
         self.name = name
 
-    def __str__(self):
+    def __unicode__(self):
         return self.name
 
-    def __repr__(self):
-        return '<Use %s>' % self.__str__()
 
-class Keyword(object):
+class Keyword(ToStrMixin):
     def __init__(self, name, is_stable = False):
         if name[0] == '~':
             name = name[1:]
@@ -55,11 +60,9 @@ class Keyword(object):
         self.name = name
         self.is_stable = is_stable
 
-    def __str__(self):
+    def __unicode__(self):
         return ('' if self.is_stable else '~' ) + self.name
 
-    def __repr__(self):
-        return '<Keyword %s>' % self.__str__()
 
 class Portage(object):
     
@@ -73,7 +76,7 @@ class Portage(object):
                 yield ebuild
     
 
-class PortTree(object):
+class PortTree(ToStrMixin):
     
     def __init__(self, porttree = '/usr/portage'):
         self.porttree = porttree # TODO: it should be read-only
@@ -91,16 +94,16 @@ class PortTree(object):
         for package in self.iter_packages():
             for ebuild in package.iter_ebuilds():
                 yield ebuild
-    
-    def __repr__(self):
-        return '<PortTree %s>' % self.porttree
 
+    def __unicode__(self):
+        return self.porttree
+    
     @property
     def porttree_path(self):
         return self.porttree
 
 
-class Category(object):
+class Category(ToStrMixin):
     
     def __init__(self, porttree, category):
         self.porttree = porttree
@@ -117,16 +120,16 @@ class Category(object):
             if atom != atom.cp:
                 continue
             yield Package(self, atom)
-    
-    def __repr__(self):
-        return '<Category %s>' % self.category
 
+    def __unicode__(self):
+        return self.category
+    
     @property
     def category_path(self):
         return os.path.join(self.porttree.porttree_path, self.category)
 
 
-class Package(object):
+class Package(ToStrMixin):
     def __init__(self, category, package):
         self.category = category
         self.package = package
@@ -136,8 +139,8 @@ class Package(object):
         for ebuild in ebuilds:
             yield Ebuild(self ,ebuild)
 
-    def __repr__(self):
-        return '<Package %s>' % self.package
+    def __unicode__(self):
+        return '%s' % self.package
 
     @property
     def package_path(self):
@@ -149,7 +152,7 @@ class Package(object):
     changelog_sha1 = property(_file_hash('changelog_path'))
 
 
-class Ebuild(object):
+class Ebuild(ToStrMixin):
     def __init__(self, package, ebuild):
         self.package = package
         self.ebuild = ebuild
@@ -212,6 +215,7 @@ class Ebuild(object):
     @property
     def sha1(self):
         return file_sha1(self.ebuild_path)
+
+    def __unicode__(self):
+        return self.ebuild
     
-    def __repr__(self):
-        return '<Ebuild %s>' % self.ebuild



^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2012-06-18 21:26 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-06-05 15:49 [gentoo-commits] proj/gentoo-packages:master commit in: gpackages/apps/packages/, gpackages/libs/ Slava Bacherikov
  -- strict thread matches above, loose matches on Subject: below --
2012-06-18 21:26 Slava Bacherikov
2012-06-12 18:34 Slava Bacherikov
2012-06-12 18:34 Slava Bacherikov
2012-06-12 18:34 Slava Bacherikov
2012-06-07 22:48 Slava Bacherikov
2012-06-06 22:48 Slava Bacherikov
2012-06-05 20:48 Slava Bacherikov
2012-06-03 19:34 Slava Bacherikov
2012-05-29 21:34 Slava Bacherikov
2012-05-28 20:32 Slava Bacherikov
2012-05-28 17:00 Slava Bacherikov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox