-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsteam_watch.py
More file actions
100 lines (78 loc) · 2.38 KB
/
steam_watch.py
File metadata and controls
100 lines (78 loc) · 2.38 KB
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
import platform
import os
import subprocess
import time
import math
from os.path import join, getsize
interval_sec = 60
# items in dirs appear in the menu as quick options
# leave the list empty to skip options and input manually
dirs = [
{
'name': 'C:\\SteamLibrary',
'path': 'C:\\Program Files (x86)\\Steam\\steamapps\\downloading'
},
{
'name': 'E:\\SteamLibrary',
'path': 'E:\\Games\\SteamLibrary\\steamapps\\downloading'
}
]
def get_dir_size(path):
total = 0
for root, dirs, files in os.walk(path):
for name in files:
total += getsize(join(root, name))
return total
def shutdown():
plat = platform.system()
print('Shutting down...')
if plat is 'Windows':
subprocess.call(['shutdown', '/s'])
elif plat is 'Linux':
subprocess.call(['shutdown', '-h', 'now'])
def wait(path, is_downloading=True):
if(is_downloading):
time.sleep(interval_sec)
size = get_dir_size(path)
if size != 0:
print('Still downloading... current size: {} GB'
.format(round(size / math.pow(1024, 3), 2)))
wait(path)
else:
print('Download finished!')
shutdown()
def custom():
path = input('\nDirectory to watch: ')
if os.path.exists(path) and os.path.isdir(path):
print('Watching directory: {}'.format(path))
wait(path)
else:
print('\n\n\tNot a directory: {}\n\n\tPlease check it exists!'.format(path))
prompt()
def prompt():
if len(dirs) == 0:
custom()
else:
msg = '\n\t[0] Custom'
for key, val in enumerate(dirs):
msg += '\n\t[{}] {}'.format(key + 1, val['name'])
msg += '\n\nPick a number: '
choice = input(msg)
try:
choice = int(choice)
if choice < 0 or choice > len(dirs):
print('Invalid choice: {}'.format(choice))
prompt()
else:
path = ''
if choice is 0:
custom()
else:
path = dirs[choice - 1]['path']
print('Watching directory: {}'.format(path))
wait(path)
except:
print('\n\n\tInvalid choice: {}\n\nChoose again...'.format(choice))
prompt()
if __name__ == "__main__":
prompt()