Skip to content

Commit 5c11e32

Browse files
committed
Update to Python3 to avoid warnings on Big Sur & Monterey
1 parent 4e37cee commit 5c11e32

File tree

5 files changed

+235
-226
lines changed

5 files changed

+235
-226
lines changed

Diff for: .gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
._*
33
*.py[cod]
44
*~
5-
ssh.alfred3workflow
5+
ssh.alfred*workflow

Diff for: Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
all:
2-
zip -j9 --filesync ssh.alfred3workflow *.{plist,png,py}
2+
zip -j9 --filesync ssh.alfredworkflow *.{plist,png,py}

Diff for: README.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,21 @@ A workflow for [Alfred](http://www.alfredapp.com/) Powerpack users to rapidly op
99
## Releases
1010

1111
- [v1.3 for Alfred 2.4+](https://github.com/isometry/alfred-ssh/releases/tag/v1.3)
12-
- [v2.x for Alfred 3.1+](https://github.com/isometry/alfred-ssh/releases/latest)
12+
- [v2.3 for Alfred 3.1+](https://github.com/isometry/alfred-ssh/releases/tag/v2.3)
13+
- [v3.x for Alfred 4.0+](https://github.com/isometry/alfred-ssh/releases/latest)
1314

1415
## Prerequisites
1516

16-
- [Alfred](http://www.alfredapp.com/) (version 2.4+/3.1+)
17+
- [Alfred](http://www.alfredapp.com/) (version 2.4+/3.1+/4.0+)
1718
- The [Alfred Powerpack](http://www.alfredapp.com/powerpack/).
19+
- Python3 for v3.x+ (most easily installed/maintained with `sudo xcode-select --install` or [Homebrew](https://brew.sh/))
1820
- (optional) [pybonjour](https://pypi.python.org/pypi/pybonjour)
1921

2022
## Usage
2123

2224
Type `ssh` in Alfred followed by either a literal hostname or by some letters from the hostname of a host referenced in any of `~/.ssh/known_hosts`, `~/.ssh/config`, `/etc/hosts`, or (with `pybonjour` installed) Bonjour.
2325

24-
Alfred 3 only: workflow configuration is available by setting/changing Workflow Environment Variables (accessed via the [𝓍] button within the workflow):
26+
Alfred 3+ only: workflow configuration is available by setting/changing Workflow Environment Variables (accessed via the [𝓍] button within the workflow):
2527

2628
- disable unwanted sources by setting the associated Workflow Environment Variable to 0; e.g. `alfredssh_known_hosts`, `alfredssh_ssh_config`, `alfredssh_hosts`, `alfredssh_bonjour`.
2729
- change the maximum number of returned results by changing `alfredssh_max_results` (default=36).

Diff for: alfredssh.py

+19-12
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
1-
#!/usr/bin/env python2.7
2-
#-*- coding: utf-8 -*-
3-
# ssh.alfredworkflow, v2.2
4-
# Robin Breathe, 2013-2017
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
# ssh.alfredworkflow, v3.0
4+
# Robin Breathe, 2013-2021
55

6-
from __future__ import unicode_literals
7-
from __future__ import print_function
8-
9-
import json, re, sys, os
6+
import json
7+
import re
8+
import sys
9+
import os
1010

1111
from collections import defaultdict
1212
from time import time
1313

14-
DEFAULT_MAX_RESULTS=36
14+
DEFAULT_MAX_RESULTS = 36
15+
1516

1617
class Hosts(defaultdict):
1718
def __init__(self, query, user=None):
1819
super(Hosts, self).__init__(list)
1920
self[query].append('input')
2021
self.query = query
21-
self.user = user
22+
self.user = user
2223

2324
def merge(self, source, hosts=()):
2425
for host in hosts:
@@ -33,7 +34,7 @@ def _alfred_item(self, host, source):
3334
"title": _uri,
3435
"subtitle": _sub,
3536
"arg": _arg,
36-
"icon": { "path": "icon.png" },
37+
"icon": {"path": "icon.png"},
3738
"autocomplete": _arg
3839
}
3940

@@ -44,6 +45,7 @@ def alfred_json(self, _filter=(lambda x: True), maxresults=DEFAULT_MAX_RESULTS):
4445
]
4546
return json.dumps({"items": items[:maxresults]})
4647

48+
4749
def cache_file(filename, volatile=True):
4850
parent = os.path.expanduser(
4951
(
@@ -57,6 +59,7 @@ def cache_file(filename, volatile=True):
5759
raise IOError('No write access: %s' % parent)
5860
return os.path.join(parent, filename)
5961

62+
6063
def fetch_file(file_path, cache_prefix, parser, env_flag):
6164
"""
6265
Parse and cache a file with the named parser
@@ -91,6 +94,7 @@ def fetch_file(file_path, cache_prefix, parser, env_flag):
9194
# Return results
9295
return (file_path, results)
9396

97+
9498
def parse_file(open_file, parser):
9599
parsers = {
96100
'ssh_config':
@@ -122,6 +126,7 @@ def parse_file(open_file, parser):
122126
}
123127
return set(parsers[parser])
124128

129+
125130
def fetch_bonjour(_service='_ssh._tcp', alias='Bonjour', timeout=0.1):
126131
if int(os.getenv('alfredssh_bonjour', 1)) != 1:
127132
return (alias, ())
@@ -132,7 +137,7 @@ def fetch_bonjour(_service='_ssh._tcp', alias='Bonjour', timeout=0.1):
132137
try:
133138
from pybonjour import DNSServiceBrowse, DNSServiceProcessResult
134139
from select import select
135-
bj_callback = lambda s, f, i, e, n, t, d: results.add('{}.{}'.format(n.lower(), d[:-1]))
140+
def bj_callback(s, f, i, e, n, t, d): return results.add('{}.{}'.format(n.lower(), d[:-1]))
136141
bj_browser = DNSServiceBrowse(regtype=_service, callBack=bj_callback)
137142
select([bj_browser], [], [], timeout)
138143
DNSServiceProcessResult(bj_browser)
@@ -142,6 +147,7 @@ def fetch_bonjour(_service='_ssh._tcp', alias='Bonjour', timeout=0.1):
142147
json.dump(list(results), open(cache, 'w'))
143148
return (alias, results)
144149

150+
145151
def complete():
146152
query = ''.join(sys.argv[1:])
147153
maxresults = int(os.getenv('alfredssh_max_results', DEFAULT_MAX_RESULTS))
@@ -174,5 +180,6 @@ def complete():
174180

175181
return hosts.alfred_json(pattern.search, maxresults=maxresults)
176182

183+
177184
if __name__ == '__main__':
178185
print(complete())

0 commit comments

Comments
 (0)