-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
107 lines (92 loc) · 2.69 KB
/
main.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import os
import ctypes
import sys
nope = ["System Volume Information","$RECYCLE.BIN"]
dirs = ["d","e","f","g"]
insert_dirs = ["H:\\downloads\\Complete\\..done\\"]
def getFolderSize(folder):
total_size = os.path.getsize(folder)
for item in os.listdir(folder):
itempath = os.path.join(folder, item)
if os.path.isfile(itempath):
total_size += os.path.getsize(itempath)
elif os.path.isdir(itempath):
total_size += getFolderSize(itempath)
return total_size
def disk_usage(path):
_, total, free = ctypes.c_ulonglong(), ctypes.c_ulonglong(), \
ctypes.c_ulonglong()
if sys.version_info >= (3,) or isinstance(path, unicode):
fun = ctypes.windll.kernel32.GetDiskFreeSpaceExW
else:
fun = ctypes.windll.kernel32.GetDiskFreeSpaceExA
ret = fun(path, ctypes.byref(_), ctypes.byref(total), ctypes.byref(free))
if ret == 0:
raise ctypes.WinError()
used = total.value - free.value
return (total.value, used, free.value)
def constructSection(target_directory):
entries = {}
alpha_entries = []
for x in os.listdir(target_directory):
if x not in nope:
entries[x] = getFolderSize(target_directory+x)
alpha_entries.append(x)
return [entries,alpha_entries]
series = {}
alpha_series = []
dirs.sort()
dirs.reverse()
for x in dirs:
x += ":\\"
b = constructSection(x)
series.update(b[0])
alpha_series+=b[1]
for x in insert_dirs:
b = constructSection(x)
series.update(b[0])
alpha_series+=b[1]
alpha_series.sort()
alpha_series.reverse()
total_stored = 0
for x in series:
total_stored += series[x]
total_storage = 0
def sizeOfDirs(dirs):
total = 0
for x in dirs:
total += series[x]
return total
for x in dirs:
total_storage += disk_usage(x+":\\")[0]
finished = {}
total_per_drive = total_stored/len(dirs)
alpha_series_cur = alpha_series
for x in dirs:
this_drive = []
cont = 1
while sizeOfDirs(this_drive) < total_per_drive and cont == 1 and len(alpha_series_cur) > 0:
this_drive.append(alpha_series_cur[0])
if sizeOfDirs(this_drive) > disk_usage(x+":\\")[0]:
cont = 0
else:
alpha_series_cur = alpha_series_cur[1:]
finished[x] = this_drive
sizes = {}
for x in dirs:
sizes[x] = 0
operations = []
for x in finished:
for y in finished[x]:
if not os.path.isdir(x+":\\"+y):
operations.append((y,x))
sizes[x] += series[y]
# make this do stuff instead
for x in operations:
print x
print "To move:"
total = 0
for x in sizes:
print x,str(sizes[x]/1073741824.0)+"GB"
total += sizes[x]
print "Total:",str(total//1073741824.0)+"GB"