forked from KEMMY/BC-2012
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_dict.py
49 lines (33 loc) · 1.17 KB
/
make_dict.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
import pickle
import hashlib
import os
import sys
from stat import *
import shutil
ef pickluj(src_dict,path):
path += ".pkl"
pkl_file = open(path,"wb")
str_dict = str(src_dict)
# x = hashlib.sha1(str_dict) can't pickle HASH objects
pickle.dump(str_dict,pkl_file)
pkl_file.close()
#os.renames(path,file_name)??? tento posledny krok nefunguje nechapem chybe interpretra
# Skuska dict to string pomocov pikle
def make_dict(src):
src_dict = {}
for F in os.listdir(src):
nextpath = os.path.join(src,F)
mode = os.stat(nextpath).st_mode
if S_ISREG(mode):
stat = os.stat(nextpath)
typ = "Blob"
file_name = os.path.basename(nextpath)
hash_file_name = hashlib.sha1(file_name) #iba skuska hashovania nazvu
value = str(mode) +" "+ typ + " " + str(hash_file_name) + " " + file_name
src_dict[file_name] = value
else:
# Directory or Unknown file type, print a message
print('Skipping %s' % nextpath)
pickluj(src_dict,src)
print (src_dict)
make_dict('/home/kmm/Plocha/source')