forked from KEMMY/BC-2012
-
Notifications
You must be signed in to change notification settings - Fork 0
/
find.py
70 lines (55 loc) · 1.64 KB
/
find.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
import os
import pickle
import md5
import sys
from stat import *
import shutil
sys.path.append('/home/kmm/Plocha/python_code')
def hash_list(inputlist):
output_list = []
for L in inputlist:
m = md5.new()
m.update(L)
output_list.append(m.digest())
return output_list
def change_adress(path):
new_path = "/home/kmm/Plocha/target/zaloha" + path[23:]
return new_path
def compare_file(src,trg):
trgstat = os.stat(trg)
srcstat = os.stat(src)
if srcstat.st_ctime == trgstat.st_ctime and srcstat.st_mtime == trgstat.st_mtime:
print(src + ": Súbor bez zmeny")
return True
else:
print(src + ": Zmenený súbor")
return False
def pickluj(stat):
pkl_file = open("/home/kmm/Plocha/nove/piclujem.pkl","wb")
pickle.dump(stat,pkl_file)
pkl_file.close()
def walktree(src):
list_zmien = []
trg = change_adress(src)
for f in os.listdir(src):
pathname = os.path.join(src, f)
mode = os.stat(pathname).st_mode
if S_ISDIR(mode):
# It's a directory
dst = os.path.join(trg,f)
walktree(pathname)
elif S_ISREG(mode):
abc = os.path.join(trg,f)
x = compare_file(pathname,abc)
if x == False : list_zmien.append(pathname)
else:
# Unknown file type, print a message
print('Skipping %s' % pathname)
return hash_list(list_zmien)
adress = change_adress("/home/kmm/Plocha/source")
print adress
src="/home/kmm/Plocha/source"
zmeny = walktree(src)
print zmeny
x = os.stat("/home/kmm/Plocha/nove/stats.txt")
pickluj(x)