diff options
author | Ask Solem <askh@opera.com> | 2009-05-08 16:35:17 +0200 |
---|---|---|
committer | Ask Solem <askh@opera.com> | 2009-05-08 16:35:17 +0200 |
commit | 0723510042387af824d33f7621106ca0151e0aa5 (patch) | |
tree | 39c702f9dcfc5a50ddcfe007de75b781261981c2 | |
parent | 9e56d5194e4138018a1f2a876fbdc16056537800 (diff) | |
parent | acf27b48661286040a009088420804192b831ad4 (diff) | |
download | chishop-0723510042387af824d33f7621106ca0151e0aa5.tar.bz2 chishop-0723510042387af824d33f7621106ca0151e0aa5.tar.xz chishop-0723510042387af824d33f7621106ca0151e0aa5.zip |
Merge branch 'runeh/master'
-rw-r--r-- | TODO | 7 | ||||
-rw-r--r-- | djangopypi/management/commands/loadclassifiers.py | 53 |
2 files changed, 56 insertions, 4 deletions
@@ -1,4 +1,4 @@ | |||
1 | * Write a tutorial on how to set up the server, registering projects, and | 1 | * Write a tutorial on how to set up the server, registering projects, and |
2 | how to upload releases. | 2 | how to upload releases. |
3 | * Make it possible to register users via distutils. | 3 | * Make it possible to register users via distutils. |
4 | (There should be a setting to turn this feature on/off). | 4 | (There should be a setting to turn this feature on/off). |
@@ -7,7 +7,6 @@ | |||
7 | * Maybe add a permission "can upload new release", so more than one | 7 | * Maybe add a permission "can upload new release", so more than one |
8 | user can change the same project. | 8 | user can change the same project. |
9 | * Should a project have co-owners? | 9 | * Should a project have co-owners? |
10 | - One possible solution: | 10 | - One possible solution: |
11 | http://github.com/initcrash/django-object-permissions/tree | 11 | http://github.com/initcrash/django-object-permissions/tree |
12 | * Script to populate classifiers from | 12 | |
13 | http://pypi.python.org/pypi?%3Aaction=list_classifiers | ||
diff --git a/djangopypi/management/commands/loadclassifiers.py b/djangopypi/management/commands/loadclassifiers.py new file mode 100644 index 0000000..49e2642 --- /dev/null +++ b/djangopypi/management/commands/loadclassifiers.py | |||
@@ -0,0 +1,53 @@ | |||
1 | """ | ||
2 | Management command for loading all the known classifiers from the official | ||
3 | pypi, or from a file/url. | ||
4 | |||
5 | Note, pypi docs says to not add classifiers that are not used in submitted | ||
6 | projects. On the other hand it can be usefull to have a list of classifiers | ||
7 | to choose if you have to modify package data. Use it if you need it. | ||
8 | """ | ||
9 | |||
10 | from __future__ import with_statement | ||
11 | import urllib | ||
12 | import os.path | ||
13 | |||
14 | from django.core.management.base import BaseCommand | ||
15 | from djangopypi.models import Classifier | ||
16 | |||
17 | CLASSIFIERS_URL = "http://pypi.python.org/pypi?%3Aaction=list_classifiers" | ||
18 | |||
19 | class Command(BaseCommand): | ||
20 | help = """Load all classifiers from pypi. If any arguments are given, | ||
21 | they will be used as paths or urls for classifiers instead of using the | ||
22 | official pypi list url""" | ||
23 | |||
24 | def handle(self, *args, **options): | ||
25 | args = args or [CLASSIFIERS_URL] | ||
26 | |||
27 | cnt = 0 | ||
28 | for location in args: | ||
29 | print "Loading %s" % location | ||
30 | lines = self._get_lines(location) | ||
31 | for name in lines: | ||
32 | c, created = Classifier.objects.get_or_create(name=name) | ||
33 | if created: | ||
34 | c.save() | ||
35 | cnt += 1 | ||
36 | |||
37 | print "Added %s new classifiers from %s source(s)" % (cnt, len(args)) | ||
38 | |||
39 | def _get_lines(self, location): | ||
40 | """Return a list of lines for a lication that can be a file or | ||
41 | a url. If path/url doesn't exist, returns an empty list""" | ||
42 | try: # This is dirty, but OK I think. both net and file ops raise IOE | ||
43 | if location.startswith(("http://", "https://")): | ||
44 | fp = urllib.urlopen(location) | ||
45 | return [e.strip() for e in fp.read().split('\n') | ||
46 | if e and not e.isspace()] | ||
47 | else: | ||
48 | fp = open(location) | ||
49 | return [e.strip() for e in fp.readlines() | ||
50 | if e and not e.isspace()] | ||
51 | except IOError: | ||
52 | print "Couldn't load %s" % location | ||
53 | return [] | ||