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

Proposed by Daniel Holbach
Status: Superseded
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
Paul Hummer (community) Needs Information
harvest-dev Pending
Review via email: mp+17900@code.launchpad.net

This proposal has been superseded by a proposal from 2010-01-27.

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

=== 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) :
review: Needs Information
Revision history for this message
Daniel Holbach (dholbach) wrote :

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.

lp:~dholbach/harvest/packagesets updated
159. By Daniel Holbach

add docstrings, raise exception

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'INSTALL'
2--- INSTALL 2009-12-07 11:07:52 +0000
3+++ INSTALL 2010-01-27 12:37:10 +0000
4@@ -1,63 +1,23 @@
5-To begin, we have two options to get started with harvest: first one is using sqlite3 and the other one is using postgres
6-
7-First one is using sqlite3, this is probably the easier one:
8-
9-1.
10-
11-sudo apt-get install python-django python-launchpadlib
12-
13-- install python-django-openid-auth from karmic or from:
14-http://archive.ubuntu.com/ubuntu/pool/universe/p/python-django-openid-auth/
15-
16-2.
17-
18-- cd harvest
19-- cp settings.py.sample settings.py
20-
21-3.
22-
23-Now to edit settings.py
24-
25-set DATABASE_ENGINE = 'sqlite3'
26-set DATABASE_NAME = 'dev.db'
27-
28-4.
29-
30-- ./manage.py syncdb
31-- ./manage.py compilemessages
32-- ./manage.py updatelists
33-- ./manage.py runserver
34-
35---------------------------------------------------------------------------------------------------
36-
37-Second one is using postgres:
38-
39-1.
40-
41- - sudo apt-get install postgresql-8.3 python-django python-psycopg2 python-launchpadlib
42-
43-2.
44-
45- - cd harvest
46- - cp settings.py.sample settings.py
47+
48+1. sudo apt-get install python-django python-launchpadlib python-django-openid-auth bzr
49+2. cd harvest; cp settings.py.sample settings.py
50+
51+---
52+Optional for postgres usage:
53+ - sudo apt-get install postgresql-8.3 python-psycopg2
54+ - Edit settings.py
55+ - set DATABASE_* according to the appropiate settings
56+ - Not sure if necessary:
57+ - sudo passwd postgres
58+ change password to 'password' or whatever the password is in harvest/settings.py
59+ - sudo -u postgres psql template1
60+ ALTER USER postgres WITH ENCRYPTED PASSWORD 'password';
61+ - sudo -u postgres createdb -O postgres harvest
62+---
63+
64
65 3.
66-
67-Edit settings.py
68-
69-set SECRET_KEY, DATABASE_USER and DATABASE_PASSWORD according to the appropiate settings
70-
71-* Not sure if necessary
72-
73-- sudo passwd postgres
74-change password to 'password' or whatever the password is in harvest/settings.py
75-- sudo -u postgres psql template1
76-ALTER USER postgres WITH ENCRYPTED PASSWORD 'password';
77-- sudo -u postgres createdb -O postgres harvest
78-
79-4.
80-
81-- ./manage.py syncdb
82-- ./manage.py compilemessages
83-- ./manage.py updatelists
84-- ./manage.py runserver
85+ - ./manage.py syncdb
86+ - ./manage.py init-harvest
87+ - ./manage.py updatelists
88+ - ./manage.py runserver
89
90=== added file 'harvest/common/launchpad.py'
91--- harvest/common/launchpad.py 1970-01-01 00:00:00 +0000
92+++ harvest/common/launchpad.py 2010-01-27 12:37:10 +0000
93@@ -0,0 +1,46 @@
94+from launchpadlib.launchpad import Launchpad, EDGE_SERVICE_ROOT
95+from launchpadlib.credentials import Credentials
96+from launchpadlib.errors import HTTPError
97+
98+from django.conf import settings
99+
100+import sys
101+import os
102+
103+def lp_login(lp_instance=EDGE_SERVICE_ROOT):
104+ """
105+ Return a logged in Launchpad object.
106+
107+ XXX: Once https://bugs.launchpad.net/soyuz/+bug/510180 is fixed we can
108+ probably use "anonymous login" everywhere.
109+ """
110+ cachedir = os.path.join(settings.PROJECT_PATH, 'lp_data/cache')
111+ creddir = os.path.join(settings.PROJECT_PATH, 'lp_data/lp_credentials')
112+ project = settings.PROJECT_NAME.strip()
113+ if not os.path.isdir(creddir):
114+ os.makedirs(creddir)
115+ cred = os.path.join(creddir, '%s.credentials' % project)
116+
117+ if os.path.exists(cred):
118+ credentials = Credentials()
119+ credentials.load(open(cred))
120+ launchpad = Launchpad(credentials, lp_instance, cachedir)
121+ else:
122+ try:
123+ launchpad = Launchpad.get_token_and_login(project, lp_instance,
124+ cachedir)
125+ except HTTPError as e:
126+ raise 'Error connecting to Launchpad: %s' % str(e.value)
127+ f = open(cred, 'w')
128+ os.chmod(cred, 0600)
129+ launchpad.credentials.save(f)
130+ f.close()
131+ return launchpad
132+
133+def get_packagesets(lp):
134+ """
135+ Get list of packagesets for current development release of Ubuntu.
136+ """
137+ current_series = lp.distributions['ubuntu'].current_series
138+ packagesets = filter(lambda a: a.distroseries == current_series, lp.packagesets)
139+ return packagesets
140
141=== removed file 'harvest/common/utils.py'
142--- harvest/common/utils.py 2009-07-08 11:31:32 +0000
143+++ harvest/common/utils.py 1970-01-01 00:00:00 +0000
144@@ -1,9 +0,0 @@
145-from django.utils.translation import ugettext as _
146-
147-def trans_sort_object_list(lst, tr_field):
148- """ Sort an object list with translated_name """
149- for l in lst:
150- l.translated_name = _(getattr(l, tr_field))
151- templist = [(obj_.translated_name.lower(), obj_) for obj_ in lst]
152- templist.sort()
153- return [obj_ for (key1, obj_) in templist]
154
155=== added file 'harvest/opportunities/management/commands/init-harvest.py'
156--- harvest/opportunities/management/commands/init-harvest.py 1970-01-01 00:00:00 +0000
157+++ harvest/opportunities/management/commands/init-harvest.py 2010-01-27 12:37:10 +0000
158@@ -0,0 +1,24 @@
159+#!/usr/bin/python
160+
161+from django.core.management.base import NoArgsCommand
162+
163+import settings
164+
165+import subprocess
166+import os
167+
168+class Command(NoArgsCommand):
169+ help = "Make sure Harvest is set up properly."
170+
171+ def handle_noargs(self, **options):
172+ print " * Compiling messages."
173+ subprocess.call(["./manage.py", "compilemessages"])
174+
175+ path = settings.PROJECT_PATH
176+
177+ if os.path.exists(os.path.join(path, "settings.py.sample")) and \
178+ os.path.exists(os.path.join(path, "settings.py")):
179+ print " * Showing diff between settings.py.sample and settings.py."
180+ subprocess.call(["diff", "-u",
181+ os.path.join(path, "settings.py.sample"),
182+ os.path.join(path, "settings.py")])
183
184=== added file 'harvest/opportunities/management/commands/updatepackagesets.py'
185--- harvest/opportunities/management/commands/updatepackagesets.py 1970-01-01 00:00:00 +0000
186+++ harvest/opportunities/management/commands/updatepackagesets.py 2010-01-27 12:37:10 +0000
187@@ -0,0 +1,41 @@
188+#!/usr/bin/python
189+
190+from django.core.management.base import NoArgsCommand
191+
192+from common import launchpad
193+from opportunities.models import SourcePackage, PackageSet
194+
195+import sys
196+
197+class Command(NoArgsCommand):
198+ help = "Pull packageset information from Launchpad."
199+
200+ def handle_noargs(self, **options):
201+ lp = launchpad.lp_login()
202+ if not lp:
203+ sys.exit(1)
204+ lp_packagesets = launchpad.get_packagesets(lp)
205+ package_mapping = {}
206+ for lp_packageset in lp_packagesets:
207+ packageset, created = PackageSet.objects.get_or_create(name=lp_packageset.name)
208+ if created:
209+ packageset.save()
210+ for package_name in lp_packageset.getSourcesIncluded():
211+ if not package_mapping.has_key(package_name):
212+ package_mapping[package_name] = set()
213+ package_mapping[package_name].add((lp_packageset.name))
214+ for package_name in package_mapping.keys():
215+ try:
216+ package = SourcePackage.objects.get(name=package_name)
217+ except SourcePackage.DoesNotExist:
218+ package = None
219+ if package:
220+ for packageset_name in package_mapping[package_name]:
221+ try:
222+ package.packagesets.get(name=packageset_name)
223+ except PackageSet.DoesNotExist:
224+ package.packagesets.add(PackageSet.objects.get(name=packageset_name))
225+ for packageset in package.packagesets.all():
226+ if packageset.name not in package_mapping[package_name]:
227+ package.packagesets.delete(PackageSet.objects.get(name=packageset))
228+ package.save()
229
230=== modified file 'harvest/opportunities/models.py'
231--- harvest/opportunities/models.py 2010-01-15 11:49:19 +0000
232+++ harvest/opportunities/models.py 2010-01-27 12:37:10 +0000
233@@ -7,9 +7,12 @@
234 TYPE_GREEN_THRESHOLD = 200
235 TYPE_RED_THRESHOLD = 1000
236
237+class PackageSet(models.Model):
238+ name = models.SlugField(_("Name"), max_length=40)
239
240 class SourcePackage(models.Model):
241 name = models.SlugField(_("Name"), max_length=70)
242+ packagesets = models.ManyToManyField(PackageSet, null=True)
243
244 class Meta:
245 ordering = ['name']
246
247=== modified file 'harvest/opportunities/views.py'
248--- harvest/opportunities/views.py 2010-01-05 01:39:53 +0000
249+++ harvest/opportunities/views.py 2010-01-27 12:37:10 +0000
250@@ -1,6 +1,5 @@
251 from django.core.paginator import Paginator, InvalidPage, EmptyPage
252 from django.db.models import Count
253-from django.http import HttpResponse
254 from django.shortcuts import get_object_or_404
255 from django.shortcuts import render_to_response as render
256
257@@ -8,7 +7,6 @@
258 from django.views.generic import list_detail
259
260 import models
261-from common import utils
262
263 def opportunity_index(request):
264 sources_list = models.SourcePackage.objects.all()
265
266=== modified file 'harvest/settings.py.sample'
267--- harvest/settings.py.sample 2010-01-22 16:49:24 +0000
268+++ harvest/settings.py.sample 2010-01-27 12:37:10 +0000
269@@ -6,6 +6,7 @@
270 DEBUG = True
271 TEMPLATE_DEBUG = DEBUG
272 STATIC_SERVE = True
273+PROJECT_NAME = 'harvest'
274
275 ADMINS = ('Daniel Holbach', 'daniel.holbach@ubuntu.com')
276 MANAGERS = ADMINS

Subscribers

People subscribed via source and target branches

to all changes: