-
Notifications
You must be signed in to change notification settings - Fork 0
/
blinding.py
72 lines (34 loc) · 1.36 KB
/
blinding.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
71
72
#!/usr/bin/env python
import glob, os, shutil, datetime, getpass
from random import shuffle
import tkinter, tkinter.filedialog
root = tkinter.Tk()
dirname = tkinter.filedialog.askdirectory(parent=root,initialdir="/",title='Please select a directory')
if len(dirname) > 0:
print ("You chose %s" % dirname)
files = glob.glob("%s/*"%dirname)
if len(files) > 0:
print ("Which contains %s files" % len(files))
n_file = list(range(1, len(files)+1))
shuffle(n_file)
# new directory for blinded files
blind_dir = "%s_blinded"%dirname
os.mkdir(blind_dir)
print ("New directory for blinded files is %s"%blind_dir)
# open write file for blinded list
now = datetime.datetime.now()
blind_list = open("%s/blinded_file_list.txt"%blind_dir, 'w')
blind_list.write("Files blinded by %s at %d:%d on date %d %d %d\n"%(getpass.getuser(), now.hour, now.minute, now.year, now.month, now.day))
blind_list.write("blinded file\toriginal file\n")
# loop
print ("Blinding files...")
for i in list(range(len(files))):
print ("%s / %s"%(i+1, len(files)))
# new blinded file name
b_fnm = "%s/%s.%s"%(blind_dir,n_file[i],files[i].split('.')[-1])
# write into blinded list
blind_list.write("%s\t%s\n"%(b_fnm,files[i]))
# copy file to blinded directory, with blinded file name
shutil.copyfile(files[i], b_fnm)
blind_list.close()
print ("Finished.")