From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pigeon.gentoo.org ([208.92.234.80] helo=lists.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.60) (envelope-from ) id 1SclVZ-0001n1-AU for garchives@archives.gentoo.org; Thu, 07 Jun 2012 22:48:49 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id D087FE068E; Thu, 7 Jun 2012 22:48:16 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id 9239AE068E for ; Thu, 7 Jun 2012 22:48:16 +0000 (UTC) Received: from hornbill.gentoo.org (hornbill.gentoo.org [94.100.119.163]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 37C141B4028 for ; Thu, 7 Jun 2012 22:48:15 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id A0F8EE5432 for ; Thu, 7 Jun 2012 22:48:13 +0000 (UTC) From: "Slava Bacherikov" To: gentoo-commits@lists.gentoo.org Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Slava Bacherikov" Message-ID: <1339097563.6bf1b245210d63a003efa22db88244a35cf0bfe0.bacher09@gentoo> Subject: [gentoo-commits] proj/gentoo-packages:master commit in: gpackages/apps/packages/, gpackages/libs/ X-VCS-Repository: proj/gentoo-packages X-VCS-Files: gpackages/apps/packages/managers.py gpackages/apps/packages/models.py gpackages/libs/generic.py X-VCS-Directories: gpackages/apps/packages/ gpackages/libs/ X-VCS-Committer: bacher09 X-VCS-Committer-Name: Slava Bacherikov X-VCS-Revision: 6bf1b245210d63a003efa22db88244a35cf0bfe0 X-VCS-Branch: master Date: Thu, 7 Jun 2012 22:48:13 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: quoted-printable X-Archives-Salt: 37237fc3-978a-493c-b7eb-b14c4fb7d7f4 X-Archives-Hash: b1836c89f01637fe0a1c4b1c06f370fc commit: 6bf1b245210d63a003efa22db88244a35cf0bfe0 Author: Slava Bacherikov bacher09 org> AuthorDate: Thu Jun 7 18:54:24 2012 +0000 Commit: Slava Bacherikov bacherikov org ua> CommitDate: Thu Jun 7 19:32:43 2012 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/gentoo-packag= es.git;a=3Dcommit;h=3D6bf1b245 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/package= s/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, Integrit= yError from porttree import Category, Package, Ebuild, Keyword import packages.models +from generic import get_from_kwargs_and_del =20 =20 def _gen_query_and_manager(MixinClass, QueryClassName, ManagerClassName)= : @@ -72,19 +73,17 @@ class EbuildMixin(object):#{{{ =20 class HerdsMixin(object):#{{{ def filter(self, *args, **kwargs): - if 'herd__in' in kwargs: - herds =3D kwargs['herd__in'] - del kwargs['herd__in'] - kwargs['name__in'] =3D herds + herd__in =3D get_from_kwargs_and_del('herd__in',kwargs) + if herd__in is not None: + kwargs['name__in'] =3D herd__in return super(HerdsMixin, self).filter(*args, **kwargs)#}}} =20 =20 class MaintainerMixin(object):#{{{ def filter(self, *args, **kwargs): - if 'maintainer__in' in kwargs: - maintars =3D kwargs['maintainer__in'] - del kwargs['maintainer__in'] - kwargs['email__in'] =3D maintars + maintainer__in =3D get_from_kwargs_and_del('maintainer__in', kwa= rgs) + if maintainer__in is not None: + kwargs['email__in'] =3D maintainer__in return super(MaintainerMixin, self).filter(*args, **kwargs)#}}} =20 =20 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 =20 from porttree import Category, Package, Ebuild import managers +from generic import get_from_kwargs_and_del =20 class AbstractDateTimeModel(models.Model): created_datetime =3D models.DateTimeField(auto_now_add =3D True) @@ -40,11 +41,7 @@ class CategoryModel(models.Model): class MaintainerModel(AbstractDateTimeModel): =20 def __init__(self, *args, **kwargs): - #TODO: Bad code, maybe use some libraries for overload methods - maintainer =3D None - if 'maintainer' in kwargs: - maintainer =3D kwargs['maintainer'] - del kwargs['maintainer'] + maintainer =3D 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): =20 def __init__(self, *args, **kwargs): - herd =3D None - if 'herd' in kwargs: - herd =3D kwargs['herd'] - del kwargs['herd'] + herd =3D 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): =20 class PackageModel(AbstractDateTimeModel): def __init__(self, *args, **kwargs): - # TODO: Bad code, maybe use some library to overload method - package_object =3D None - if len(args)>=3D1: - package_object =3D args[0]=20 + package_object =3D get_from_kwargs_and_del('package', kwargs) =20 - if 'package' in kwargs: - package_object =3D 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 =3D kwargs.get= ('category')) - else: - super(PackageModel, self).__init__(*args, **kwargs) =20 =20 =20 @@ -221,7 +206,6 @@ class EbuildModel(AbstractDateTimeModel): is_deleted =3D models.BooleanField(default =3D False) is_masked =3D models.BooleanField(default =3D False) =20 - #homepage =3D models.URLField(blank =3D True, null =3D True, max_len= gth=3D255) homepages =3D models.ManyToManyField(HomepageModel, blank =3D True) description =3D models.TextField(blank =3D True, null =3D True) =20 @@ -233,12 +217,9 @@ class EbuildModel(AbstractDateTimeModel): objects =3D managers.EbuildManager() =20 def __init__(self, *args, **kwargs ): - ebuild =3D None - if 'ebuild' in kwargs: - ebuild =3D kwargs['ebuild'] - del kwargs['ebuild'] + ebuild =3D 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) =20 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 =20 __all__ =3D ('StrThatIgnoreCase', 'ToStrMixin', 'file_get_content', 'fil= e_sha1', \ 'file_mtime', 'cached_property' ) =20 +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 =3D [] + if isinstance(list_what, types.StringTypes): + list_what =3D (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)=3D=3D1: + return ret_list[0] + else: + return ret_list + =20 class StrThatIgnoreCase(unicode): __slots__ =3D ('_forcmp',) =20