-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnew_tree
89 lines (80 loc) · 2.64 KB
/
new_tree
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import pickle
import md5
import os
import sys
from stat import *
import shutil
'''
hash_file - skusal som nahradzat nazvy suborov ich hasmi,
funkciu zatial nevyuzivam
'''
def hash_file_names(file_name):
return (md5.md5(file_name).hexdigest())
'''
funkcia zoberie zdrojovy subor a o uroven vysie
v cielom adresari zapikluje jeho meta data
'''
def meta_maker(source_file,target_path):
source_stat = os.stat(source_file)
pickle_file_adress = target_path + ".pkl"
pkl_file = open(pickle_file_adress,"wb")
pickle.dump(source_stat,pkl_file)
pkl_file.close()
'''
obycajne kopirovanie stromu konecne s 3 paranetrami,
takto odpadaju moje funkcie chage_adress a podobne
neprijemnosti s path-mi
dakujem Vam za radu
'''
def tree_copy(source,target,path):
src = os.path.join(source,path)
trg = os.path.join(target,path)
for f in os.listdir(src):
src_path = os.path.join(src, f)
mode = os.stat(src_path).st_mode
print(mode)
if S_ISDIR(mode):
# It's a directory
print "os.mkdir(%s)" % (trg)
dst_f = os.path.join(trg,f)
os.mkdir(dst_f)
tree_copy(src,trg,f)
elif S_ISREG(mode):
print (path)
print "shutil.copy(%s,%s)" % (src,trg)
target_f = os.path.join(trg,f)
shutil.copy(src_path,target_f)
else:
# Unknown file type, print a message
print('Skipping %s' % pathname)
'''
to iste + aj vytvaranie meta o uroven vysie
'''
def tree_copy_with_meta_maker(source,target,path):
src = os.path.join(source,path)
trg = os.path.join(target,path)
for f in os.listdir(src):
src_path = os.path.join(src, f)
mode = os.stat(src_path).st_mode
print(mode)
if S_ISDIR(mode):
# It's a directory
print "os.mkdir(%s)" % (trg)
dst_f = os.path.join(trg,f)
os.mkdir(dst_f)
tree_copy_with_meta_maker(src,trg,f)
elif S_ISREG(mode):
print (path)
print "shutil.copy(%s,%s)" % (src,trg)
target_f = os.path.join(trg,f)
meta_f = os.path.join(target,f)
shutil.copy(src_path,target_f)
meta_maker(src_path,meta_f)
else:
# Unknown file type, print a message
print('Skipping %s' % pathname)
'''tree_copy("/home/kmm/Plocha/source/","/home/kmm/Plocha/target/zaloha","")'''
tree_copy_with_meta_maker("/home/kmm/Plocha/source/","/home/kmm/Plocha/target/zaloha","")
x = hash_file_names("/home/kmm/Plocha/target/zaloha/subor1.pkl")
print (x)
os.renames("/home/kmm/Plocha/target/zaloha/subor1.pkl",x)