-
Notifications
You must be signed in to change notification settings - Fork 2
/
alfredChecksum.py
executable file
·48 lines (39 loc) · 1.25 KB
/
alfredChecksum.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
#!/usr/bin/env python
import commands
import ntpath
import alfred
results = []
algs = ['sha1', 'md5', 'sha256']
def addResult(title, subtitle, icon, c_digest=None):
global results
results.append(alfred.Item(
attributes= {'uid': alfred.uid(0), 'arg': c_digest},
title=title,
subtitle=subtitle,
icon=icon
))
def getDigest(filename, alg):
digest = commands.getstatusoutput('openssl dgst -'+ alg +' ' + filename)
return digest[1].split('= ')[1]
def checkDigests(filename, digest):
global algs
match = False
for alg in algs:
c_digest = getDigest(filename, alg)
if digest == c_digest:
match = True
addResult(alg.upper() + ' MATCH for \''+ ntpath.basename(filename) + '\'', '[' + c_digest + ']', 'icons/green.png')
if not match:
addResult('NO MATCH for \''+ ntpath.basename(filename) + '\'', 'file may be corrupted!', 'icons/red.png')
def showAllDigests(filename):
global algs
for alg in algs:
c_digest = getDigest(filename, alg)
addResult(alg.upper() + ':' + c_digest, ' Hit Enter to Copy to Clipboard', 'icons/orange.png', c_digest)
# main
(filename, digest) = alfred.args()
if digest == 'all':
showAllDigests(filename)
else:
checkDigests(filename, digest)
alfred.write(alfred.xml(results))