-
Notifications
You must be signed in to change notification settings - Fork 0
/
simpletracker.py
41 lines (33 loc) · 1.01 KB
/
simpletracker.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
#!/usr/bin/env python
import os
import hashlib
folder_info = {}
def getFolderInfo(folder):
if not os.path.exists(folder):
print("Path does not exist!")
return folder_info
if os.path.isfile(folder):
print("This is a file!")
return folder_info
print(os.listdir(folder))
for item in os.listdir(folder):
itempath = os.path.join(folder, item)
if os.path.isfile(itempath):
file_sha = hashfile(itempath)
file_size = os.path.getsize(itempath)
print("I find: "+itempath)
folder_info.setdefault(itempath, {"sha":file_sha, "size":file_size, "src":"10.0.0.1"});
elif os.path.isdir(itempath):
getFolderInfo(itempath)
return folder_info
def hashfile(filepath):
sha1 = hashlib.sha1()
f = open(filepath, 'rb')
try:
sha1.update(f.read())
finally:
f.close()
return sha1.hexdigest()
folder_info = getFolderInfo('./')
print folder_info
print len(folder_info)