-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsize_cmd.py
45 lines (37 loc) · 1.2 KB
/
size_cmd.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
import os
from file_process import sub_dir_path
# Parent directory of VehSense data
parent_path = os.path.dirname(os.path.realpath(__file__))
# VehSense data directory
data_path = os.path.join(parent_path, "vehsense-backend-data")
def get_size(start_path='.'):
"""
Calculates the size of file or directory.
Args:
start_path (str): path of file or directory.
Returns:
float: size of file or directory in KB.
"""
total_size = 0
for dirpath, dirnames, filenames in os.walk(start_path):
for f in filenames:
fp = os.path.join(dirpath, f)
total_size += os.path.getsize(fp)
return total_size/float(1000)
def size_cmd(cmd):
"""
Performs the operations for the size command, i.e, displays the size of each user.
Args:
cmd (str): path of file or directory.
"""
if(cmd == "syntax"):
print("size")
elif(len(cmd) != 1):
print("Please enter correct syntax.")
else:
print(cmd)
print("Overall size: ")
print(get_size(data_path), "KB")
for subdir in sub_dir_path(data_path):
print(os.path.basename(subdir))
print("size", get_size(subdir), "KB")