Merge lp:~andrewsomething/ssh-import-id/python3-port into lp:ssh-import-id

Proposed by Andrew Starr-Bochicchio
Status: Merged
Merged at revision: 167
Proposed branch: lp:~andrewsomething/ssh-import-id/python3-port
Merge into: lp:ssh-import-id
Diff against target: 219 lines (+28/-68)
7 files modified
bin/ssh-import-id (+2/-2)
bin/ssh-import-id-gh (+4/-25)
bin/ssh-import-id-lp (+5/-26)
debian/changelog (+4/-0)
debian/control (+8/-7)
debian/rules (+3/-6)
setup.py (+2/-2)
To merge this branch: bzr merge lp:~andrewsomething/ssh-import-id/python3-port
Reviewer Review Type Date Requested Status
ssh-import-id Pending
Review via email: mp+217360@code.launchpad.net

Description of the change

Ported to Python3. Also dropped some of the work arounds for old versions of requests and urllib.

I've added and removed keys from both GitHub and Launchpad. Though, I can't guarantee I've tested every code path.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/ssh-import-id'
2--- bin/ssh-import-id 2014-02-27 15:37:37 +0000
3+++ bin/ssh-import-id 2014-04-27 16:24:09 +0000
4@@ -1,4 +1,4 @@
5-#!/usr/bin/env python
6+#!/usr/bin/env python3
7 #
8 # ssh-import-id - Authorize SSH public keys from trusted online identities
9 #
10@@ -188,7 +188,7 @@
11 output, _ = proc.communicate(None)
12 if proc.returncode:
13 raise Exception("Error executing protocol helper [%s]" % proto_cmd_path)
14- return output.split("\n")
15+ return output.split(b"\n")
16
17
18 def import_keys(proto, username):
19
20=== modified file 'bin/ssh-import-id-gh'
21--- bin/ssh-import-id-gh 2013-03-15 14:54:58 +0000
22+++ bin/ssh-import-id-gh 2014-04-27 16:24:09 +0000
23@@ -1,4 +1,4 @@
24-#!/usr/bin/env python
25+#!/usr/bin/env python3
26 #
27 # ssh-import-id - Authorize SSH public keys from trusted online identities.
28 #
29@@ -21,19 +21,8 @@
30 import json
31 import subprocess
32 import sys
33-try:
34- import requests
35- # Only versions >= 1.1.0 support SSL certificate verification
36- if requests.__version__ >= '1.1.0':
37- REQUESTS = True
38- else:
39- REQUESTS = False
40-except:
41- REQUESTS = False
42-try:
43- from urllib import quote_plus
44-except (ImportError,):
45- from urllib.parse import quote_plus
46+import requests
47+from urllib.parse import quote_plus
48
49
50 if __name__ == '__main__':
51@@ -43,17 +32,7 @@
52 for ghid in sys.argv[1:]:
53 try:
54 url = "https://api.github.com/users/%s/keys" % (quote_plus(ghid))
55- if REQUESTS:
56- text = requests.get(url, verify=True).text
57- else:
58- # Fall back to using good 'ole ubiquitous wget
59- p = subprocess.Popen(["wget", "--no-verbose", "-O", "-", url], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
60- stdout, stderr = p.communicate()
61- sys.stderr.write(stderr.decode('utf-8'))
62- if p.returncode == 0:
63- text = stdout.decode('utf-8')
64- else:
65- raise Exception("Could not fetch URL [%s]" % url)
66+ text = requests.get(url, verify=True).text
67 data = json.loads(text)
68 for keyobj in data:
69 sys.stdout.write("%s %s@github/%s\n" % (keyobj['key'], ghid, keyobj['id']))
70
71=== modified file 'bin/ssh-import-id-lp'
72--- bin/ssh-import-id-lp 2013-03-15 14:51:43 +0000
73+++ bin/ssh-import-id-lp 2014-04-27 16:24:09 +0000
74@@ -1,4 +1,4 @@
75-#!/usr/bin/env python
76+#!/usr/bin/env python3
77 #
78 # ssh-import-id - Authorize SSH public keys from trusted online identities.
79 #
80@@ -21,19 +21,8 @@
81 import os
82 import subprocess
83 import sys
84-try:
85- import requests
86- # Only versions >= 1.1.0 support SSL certificate verification
87- if requests.__version__ >= '1.1.0':
88- REQUESTS = True
89- else:
90- REQUESTS = False
91-except:
92- REQUESTS = False
93-try:
94- from urllib import quote_plus
95-except (ImportError,):
96- from urllib.parse import quote_plus
97+import requests
98+from urllib.parse import quote_plus
99
100
101 if __name__ == '__main__':
102@@ -46,7 +35,7 @@
103 if url is None and os.path.exists("/etc/ssh/ssh_import_id"):
104 try:
105 conf = json.loads(open("/etc/ssh/ssh_import_id").read())
106- url = conf.get("URL", None).decode("utf-8") % (quote_plus(lpid))
107+ url = conf.get("URL", None) % (quote_plus(lpid))
108 except:
109 raise Exception("Ensure that URL is defined in [/etc/ssh/ssh_import_id] is in JSON syntax")
110 elif url is not None:
111@@ -54,17 +43,7 @@
112 # Finally, fall back to Launchpad
113 if url is None:
114 url = "https://launchpad.net/~%s/+sshkeys" % (quote_plus(lpid))
115- if REQUESTS:
116- text = requests.get(url, verify=True).text
117- else:
118- # Fall back to using good 'ole ubiquitous wget
119- p = subprocess.Popen(["wget", "--no-verbose", "-O", "-", url], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
120- stdout, stderr = p.communicate()
121- sys.stderr.write(stderr.decode('utf-8'))
122- if p.returncode == 0:
123- text = stdout.decode('utf-8')
124- else:
125- raise Exception("Could not fetch URL [%s]" % url)
126+ text = requests.get(url, verify=True).text
127 sys.stdout.write(str(text))
128 sys.stdout.write("\n")
129 sys.stdout.flush()
130
131=== modified file 'debian/changelog'
132--- debian/changelog 2014-02-27 15:39:24 +0000
133+++ debian/changelog 2014-04-27 16:24:09 +0000
134@@ -1,7 +1,11 @@
135 ssh-import-id (3.22) unreleased; urgency=low
136
137+ [ Dustin Kirkland ]
138 * UNRELEASED
139
140+ [ Andrew Starr-Bochicchio ]
141+ * Port to python3 (LP: #1252474).
142+
143 -- Dustin Kirkland <kirkland@ubuntu.com> Thu, 27 Feb 2014 09:39:24 -0600
144
145 ssh-import-id (3.21-0ubuntu1) trusty; urgency=low
146
147=== modified file 'debian/control'
148--- debian/control 2013-08-16 20:31:19 +0000
149+++ debian/control 2014-04-27 16:24:09 +0000
150@@ -3,11 +3,12 @@
151 Priority: extra
152 Maintainer: Dustin Kirkland <kirkland@ubuntu.com>
153 Uploaders: Andrew Starr-Bochicchio <asb@debian.org>
154-Build-Depends: debhelper (>= 7.0.50~),
155- pep8,
156- python-all (>= 2.6),
157- python-setuptools
158-Standards-Version: 3.9.4
159+Build-Depends: debhelper (>= 8),
160+ python3-pep8,
161+ python3-all,
162+ python3-setuptools
163+Standards-Version: 3.9.5
164+X-Python3-Version: >= 3.2
165 Homepage: http://launchpad.net/ssh-import-id
166 Vcs-Browser: http://bazaar.launchpad.net/~ssh-import-id/ssh-import-id/trunk/files
167 Vcs-Bzr: https://code.launchpad.net/~ssh-import-id/ssh-import-id/trunk
168@@ -16,10 +17,10 @@
169 Architecture: all
170 Depends: ca-certificates,
171 openssh-client,
172- python-requests (>= 1.1.0),
173+ python3-requests (>= 1.1.0),
174 wget,
175 ${misc:Depends},
176- ${python:Depends}
177+ ${python3:Depends}
178 Recommends: openssh-server
179 Description: securely retrieve an SSH public key and install it locally
180 This utility will securely contact a public keyserver (Launchpad.net by
181
182=== modified file 'debian/rules'
183--- debian/rules 2013-02-15 22:54:53 +0000
184+++ debian/rules 2014-04-27 16:24:09 +0000
185@@ -1,13 +1,10 @@
186 #!/usr/bin/make -f
187
188-# Lucid does not have dh_python2, but we would like to be able to use this
189-# rules file to build on lucid as well. Thus the branching logic.
190-WITH_PYTHON2 = $(shell test -f /usr/bin/dh_python2 && echo "--with python2")
191-
192 override_dh_auto_build:
193 # Check syntax
194- pep8 --verbose --repeat --ignore W191,E501,E121 bin/*
195+ python3 /usr/lib/python3/dist-packages/pep8.py \
196+ --verbose --repeat --ignore W191,E501,E121 bin/*
197 dh_auto_build
198
199 %:
200- dh $@ ${WITH_PYTHON2}
201+ dh $@ --with python3 --buildsystem=pybuild
202
203=== modified file 'setup.py'
204--- setup.py 2014-02-27 15:39:24 +0000
205+++ setup.py 2014-04-27 16:24:09 +0000
206@@ -1,4 +1,4 @@
207-#!/usr/bin/env python
208+#!/usr/bin/env python3
209 #
210 # ssh-import-id - Authorize SSH public keys from trusted online identities.
211 # Copyright (c) 2013 Casey Marshall <casey.marshall@gmail.com>
212@@ -37,6 +37,6 @@
213 'bin/ssh-import-id',
214 'bin/ssh-import-id-gh',
215 'bin/ssh-import-id-lp'],
216- install_requires=["argparse", "Requests>=1.1.0"
217+ install_requires=["Requests>=1.1.0"
218 ],
219 )

Subscribers

People subscribed via source and target branches