From 5add4ddfcc77ff2e6c6c9299a58aa231fd14418c Mon Sep 17 00:00:00 2001 From: Corentin Chary Date: Sat, 21 Jul 2012 07:36:06 +0200 Subject: [PATCH 1/2] djeuscan: helpers.py is actually unused Signed-off-by: Corentin Chary --- euscanwww/djeuscan/helpers.py | 108 ---------------------------------- 1 file changed, 108 deletions(-) delete mode 100644 euscanwww/djeuscan/helpers.py diff --git a/euscanwww/djeuscan/helpers.py b/euscanwww/djeuscan/helpers.py deleted file mode 100644 index f7a6b82..0000000 --- a/euscanwww/djeuscan/helpers.py +++ /dev/null @@ -1,108 +0,0 @@ -""" -djeuscan.helpers -""" - -from distutils.version import StrictVersion, LooseVersion - - -def xint(i): - """ - Tries to cast to int, fallbacks to 0 - """ - try: - return int(i) - except Exception: - return 0 - - -def select_related_last_versions(queryset): - queryset = queryset.select_related( - 'last_version_gentoo', - 'last_version_overlay', - 'last_version_upstream' - ) - - -def version_key(version): - version = version.version - try: - return StrictVersion(version) - # in case of abnormal version number, fall back to LooseVersion - except ValueError: - return LooseVersion(version) - - -def packages_from_names(data): - """ - Returns a list of Package objects from a string of names - """ - - from djeuscan.models import Package - - packages = [] - data = data.replace("\r", "") - - for pkg in data.split('\n'): - if '/' in pkg: - cat, pkg = pkg.split('/') - packages.extend(Package.objects.filter(category=cat, name=pkg)) - else: - packages.extend(Package.objects.filter(name=pkg)) - return packages - - -def rename_fields(vqs, fields): - ret = [] - for n in vqs: - for tr in fields: - if tr[0] in n: - n[tr[1]] = n[tr[0]] - del n[tr[0]] - ret.append(n) - return ret - - -class catch_and_return(object): - def __init__(self, err, response): - self.err = err - self.response = response - - def __call__(self, fn): - def wrapper(*args, **kwargs): - try: - return fn(*args, **kwargs) - except self.err: - return self.response - return wrapper - - -def get_account_categories(user): - from djeuscan.models import Package, CategoryAssociation - - # TODO: This is quite ugly - category_names = [obj.category for obj in - CategoryAssociation.objects.filter(user=user)] - return [c for c in Package.objects.categories() - if c["category"] in category_names] - - -def get_account_herds(user): - from djeuscan.models import Package, HerdAssociation - - ids = [obj.herd.pk for obj in - HerdAssociation.objects.filter(user=user)] - return Package.objects.herds(ids=ids) - - -def get_account_maintainers(user): - from djeuscan.models import Package, MaintainerAssociation - - ids = [obj.maintainer.pk for obj in - MaintainerAssociation.objects.filter(user=user)] - return Package.objects.maintainers(ids=ids) - - -def get_account_packages(user): - from djeuscan.models import PackageAssociation - return [obj.package for obj in - PackageAssociation.objects.filter(user=user)] From 65618e3056e843361ed420577283435bbacccfdb Mon Sep 17 00:00:00 2001 From: Corentin Chary Date: Sat, 21 Jul 2012 07:36:35 +0200 Subject: [PATCH 2/2] djeuscan: portage. can be used instead of PORTDB Signed-off-by: Corentin Chary --- euscanwww/djeuscan/processing/scan/scan_portage.py | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/euscanwww/djeuscan/processing/scan/scan_portage.py b/euscanwww/djeuscan/processing/scan/scan_portage.py index a30254e..79fa62a 100644 --- a/euscanwww/djeuscan/processing/scan/scan_portage.py +++ b/euscanwww/djeuscan/processing/scan/scan_portage.py @@ -13,9 +13,6 @@ from euscan.version import get_version_type from djeuscan.processing import FakeLogger from djeuscan.models import Package, Version, VersionLog -PORTDB = None - - class ScanPortage(object): def __init__(self, logger=None, no_log=False, purge_packages=False, purge_versions=False): @@ -24,10 +21,6 @@ class ScanPortage(object): self.purge_packages = purge_packages self.purge_versions = purge_versions - global PORTDB - if not PORTDB: # Lazy loading for portdb - PORTDB = portage.db[portage.root]["porttree"].dbapi - self.style = color_style() self._cache = {'packages': {}, 'versions': {}} @@ -231,7 +224,7 @@ class ScanPortage(object): package.category, package.name, ver, rev, slot, overlay ) - overlay_path = overlay_path or PORTDB.settings["PORTDIR"] + overlay_path = overlay_path or portage.settings["PORTDIR"] package_path = join(overlay_path, package.category, package.name) ebuild_path = join(package_path, "%s.ebuild" % cpv.split("/")[-1]) metadata_path = join(package_path, "metadata.xml")