This repository has been archived by the owner on May 24, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
cyberduck.py
71 lines (52 loc) · 1.68 KB
/
cyberduck.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import sys
import os
import getpass
import xml.etree.ElementTree as ET
import Alfred
handler = Alfred.Handler(sys.argv, use_no_query_string=False)
f = open("cyberduck_settings_folder.txt", "r")
settings_folder = f.read()
# remove the \n
settings_folder = settings_folder[:-1]
f.close()
settings_folder = settings_folder.replace("${username}", getpass.getuser())
settings_folder = os.path.join(settings_folder, "Bookmarks")
bookmark_info = []
for files in os.listdir(settings_folder):
if files.endswith(".duck"):
keys = []
values = []
file_path = os.path.join(settings_folder, files)
tree = ET.parse(file_path)
root = tree.getroot()[0]
for child in root:
if child.tag == "key":
keys.append(child.text)
elif child.tag == "string":
values.append(child.text)
bookmark_info.append({"keys": keys, "values": values, "file_path": file_path})
for info in bookmark_info:
nickname = ""
username = ""
port = ""
protocol = ""
hostname = ""
file_path = info["file_path"]
i = 0
for key in info["keys"]:
if key == "Nickname":
nickname = info["values"][i]
elif key == "Username":
username = info["values"][i]
elif key == "Port":
port = info["values"][i]
elif key == "Protocol":
protocol = info["values"][i]
elif key == "Hostname":
hostname = info["values"][i]
i += 1
if handler.query == "" or handler.query.lower() in nickname.lower():
handler.add_new_item(title=nickname, subtitle="%s %s@%s:%s" % (protocol.upper(), username, hostname, port), icon="bookmark_icon.png", arg=file_path)
if len(os.listdir(settings_folder)) == 0:
handler.add_new_item(title="No bookmarks found at", subtitle="%s" % settings_folder, icon="bookmark_icon.png")
handler.push()