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
=== modified file 'bin/ssh-import-id'
--- bin/ssh-import-id 2014-02-27 15:37:37 +0000
+++ bin/ssh-import-id 2014-04-27 16:24:09 +0000
@@ -1,4 +1,4 @@
1#!/usr/bin/env python1#!/usr/bin/env python3
2#2#
3# ssh-import-id - Authorize SSH public keys from trusted online identities3# ssh-import-id - Authorize SSH public keys from trusted online identities
4#4#
@@ -188,7 +188,7 @@
188 output, _ = proc.communicate(None)188 output, _ = proc.communicate(None)
189 if proc.returncode:189 if proc.returncode:
190 raise Exception("Error executing protocol helper [%s]" % proto_cmd_path)190 raise Exception("Error executing protocol helper [%s]" % proto_cmd_path)
191 return output.split("\n")191 return output.split(b"\n")
192192
193193
194def import_keys(proto, username):194def import_keys(proto, username):
195195
=== modified file 'bin/ssh-import-id-gh'
--- bin/ssh-import-id-gh 2013-03-15 14:54:58 +0000
+++ bin/ssh-import-id-gh 2014-04-27 16:24:09 +0000
@@ -1,4 +1,4 @@
1#!/usr/bin/env python1#!/usr/bin/env python3
2#2#
3# ssh-import-id - Authorize SSH public keys from trusted online identities.3# ssh-import-id - Authorize SSH public keys from trusted online identities.
4#4#
@@ -21,19 +21,8 @@
21import json21import json
22import subprocess22import subprocess
23import sys23import sys
24try:24import requests
25 import requests25from urllib.parse import quote_plus
26 # Only versions >= 1.1.0 support SSL certificate verification
27 if requests.__version__ >= '1.1.0':
28 REQUESTS = True
29 else:
30 REQUESTS = False
31except:
32 REQUESTS = False
33try:
34 from urllib import quote_plus
35except (ImportError,):
36 from urllib.parse import quote_plus
3726
3827
39if __name__ == '__main__':28if __name__ == '__main__':
@@ -43,17 +32,7 @@
43 for ghid in sys.argv[1:]:32 for ghid in sys.argv[1:]:
44 try:33 try:
45 url = "https://api.github.com/users/%s/keys" % (quote_plus(ghid))34 url = "https://api.github.com/users/%s/keys" % (quote_plus(ghid))
46 if REQUESTS:35 text = requests.get(url, verify=True).text
47 text = requests.get(url, verify=True).text
48 else:
49 # Fall back to using good 'ole ubiquitous wget
50 p = subprocess.Popen(["wget", "--no-verbose", "-O", "-", url], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
51 stdout, stderr = p.communicate()
52 sys.stderr.write(stderr.decode('utf-8'))
53 if p.returncode == 0:
54 text = stdout.decode('utf-8')
55 else:
56 raise Exception("Could not fetch URL [%s]" % url)
57 data = json.loads(text)36 data = json.loads(text)
58 for keyobj in data:37 for keyobj in data:
59 sys.stdout.write("%s %s@github/%s\n" % (keyobj['key'], ghid, keyobj['id']))38 sys.stdout.write("%s %s@github/%s\n" % (keyobj['key'], ghid, keyobj['id']))
6039
=== modified file 'bin/ssh-import-id-lp'
--- bin/ssh-import-id-lp 2013-03-15 14:51:43 +0000
+++ bin/ssh-import-id-lp 2014-04-27 16:24:09 +0000
@@ -1,4 +1,4 @@
1#!/usr/bin/env python1#!/usr/bin/env python3
2#2#
3# ssh-import-id - Authorize SSH public keys from trusted online identities.3# ssh-import-id - Authorize SSH public keys from trusted online identities.
4#4#
@@ -21,19 +21,8 @@
21import os21import os
22import subprocess22import subprocess
23import sys23import sys
24try:24import requests
25 import requests25from urllib.parse import quote_plus
26 # Only versions >= 1.1.0 support SSL certificate verification
27 if requests.__version__ >= '1.1.0':
28 REQUESTS = True
29 else:
30 REQUESTS = False
31except:
32 REQUESTS = False
33try:
34 from urllib import quote_plus
35except (ImportError,):
36 from urllib.parse import quote_plus
3726
3827
39if __name__ == '__main__':28if __name__ == '__main__':
@@ -46,7 +35,7 @@
46 if url is None and os.path.exists("/etc/ssh/ssh_import_id"):35 if url is None and os.path.exists("/etc/ssh/ssh_import_id"):
47 try:36 try:
48 conf = json.loads(open("/etc/ssh/ssh_import_id").read())37 conf = json.loads(open("/etc/ssh/ssh_import_id").read())
49 url = conf.get("URL", None).decode("utf-8") % (quote_plus(lpid))38 url = conf.get("URL", None) % (quote_plus(lpid))
50 except:39 except:
51 raise Exception("Ensure that URL is defined in [/etc/ssh/ssh_import_id] is in JSON syntax")40 raise Exception("Ensure that URL is defined in [/etc/ssh/ssh_import_id] is in JSON syntax")
52 elif url is not None:41 elif url is not None:
@@ -54,17 +43,7 @@
54 # Finally, fall back to Launchpad43 # Finally, fall back to Launchpad
55 if url is None:44 if url is None:
56 url = "https://launchpad.net/~%s/+sshkeys" % (quote_plus(lpid))45 url = "https://launchpad.net/~%s/+sshkeys" % (quote_plus(lpid))
57 if REQUESTS:46 text = requests.get(url, verify=True).text
58 text = requests.get(url, verify=True).text
59 else:
60 # Fall back to using good 'ole ubiquitous wget
61 p = subprocess.Popen(["wget", "--no-verbose", "-O", "-", url], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
62 stdout, stderr = p.communicate()
63 sys.stderr.write(stderr.decode('utf-8'))
64 if p.returncode == 0:
65 text = stdout.decode('utf-8')
66 else:
67 raise Exception("Could not fetch URL [%s]" % url)
68 sys.stdout.write(str(text))47 sys.stdout.write(str(text))
69 sys.stdout.write("\n")48 sys.stdout.write("\n")
70 sys.stdout.flush()49 sys.stdout.flush()
7150
=== modified file 'debian/changelog'
--- debian/changelog 2014-02-27 15:39:24 +0000
+++ debian/changelog 2014-04-27 16:24:09 +0000
@@ -1,7 +1,11 @@
1ssh-import-id (3.22) unreleased; urgency=low1ssh-import-id (3.22) unreleased; urgency=low
22
3 [ Dustin Kirkland ]
3 * UNRELEASED4 * UNRELEASED
45
6 [ Andrew Starr-Bochicchio ]
7 * Port to python3 (LP: #1252474).
8
5 -- Dustin Kirkland <kirkland@ubuntu.com> Thu, 27 Feb 2014 09:39:24 -06009 -- Dustin Kirkland <kirkland@ubuntu.com> Thu, 27 Feb 2014 09:39:24 -0600
610
7ssh-import-id (3.21-0ubuntu1) trusty; urgency=low11ssh-import-id (3.21-0ubuntu1) trusty; urgency=low
812
=== modified file 'debian/control'
--- debian/control 2013-08-16 20:31:19 +0000
+++ debian/control 2014-04-27 16:24:09 +0000
@@ -3,11 +3,12 @@
3Priority: extra3Priority: extra
4Maintainer: Dustin Kirkland <kirkland@ubuntu.com>4Maintainer: Dustin Kirkland <kirkland@ubuntu.com>
5Uploaders: Andrew Starr-Bochicchio <asb@debian.org>5Uploaders: Andrew Starr-Bochicchio <asb@debian.org>
6Build-Depends: debhelper (>= 7.0.50~),6Build-Depends: debhelper (>= 8),
7 pep8,7 python3-pep8,
8 python-all (>= 2.6),8 python3-all,
9 python-setuptools9 python3-setuptools
10Standards-Version: 3.9.410Standards-Version: 3.9.5
11X-Python3-Version: >= 3.2
11Homepage: http://launchpad.net/ssh-import-id12Homepage: http://launchpad.net/ssh-import-id
12Vcs-Browser: http://bazaar.launchpad.net/~ssh-import-id/ssh-import-id/trunk/files13Vcs-Browser: http://bazaar.launchpad.net/~ssh-import-id/ssh-import-id/trunk/files
13Vcs-Bzr: https://code.launchpad.net/~ssh-import-id/ssh-import-id/trunk14Vcs-Bzr: https://code.launchpad.net/~ssh-import-id/ssh-import-id/trunk
@@ -16,10 +17,10 @@
16Architecture: all17Architecture: all
17Depends: ca-certificates,18Depends: ca-certificates,
18 openssh-client,19 openssh-client,
19 python-requests (>= 1.1.0),20 python3-requests (>= 1.1.0),
20 wget,21 wget,
21 ${misc:Depends},22 ${misc:Depends},
22 ${python:Depends}23 ${python3:Depends}
23Recommends: openssh-server24Recommends: openssh-server
24Description: securely retrieve an SSH public key and install it locally25Description: securely retrieve an SSH public key and install it locally
25 This utility will securely contact a public keyserver (Launchpad.net by26 This utility will securely contact a public keyserver (Launchpad.net by
2627
=== modified file 'debian/rules'
--- debian/rules 2013-02-15 22:54:53 +0000
+++ debian/rules 2014-04-27 16:24:09 +0000
@@ -1,13 +1,10 @@
1#!/usr/bin/make -f1#!/usr/bin/make -f
22
3# Lucid does not have dh_python2, but we would like to be able to use this
4# rules file to build on lucid as well. Thus the branching logic.
5WITH_PYTHON2 = $(shell test -f /usr/bin/dh_python2 && echo "--with python2")
6
7override_dh_auto_build:3override_dh_auto_build:
8 # Check syntax4 # Check syntax
9 pep8 --verbose --repeat --ignore W191,E501,E121 bin/*5 python3 /usr/lib/python3/dist-packages/pep8.py \
6 --verbose --repeat --ignore W191,E501,E121 bin/*
10 dh_auto_build7 dh_auto_build
118
12%:9%:
13 dh $@ ${WITH_PYTHON2}10 dh $@ --with python3 --buildsystem=pybuild
1411
=== modified file 'setup.py'
--- setup.py 2014-02-27 15:39:24 +0000
+++ setup.py 2014-04-27 16:24:09 +0000
@@ -1,4 +1,4 @@
1#!/usr/bin/env python1#!/usr/bin/env python3
2#2#
3# ssh-import-id - Authorize SSH public keys from trusted online identities.3# ssh-import-id - Authorize SSH public keys from trusted online identities.
4# Copyright (c) 2013 Casey Marshall <casey.marshall@gmail.com>4# Copyright (c) 2013 Casey Marshall <casey.marshall@gmail.com>
@@ -37,6 +37,6 @@
37 'bin/ssh-import-id',37 'bin/ssh-import-id',
38 'bin/ssh-import-id-gh',38 'bin/ssh-import-id-gh',
39 'bin/ssh-import-id-lp'],39 'bin/ssh-import-id-lp'],
40 install_requires=["argparse", "Requests>=1.1.0"40 install_requires=["Requests>=1.1.0"
41 ],41 ],
42)42)

Subscribers

People subscribed via source and target branches