-
Notifications
You must be signed in to change notification settings - Fork 0
/
DiskUsage.py
40 lines (32 loc) · 1.26 KB
/
DiskUsage.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
from pathlib import Path
from DirectoryNode import DirectoryNode
from DirectorySizeVisitor import DirectorySizeVisitor
from DirectorySizeAndFileVisitor import DirectorySizeAndFileVisitor
from LineCountVisitor import LineCountVisitor
class DiskUsage(object):
def __init__(self):
self.rootDirectory = "/Users/zube/Downloads"
self.root_node = None
self.lcv = LineCountVisitor()
def scan_progress(self, current_path):
print("Scanning: {0}".format(current_path))
def build(self):
self.root_node = DirectoryNode(self.rootDirectory)
self.root_node.scan(self.scan_progress)
dsv = DirectorySizeVisitor()
dsv = DirectorySizeAndFileVisitor()
self.root_node.accept(dsv)
# todo: get scan_progress hooked up into this somehow...
self.root_node.accept(self.lcv)
self.lcv.print_results()
def run(self):
p = Path(self.rootDirectory)
directories = [x for x in p.iterdir() if x.is_dir()]
for directory in directories:
print(directory)
files = [x for x in directory.glob("*") if x.is_file()]
for theFile in files:
print(theFile)
theFile.stat().st_size
diskUsage = DiskUsage()
diskUsage.build()