Merge lp:~dholbach/harvest/packagesets into lp:harvest

Proposed by Daniel Holbach
Status: Merged
Merged at revision: not available
Proposed branch: lp:~dholbach/harvest/packagesets
Merge into: lp:harvest
Prerequisite: lp:~dholbach/harvest/schema-changes
Diff against target: 276 lines (+136/-72)
8 files modified
INSTALL (+21/-61)
harvest/common/launchpad.py (+46/-0)
harvest/common/utils.py (+0/-9)
harvest/opportunities/management/commands/init-harvest.py (+24/-0)
harvest/opportunities/management/commands/updatepackagesets.py (+41/-0)
harvest/opportunities/models.py (+3/-0)
harvest/opportunities/views.py (+0/-2)
harvest/settings.py.sample (+1/-0)
To merge this branch: bzr merge lp:~dholbach/harvest/packagesets
Reviewer Review Type Date Requested Status
James Westby Approve
Paul Hummer Pending
Review via email: mp+18133@code.launchpad.net

This proposal supersedes a proposal from 2010-01-22.

To post a comment you must log in.
Revision history for this message
Paul Hummer (rockstar) wrote : Posted in a previous version of this proposal

=== added file 'harvest/common/launchpad.py'
--- harvest/common/launchpad.py 1970-01-01 00:00:00 +0000
+++ harvest/common/launchpad.py 2010-01-22 17:07:20 +0000
@@ -0,0 +1,38 @@
+from launchpadlib.launchpad import Launchpad, EDGE_SERVICE_ROOT
+from launchpadlib.credentials import Credentials
+from launchpadlib.errors import HTTPError
+
+from django.conf import settings
+
+import sys
+import os
+
+def lp_login(lp_instance=EDGE_SERVICE_ROOT):

A docstring here would be really helpful. Something like:

    """Return a logged in launchpad object."""

+ cachedir = os.path.join(settings.PROJECT_PATH, 'lp_data/cache')
+ creddir = os.path.join(settings.PROJECT_PATH, 'lp_data/lp_credentials')
+ project = settings.PROJECT_NAME.strip()
+ if not os.path.isdir(creddir):
+ os.makedirs(creddir)
+ cred = os.path.join(creddir, '%s.credentials' % project)
+
+ if os.path.exists(cred):
+ credentials = Credentials()
+ credentials.load(open(cred))
+ launchpad = Launchpad(credentials, lp_instance, cachedir)
+ else:
+ try:
+ launchpad = Launchpad.get_token_and_login(project, lp_instance,
+ cachedir)
+ except HTTPError, e:
+ print >> sys.stderr, 'Error connecting to Launchpad: %s' % str(e)
+ sys.exit(1)

It would be better to raise an exception here, instead of printing to standard error and exiting. Sometimes the e part of the except is rather unhelpful.

+ f = open(cred, 'w')
+ os.chmod(cred, 0600)
+ launchpad.credentials.save(f)
+ f.close()
+ return launchpad
+
+def get_packagesets(lp):
+ current_series = lp.distributions['ubuntu'].current_series
+ packagesets = filter(lambda a: a.distroseries == current_series, lp.packagesets)
+ return packagesets

=== modified file 'harvest/opportunities/models.py'
--- harvest/opportunities/models.py 2010-01-22 17:07:20 +0000
+++ harvest/opportunities/models.py 2010-01-22 17:07:20 +0000
@@ -7,9 +7,12 @@
 TYPE_GREEN_THRESHOLD = 200
 TYPE_RED_THRESHOLD = 1000

+class PackageSet(models.Model):
+ name = models.SlugField(_("Name"), max_length=40)

 class SourcePackage(models.Model):
     name = models.SlugField(_("Name"), max_length=70)
+ packagesets = models.ManyToManyField(PackageSet, null=True)

     class Meta:
         ordering = ['name']

So, by this model definition, is it safe to say that packages can be in many different package sets? Have you tested this at all? I think we need a property on packagesets that can link back to the SourcePackages as well.

Revision history for this message
Paul Hummer (rockstar) : Posted in a previous version of this proposal
review: Needs Information
Revision history for this message
Daniel Holbach (dholbach) wrote : Posted in a previous version of this proposal

On 26.01.2010 04:28, Paul Hummer wrote:
> A docstring here would be really helpful. Something like:
>
> """Return a logged in launchpad object."""

I'll have a look at that later on. Thanks. :)

> It would be better to raise an exception here, instead of printing to standard error and exiting. Sometimes the e part of the except is rather unhelpful.

Ok. I'll have a look and see what I can improve there.

> So, by this model definition, is it safe to say that packages can be in many different package sets? Have you tested this at all? I think we need a property on packagesets that can link back to the SourcePackages as well.

Have a look at http://people.canonical.com/~cjwatson/packagesets and
search for "mousepad", it ended up in various packagesets. It sure makes
our life more complicated, but it was deemed the best solution for the
reality we are facing.

Revision history for this message
Daniel Holbach (dholbach) wrote :

The only thing that's missing is the property for the packagesets that you mentioned. Do you think you can help with that?

Revision history for this message
Daniel Holbach (dholbach) wrote :

Just let me know what you think.

Revision history for this message
James Westby (james-w) wrote :

Looks ok to me.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'INSTALL'
--- INSTALL 2009-12-07 11:07:52 +0000
+++ INSTALL 2010-01-27 12:44:16 +0000
@@ -1,63 +1,23 @@
1To begin, we have two options to get started with harvest: first one is using sqlite3 and the other one is using postgres1
221. sudo apt-get install python-django python-launchpadlib python-django-openid-auth bzr
3First one is using sqlite3, this is probably the easier one:32. cd harvest; cp settings.py.sample settings.py
44
51. 5---
66Optional for postgres usage:
7sudo apt-get install python-django python-launchpadlib7 - sudo apt-get install postgresql-8.3 python-psycopg2
88 - Edit settings.py
9- install python-django-openid-auth from karmic or from:9 - set DATABASE_* according to the appropiate settings
10http://archive.ubuntu.com/ubuntu/pool/universe/p/python-django-openid-auth/10 - Not sure if necessary:
1111 - sudo passwd postgres
122. 12 change password to 'password' or whatever the password is in harvest/settings.py
1313 - sudo -u postgres psql template1
14- cd harvest14 ALTER USER postgres WITH ENCRYPTED PASSWORD 'password';
15- cp settings.py.sample settings.py15 - sudo -u postgres createdb -O postgres harvest
1616---
173. 17
18
19Now to edit settings.py
20
21set DATABASE_ENGINE = 'sqlite3'
22set DATABASE_NAME = 'dev.db'
23
244.
25
26- ./manage.py syncdb
27- ./manage.py compilemessages
28- ./manage.py updatelists
29- ./manage.py runserver
30
31--------------------------------------------------------------------------------------------------
32
33Second one is using postgres:
34
351.
36
37 - sudo apt-get install postgresql-8.3 python-django python-psycopg2 python-launchpadlib
38
392.
40
41 - cd harvest
42 - cp settings.py.sample settings.py
4318
443.193.
4520 - ./manage.py syncdb
46Edit settings.py21 - ./manage.py init-harvest
4722 - ./manage.py updatelists
48set SECRET_KEY, DATABASE_USER and DATABASE_PASSWORD according to the appropiate settings23 - ./manage.py runserver
49
50* Not sure if necessary
51
52- sudo passwd postgres
53change password to 'password' or whatever the password is in harvest/settings.py
54- sudo -u postgres psql template1
55ALTER USER postgres WITH ENCRYPTED PASSWORD 'password';
56- sudo -u postgres createdb -O postgres harvest
57
584.
59
60- ./manage.py syncdb
61- ./manage.py compilemessages
62- ./manage.py updatelists
63- ./manage.py runserver
6424
=== added file 'harvest/common/launchpad.py'
--- harvest/common/launchpad.py 1970-01-01 00:00:00 +0000
+++ harvest/common/launchpad.py 2010-01-27 12:44:16 +0000
@@ -0,0 +1,46 @@
1from launchpadlib.launchpad import Launchpad, EDGE_SERVICE_ROOT
2from launchpadlib.credentials import Credentials
3from launchpadlib.errors import HTTPError
4
5from django.conf import settings
6
7import sys
8import os
9
10def lp_login(lp_instance=EDGE_SERVICE_ROOT):
11 """
12 Return a logged in Launchpad object.
13
14 XXX: Once https://bugs.launchpad.net/soyuz/+bug/510180 is fixed we can
15 probably use "anonymous login" everywhere.
16 """
17 cachedir = os.path.join(settings.PROJECT_PATH, 'lp_data/cache')
18 creddir = os.path.join(settings.PROJECT_PATH, 'lp_data/lp_credentials')
19 project = settings.PROJECT_NAME.strip()
20 if not os.path.isdir(creddir):
21 os.makedirs(creddir)
22 cred = os.path.join(creddir, '%s.credentials' % project)
23
24 if os.path.exists(cred):
25 credentials = Credentials()
26 credentials.load(open(cred))
27 launchpad = Launchpad(credentials, lp_instance, cachedir)
28 else:
29 try:
30 launchpad = Launchpad.get_token_and_login(project, lp_instance,
31 cachedir)
32 except HTTPError as e:
33 raise 'Error connecting to Launchpad: %s' % str(e.value)
34 f = open(cred, 'w')
35 os.chmod(cred, 0600)
36 launchpad.credentials.save(f)
37 f.close()
38 return launchpad
39
40def get_packagesets(lp):
41 """
42 Get list of packagesets for current development release of Ubuntu.
43 """
44 current_series = lp.distributions['ubuntu'].current_series
45 packagesets = filter(lambda a: a.distroseries == current_series, lp.packagesets)
46 return packagesets
047
=== removed file 'harvest/common/utils.py'
--- harvest/common/utils.py 2009-07-08 11:31:32 +0000
+++ harvest/common/utils.py 1970-01-01 00:00:00 +0000
@@ -1,9 +0,0 @@
1from django.utils.translation import ugettext as _
2
3def trans_sort_object_list(lst, tr_field):
4 """ Sort an object list with translated_name """
5 for l in lst:
6 l.translated_name = _(getattr(l, tr_field))
7 templist = [(obj_.translated_name.lower(), obj_) for obj_ in lst]
8 templist.sort()
9 return [obj_ for (key1, obj_) in templist]
100
=== added file 'harvest/opportunities/management/commands/init-harvest.py'
--- harvest/opportunities/management/commands/init-harvest.py 1970-01-01 00:00:00 +0000
+++ harvest/opportunities/management/commands/init-harvest.py 2010-01-27 12:44:16 +0000
@@ -0,0 +1,24 @@
1#!/usr/bin/python
2
3from django.core.management.base import NoArgsCommand
4
5import settings
6
7import subprocess
8import os
9
10class Command(NoArgsCommand):
11 help = "Make sure Harvest is set up properly."
12
13 def handle_noargs(self, **options):
14 print " * Compiling messages."
15 subprocess.call(["./manage.py", "compilemessages"])
16
17 path = settings.PROJECT_PATH
18
19 if os.path.exists(os.path.join(path, "settings.py.sample")) and \
20 os.path.exists(os.path.join(path, "settings.py")):
21 print " * Showing diff between settings.py.sample and settings.py."
22 subprocess.call(["diff", "-u",
23 os.path.join(path, "settings.py.sample"),
24 os.path.join(path, "settings.py")])
025
=== added file 'harvest/opportunities/management/commands/updatepackagesets.py'
--- harvest/opportunities/management/commands/updatepackagesets.py 1970-01-01 00:00:00 +0000
+++ harvest/opportunities/management/commands/updatepackagesets.py 2010-01-27 12:44:16 +0000
@@ -0,0 +1,41 @@
1#!/usr/bin/python
2
3from django.core.management.base import NoArgsCommand
4
5from common import launchpad
6from opportunities.models import SourcePackage, PackageSet
7
8import sys
9
10class Command(NoArgsCommand):
11 help = "Pull packageset information from Launchpad."
12
13 def handle_noargs(self, **options):
14 lp = launchpad.lp_login()
15 if not lp:
16 sys.exit(1)
17 lp_packagesets = launchpad.get_packagesets(lp)
18 package_mapping = {}
19 for lp_packageset in lp_packagesets:
20 packageset, created = PackageSet.objects.get_or_create(name=lp_packageset.name)
21 if created:
22 packageset.save()
23 for package_name in lp_packageset.getSourcesIncluded():
24 if not package_mapping.has_key(package_name):
25 package_mapping[package_name] = set()
26 package_mapping[package_name].add((lp_packageset.name))
27 for package_name in package_mapping.keys():
28 try:
29 package = SourcePackage.objects.get(name=package_name)
30 except SourcePackage.DoesNotExist:
31 package = None
32 if package:
33 for packageset_name in package_mapping[package_name]:
34 try:
35 package.packagesets.get(name=packageset_name)
36 except PackageSet.DoesNotExist:
37 package.packagesets.add(PackageSet.objects.get(name=packageset_name))
38 for packageset in package.packagesets.all():
39 if packageset.name not in package_mapping[package_name]:
40 package.packagesets.delete(PackageSet.objects.get(name=packageset))
41 package.save()
042
=== modified file 'harvest/opportunities/models.py'
--- harvest/opportunities/models.py 2010-01-15 11:49:19 +0000
+++ harvest/opportunities/models.py 2010-01-27 12:44:16 +0000
@@ -7,9 +7,12 @@
7TYPE_GREEN_THRESHOLD = 2007TYPE_GREEN_THRESHOLD = 200
8TYPE_RED_THRESHOLD = 10008TYPE_RED_THRESHOLD = 1000
99
10class PackageSet(models.Model):
11 name = models.SlugField(_("Name"), max_length=40)
1012
11class SourcePackage(models.Model):13class SourcePackage(models.Model):
12 name = models.SlugField(_("Name"), max_length=70)14 name = models.SlugField(_("Name"), max_length=70)
15 packagesets = models.ManyToManyField(PackageSet, null=True)
1316
14 class Meta:17 class Meta:
15 ordering = ['name']18 ordering = ['name']
1619
=== modified file 'harvest/opportunities/views.py'
--- harvest/opportunities/views.py 2010-01-05 01:39:53 +0000
+++ harvest/opportunities/views.py 2010-01-27 12:44:16 +0000
@@ -1,6 +1,5 @@
1from django.core.paginator import Paginator, InvalidPage, EmptyPage1from django.core.paginator import Paginator, InvalidPage, EmptyPage
2from django.db.models import Count2from django.db.models import Count
3from django.http import HttpResponse
4from django.shortcuts import get_object_or_4043from django.shortcuts import get_object_or_404
5from django.shortcuts import render_to_response as render4from django.shortcuts import render_to_response as render
65
@@ -8,7 +7,6 @@
8from django.views.generic import list_detail7from django.views.generic import list_detail
98
10import models9import models
11from common import utils
1210
13def opportunity_index(request):11def opportunity_index(request):
14 sources_list = models.SourcePackage.objects.all()12 sources_list = models.SourcePackage.objects.all()
1513
=== modified file 'harvest/settings.py.sample'
--- harvest/settings.py.sample 2010-01-22 16:49:24 +0000
+++ harvest/settings.py.sample 2010-01-27 12:44:16 +0000
@@ -6,6 +6,7 @@
6DEBUG = True6DEBUG = True
7TEMPLATE_DEBUG = DEBUG7TEMPLATE_DEBUG = DEBUG
8STATIC_SERVE = True8STATIC_SERVE = True
9PROJECT_NAME = 'harvest'
910
10ADMINS = ('Daniel Holbach', 'daniel.holbach@ubuntu.com')11ADMINS = ('Daniel Holbach', 'daniel.holbach@ubuntu.com')
11MANAGERS = ADMINS12MANAGERS = ADMINS

Subscribers

People subscribed via source and target branches

to all changes: