Mercurial > cpython-lru_cache-weakref
annotate Lib/distutils/command/register.py @ 58925:eecf1bef052d 2.6
Merged revisions 78207 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r78207 | ezio.melotti | 2010-02-17 01:26:09 +0200 (Wed, 17 Feb 2010) | 1 line
#7930: fix stripid
........
| author | Ezio Melotti <ezio.melotti@gmail.com> |
|---|---|
| date | Tue, 16 Feb 2010 23:29:44 +0000 |
| parents | 3947fdca2f40 |
| children | b36cb4602e21 |
| rev | line source |
|---|---|
|
27049
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
1 """distutils.command.register |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
2 |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
3 Implements the Distutils 'register' command (register with the repository). |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
4 """ |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
5 |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
6 # created 2002/10/21, Richard Jones |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
7 |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
8 __revision__ = "$Id$" |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
9 |
|
45468
1d84bf5f9478
Patch #2167 from calvin: Remove unused imports
Christian Heimes <christian@cheimes.de>
parents:
45413
diff
changeset
|
10 import os, string, urllib2, getpass, urlparse |
|
46881
0df616193b98
#1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents:
46836
diff
changeset
|
11 import StringIO |
|
27049
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
12 |
|
46881
0df616193b98
#1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents:
46836
diff
changeset
|
13 from distutils.core import PyPIRCCommand |
|
27049
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
14 from distutils.errors import * |
|
46881
0df616193b98
#1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents:
46836
diff
changeset
|
15 from distutils import log |
|
27049
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
16 |
|
46881
0df616193b98
#1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents:
46836
diff
changeset
|
17 class register(PyPIRCCommand): |
|
27049
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
18 |
| 28151 | 19 description = ("register the distribution with the Python package index") |
|
46881
0df616193b98
#1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents:
46836
diff
changeset
|
20 user_options = PyPIRCCommand.user_options + [ |
|
27049
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
21 ('list-classifiers', None, |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
22 'list the valid Trove classifiers'), |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
23 ] |
|
46881
0df616193b98
#1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents:
46836
diff
changeset
|
24 boolean_options = PyPIRCCommand.boolean_options + [ |
|
0df616193b98
#1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents:
46836
diff
changeset
|
25 'verify', 'list-classifiers'] |
|
27049
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
26 |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
27 def initialize_options(self): |
|
46881
0df616193b98
#1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents:
46836
diff
changeset
|
28 PyPIRCCommand.initialize_options(self) |
|
27049
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
29 self.list_classifiers = 0 |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
30 |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
31 def run(self): |
|
46881
0df616193b98
#1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents:
46836
diff
changeset
|
32 self.finalize_options() |
|
0df616193b98
#1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents:
46836
diff
changeset
|
33 self._set_config() |
|
27049
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
34 self.check_metadata() |
|
28544
ee8853cc8ca1
Remove the --verify option in favor of the standard -n/--dry-run option
Andrew M. Kuchling <amk@amk.ca>
parents:
28151
diff
changeset
|
35 if self.dry_run: |
|
27049
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
36 self.verify_metadata() |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
37 elif self.list_classifiers: |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
38 self.classifiers() |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
39 else: |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
40 self.send_metadata() |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
41 |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
42 def check_metadata(self): |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
43 """Ensure that all required elements of meta-data (name, version, |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
44 URL, (author and author_email) or (maintainer and |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
45 maintainer_email)) are supplied by the Distribution object; warn if |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
46 any are missing. |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
47 """ |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
48 metadata = self.distribution.metadata |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
49 |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
50 missing = [] |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
51 for attr in ('name', 'version', 'url'): |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
52 if not (hasattr(metadata, attr) and getattr(metadata, attr)): |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
53 missing.append(attr) |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
54 |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
55 if missing: |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
56 self.warn("missing required meta-data: " + |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
57 string.join(missing, ", ")) |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
58 |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
59 if metadata.author: |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
60 if not metadata.author_email: |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
61 self.warn("missing meta-data: if 'author' supplied, " + |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
62 "'author_email' must be supplied too") |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
63 elif metadata.maintainer: |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
64 if not metadata.maintainer_email: |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
65 self.warn("missing meta-data: if 'maintainer' supplied, " + |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
66 "'maintainer_email' must be supplied too") |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
67 else: |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
68 self.warn("missing meta-data: either (author and author_email) " + |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
69 "or (maintainer and maintainer_email) " + |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
70 "must be supplied") |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
71 |
|
46881
0df616193b98
#1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents:
46836
diff
changeset
|
72 def _set_config(self): |
|
0df616193b98
#1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents:
46836
diff
changeset
|
73 ''' Reads the configuration file and set attributes. |
|
0df616193b98
#1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents:
46836
diff
changeset
|
74 ''' |
|
0df616193b98
#1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents:
46836
diff
changeset
|
75 config = self._read_pypirc() |
|
0df616193b98
#1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents:
46836
diff
changeset
|
76 if config != {}: |
|
0df616193b98
#1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents:
46836
diff
changeset
|
77 self.username = config['username'] |
|
0df616193b98
#1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents:
46836
diff
changeset
|
78 self.password = config['password'] |
|
0df616193b98
#1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents:
46836
diff
changeset
|
79 self.repository = config['repository'] |
|
0df616193b98
#1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents:
46836
diff
changeset
|
80 self.realm = config['realm'] |
|
0df616193b98
#1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents:
46836
diff
changeset
|
81 self.has_config = True |
|
0df616193b98
#1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents:
46836
diff
changeset
|
82 else: |
|
0df616193b98
#1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents:
46836
diff
changeset
|
83 if self.repository not in ('pypi', self.DEFAULT_REPOSITORY): |
|
0df616193b98
#1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents:
46836
diff
changeset
|
84 raise ValueError('%s not found in .pypirc' % self.repository) |
|
0df616193b98
#1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents:
46836
diff
changeset
|
85 if self.repository == 'pypi': |
|
0df616193b98
#1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents:
46836
diff
changeset
|
86 self.repository = self.DEFAULT_REPOSITORY |
|
0df616193b98
#1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents:
46836
diff
changeset
|
87 self.has_config = False |
|
0df616193b98
#1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents:
46836
diff
changeset
|
88 |
|
27049
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
89 def classifiers(self): |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
90 ''' Fetch the list of classifiers from the server. |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
91 ''' |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
92 response = urllib2.urlopen(self.repository+'?:action=list_classifiers') |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
93 print response.read() |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
94 |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
95 def verify_metadata(self): |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
96 ''' Send the metadata to the package index server to be checked. |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
97 ''' |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
98 # send the info to the server and report the result |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
99 (code, result) = self.post_to_server(self.build_post_data('verify')) |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
100 print 'Server response (%s): %s'%(code, result) |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
101 |
|
46881
0df616193b98
#1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents:
46836
diff
changeset
|
102 |
|
27049
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
103 def send_metadata(self): |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
104 ''' Send the metadata to the package index server. |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
105 |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
106 Well, do the following: |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
107 1. figure who the user is, and then |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
108 2. send the data as a Basic auth'ed POST. |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
109 |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
110 First we try to read the username/password from $HOME/.pypirc, |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
111 which is a ConfigParser-formatted file with a section |
|
46881
0df616193b98
#1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents:
46836
diff
changeset
|
112 [distutils] containing username and password entries (both |
|
27049
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
113 in clear text). Eg: |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
114 |
|
46881
0df616193b98
#1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents:
46836
diff
changeset
|
115 [distutils] |
|
0df616193b98
#1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents:
46836
diff
changeset
|
116 index-servers = |
|
0df616193b98
#1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents:
46836
diff
changeset
|
117 pypi |
|
0df616193b98
#1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents:
46836
diff
changeset
|
118 |
|
0df616193b98
#1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents:
46836
diff
changeset
|
119 [pypi] |
|
27049
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
120 username: fred |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
121 password: sekrit |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
122 |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
123 Otherwise, to figure who the user is, we offer the user three |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
124 choices: |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
125 |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
126 1. use existing login, |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
127 2. register as a new user, or |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
128 3. set the password to a random string and email the user. |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
129 |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
130 ''' |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
131 # see if we can short-cut and get the username/password from the |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
132 # config |
|
46881
0df616193b98
#1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents:
46836
diff
changeset
|
133 if self.has_config: |
|
0df616193b98
#1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents:
46836
diff
changeset
|
134 choice = '1' |
|
0df616193b98
#1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents:
46836
diff
changeset
|
135 username = self.username |
|
0df616193b98
#1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents:
46836
diff
changeset
|
136 password = self.password |
|
0df616193b98
#1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents:
46836
diff
changeset
|
137 else: |
|
0df616193b98
#1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents:
46836
diff
changeset
|
138 choice = 'x' |
|
0df616193b98
#1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents:
46836
diff
changeset
|
139 username = password = '' |
|
27049
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
140 |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
141 # get the user's login info |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
142 choices = '1 2 3 4'.split() |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
143 while choice not in choices: |
|
50298
fb150fcf165d
Merged revisions 67926 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
46881
diff
changeset
|
144 self.announce('''\ |
|
fb150fcf165d
Merged revisions 67926 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
46881
diff
changeset
|
145 We need to know who you are, so please choose either: |
|
27049
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
146 1. use your existing login, |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
147 2. register as a new user, |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
148 3. have the server generate a new password for you (and email it to you), or |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
149 4. quit |
|
50298
fb150fcf165d
Merged revisions 67926 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
46881
diff
changeset
|
150 Your selection [default 1]: ''', log.INFO) |
|
fb150fcf165d
Merged revisions 67926 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
46881
diff
changeset
|
151 |
|
27049
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
152 choice = raw_input() |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
153 if not choice: |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
154 choice = '1' |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
155 elif choice not in choices: |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
156 print 'Please choose one of the four options!' |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
157 |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
158 if choice == '1': |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
159 # get the username and password |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
160 while not username: |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
161 username = raw_input('Username: ') |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
162 while not password: |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
163 password = getpass.getpass('Password: ') |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
164 |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
165 # set up the authentication |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
166 auth = urllib2.HTTPPasswordMgr() |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
167 host = urlparse.urlparse(self.repository)[1] |
|
46881
0df616193b98
#1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents:
46836
diff
changeset
|
168 auth.add_password(self.realm, host, username, password) |
|
27049
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
169 # send the info to the server and report the result |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
170 code, result = self.post_to_server(self.build_post_data('submit'), |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
171 auth) |
|
50298
fb150fcf165d
Merged revisions 67926 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
46881
diff
changeset
|
172 self.announce('Server response (%s): %s' % (code, result), |
|
fb150fcf165d
Merged revisions 67926 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
46881
diff
changeset
|
173 log.INFO) |
|
27049
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
174 |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
175 # possibly save the login |
|
46881
0df616193b98
#1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents:
46836
diff
changeset
|
176 if not self.has_config and code == 200: |
|
50298
fb150fcf165d
Merged revisions 67926 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
46881
diff
changeset
|
177 self.announce(('I can store your PyPI login so future ' |
|
fb150fcf165d
Merged revisions 67926 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
46881
diff
changeset
|
178 'submissions will be faster.'), log.INFO) |
|
fb150fcf165d
Merged revisions 67926 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
46881
diff
changeset
|
179 self.announce('(the login will be stored in %s)' % \ |
|
fb150fcf165d
Merged revisions 67926 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
46881
diff
changeset
|
180 self._get_rc_file(), log.INFO) |
|
fb150fcf165d
Merged revisions 67926 via svnmerge from
Tarek Ziadé <ziade.tarek@gmail.com>
parents:
46881
diff
changeset
|
181 |
|
27049
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
182 choice = 'X' |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
183 while choice.lower() not in 'yn': |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
184 choice = raw_input('Save your login (y/N)?') |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
185 if not choice: |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
186 choice = 'n' |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
187 if choice.lower() == 'y': |
|
46881
0df616193b98
#1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents:
46836
diff
changeset
|
188 self._store_pypirc(username, password) |
|
0df616193b98
#1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents:
46836
diff
changeset
|
189 |
|
27049
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
190 elif choice == '2': |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
191 data = {':action': 'user'} |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
192 data['name'] = data['password'] = data['email'] = '' |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
193 data['confirm'] = None |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
194 while not data['name']: |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
195 data['name'] = raw_input('Username: ') |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
196 while data['password'] != data['confirm']: |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
197 while not data['password']: |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
198 data['password'] = getpass.getpass('Password: ') |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
199 while not data['confirm']: |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
200 data['confirm'] = getpass.getpass(' Confirm: ') |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
201 if data['password'] != data['confirm']: |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
202 data['password'] = '' |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
203 data['confirm'] = None |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
204 print "Password and confirm don't match!" |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
205 while not data['email']: |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
206 data['email'] = raw_input(' EMail: ') |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
207 code, result = self.post_to_server(data) |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
208 if code != 200: |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
209 print 'Server response (%s): %s'%(code, result) |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
210 else: |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
211 print 'You will receive an email shortly.' |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
212 print 'Follow the instructions in it to complete registration.' |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
213 elif choice == '3': |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
214 data = {':action': 'password_reset'} |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
215 data['email'] = '' |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
216 while not data['email']: |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
217 data['email'] = raw_input('Your email address: ') |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
218 code, result = self.post_to_server(data) |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
219 print 'Server response (%s): %s'%(code, result) |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
220 |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
221 def build_post_data(self, action): |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
222 # figure the data to send - the metadata plus some additional |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
223 # information used by the package server |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
224 meta = self.distribution.metadata |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
225 data = { |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
226 ':action': action, |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
227 'metadata_version' : '1.0', |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
228 'name': meta.get_name(), |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
229 'version': meta.get_version(), |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
230 'summary': meta.get_description(), |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
231 'home_page': meta.get_url(), |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
232 'author': meta.get_contact(), |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
233 'author_email': meta.get_contact_email(), |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
234 'license': meta.get_licence(), |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
235 'description': meta.get_long_description(), |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
236 'keywords': meta.get_keywords(), |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
237 'platform': meta.get_platforms(), |
|
27974
d0d29df2b639
[Patch #684398] Rename verbose argument to show-response; don't conditionalize the get_classifiers() call
Andrew M. Kuchling <amk@amk.ca>
parents:
27945
diff
changeset
|
238 'classifiers': meta.get_classifiers(), |
|
27976
d5ea2b67b5f4
Include download_url in the data POSTed to the catalog server
Andrew M. Kuchling <amk@amk.ca>
parents:
27974
diff
changeset
|
239 'download_url': meta.get_download_url(), |
|
34785
dc6f315f1f7f
PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents:
32736
diff
changeset
|
240 # PEP 314 |
|
dc6f315f1f7f
PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents:
32736
diff
changeset
|
241 'provides': meta.get_provides(), |
|
dc6f315f1f7f
PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents:
32736
diff
changeset
|
242 'requires': meta.get_requires(), |
|
dc6f315f1f7f
PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents:
32736
diff
changeset
|
243 'obsoletes': meta.get_obsoletes(), |
|
27049
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
244 } |
|
34785
dc6f315f1f7f
PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents:
32736
diff
changeset
|
245 if data['provides'] or data['requires'] or data['obsoletes']: |
|
dc6f315f1f7f
PEP 314 implementation (client side):
Fred Drake <fdrake@acm.org>
parents:
32736
diff
changeset
|
246 data['metadata_version'] = '1.1' |
|
27049
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
247 return data |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
248 |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
249 def post_to_server(self, data, auth=None): |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
250 ''' Post a query to the server, and return a string response. |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
251 ''' |
|
46881
0df616193b98
#1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents:
46836
diff
changeset
|
252 self.announce('Registering %s to %s' % (data['name'], |
|
0df616193b98
#1858: re-apply patch for this, adding the missing files
Andrew M. Kuchling <amk@amk.ca>
parents:
46836
diff
changeset
|
253 self.repository), log.INFO) |
|
27049
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
254 # Build up the MIME payload for the urllib2 POST data |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
255 boundary = '--------------GHSKFJDLGDS7543FJKLFHRE75642756743254' |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
256 sep_boundary = '\n--' + boundary |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
257 end_boundary = sep_boundary + '--' |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
258 body = StringIO.StringIO() |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
259 for key, value in data.items(): |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
260 # handle multiple entries for the same name |
|
40034
0e9fdb164d20
[Bug #1545341] Allow 'classifier' parameter to be a tuple as well as a list. Will backport.
Andrew M. Kuchling <amk@amk.ca>
parents:
34852
diff
changeset
|
261 if type(value) not in (type([]), type( () )): |
|
27049
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
262 value = [value] |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
263 for value in value: |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
264 body.write(sep_boundary) |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
265 body.write('\nContent-Disposition: form-data; name="%s"'%key) |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
266 body.write("\n\n") |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
267 body.write(value) |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
268 if value and value[-1] == '\r': |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
269 body.write('\n') # write an extra newline (lurve Macs) |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
270 body.write(end_boundary) |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
271 body.write("\n") |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
272 body = body.getvalue() |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
273 |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
274 # build the Request |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
275 headers = { |
|
34852
63c5d6ce0763
Since PyPI only accepts UTF-8 encoded data now, make sure that the data is
Walter Dörwald <walter@livinglogic.de>
parents:
34785
diff
changeset
|
276 'Content-type': 'multipart/form-data; boundary=%s; charset=utf-8'%boundary, |
|
27049
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
277 'Content-length': str(len(body)) |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
278 } |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
279 req = urllib2.Request(self.repository, body, headers) |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
280 |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
281 # handle HTTP and include the Basic Auth handler |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
282 opener = urllib2.build_opener( |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
283 urllib2.HTTPBasicAuthHandler(password_mgr=auth) |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
284 ) |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
285 data = '' |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
286 try: |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
287 result = opener.open(req) |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
288 except urllib2.HTTPError, e: |
|
27974
d0d29df2b639
[Patch #684398] Rename verbose argument to show-response; don't conditionalize the get_classifiers() call
Andrew M. Kuchling <amk@amk.ca>
parents:
27945
diff
changeset
|
289 if self.show_response: |
|
27049
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
290 data = e.fp.read() |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
291 result = e.code, e.msg |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
292 except urllib2.URLError, e: |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
293 result = 500, str(e) |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
294 else: |
|
27974
d0d29df2b639
[Patch #684398] Rename verbose argument to show-response; don't conditionalize the get_classifiers() call
Andrew M. Kuchling <amk@amk.ca>
parents:
27945
diff
changeset
|
295 if self.show_response: |
|
27049
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
296 data = result.read() |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
297 result = 200, 'OK' |
|
27974
d0d29df2b639
[Patch #684398] Rename verbose argument to show-response; don't conditionalize the get_classifiers() call
Andrew M. Kuchling <amk@amk.ca>
parents:
27945
diff
changeset
|
298 if self.show_response: |
|
27049
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
299 print '-'*75, data, '-'*75 |
|
1cd9c8564875
[Patch #658094 ] PEP 301 implementation
Andrew M. Kuchling <amk@amk.ca>
parents:
diff
changeset
|
300 return result |
