Skip to content

Commit 4eb071a

Browse files
committed
Cosmetical changes, add err_on_connect
1 parent 2e0a95d commit 4eb071a

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

transmission-trackers.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
# ...
2222
]
2323

24+
# Whether to print an error if connection failed (no Transmission running?)
25+
err_on_connect = False
26+
2427
# Where to cache downloaded lists
2528
cache_file = '/tmp/trackers_cache.txt'
2629

@@ -169,14 +172,22 @@ def readLocalLists():
169172
lg("No trackers loaded, nothing to do")
170173
exit(1)
171174

172-
tc = transmissionrpc.Client(host, port=port, user=user, password=pw)
175+
try:
176+
tc = transmissionrpc.Client(host, port=port, user=user, password=pw)
177+
except:
178+
if not err_on_connect:
179+
exit()
180+
181+
print("Unable to connect to Transmission: ", sys.exc_info()[0])
182+
raise
183+
173184
torrents = tc.get_torrents()
174185

175186
dbg('{} torrents total'.format(len(torrents)))
176187

177188
for t in torrents:
178189
if status_filter and not t.status in status_filter:
179-
if debug: print('{}: skipping due to status filter'.format(t.name))
190+
dbg('{}: skipping due to status filter'.format(t.name))
180191
continue
181192

182193
ttrk = set(())
@@ -186,7 +197,7 @@ def readLocalLists():
186197
diff = trackers - ttrk
187198

188199
if diff:
189-
if not silent: print('{}: Adding {} trackers (before: {})'.format(t.name, len(diff), len(ttrk)))
200+
lg('{}: Adding {} trackers (before: {})'.format(t.name, len(diff), len(ttrk)))
190201
tc.change_torrent(t.id, trackerAdd=list(diff))
191202
else:
192-
if debug: print('{}: update not needed'.format(t.name))
203+
dbg('{}: update not needed'.format(t.name))

0 commit comments

Comments
 (0)