-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathstats.py
More file actions
63 lines (51 loc) · 1.47 KB
/
stats.py
File metadata and controls
63 lines (51 loc) · 1.47 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
import stat
import errno
import fuse
from time import time
from subprocess import *
from common.file import File, Directory, Stat
from common.structure import Inode
def print_sep(str, sep = 0):
print "\t"*sep + str
def stat_block(block, sep = 0):
print_sep("Size: %d" % block.size, sep)
print_sep("Key: %s" % block.key, sep)
print_sep("Image: %s" % block.src, sep)
def stat_block_usage(inode, sep = 0):
if inode.exists_next_block():
print_sep("Using blocks:", sep)
else:
print_sep("Empty file", sep)
inode.rewind()
while inode.exists_next_block():
block = inode.next_block()
stat_block(block, sep+1)
def stat_file(inode, sep = 0):
if inode.is_dir():
print "ERROR: Not a file"
return
print_sep("File Name: %s" % inode.name, sep)
stat_block(inode, sep)
stat_block_usage(inode, sep)
def stat_dir(inode, pref, sep = 0):
if not inode.is_dir():
print "ERROR: Not a dir"
return
print_sep("Dir Name: %s" % inode.name, sep)
stat_block(inode, sep)
stat_block_usage(inode, sep)
print_sep("readdir:", sep)
dir = Directory(inode, prefix=pref)
for key in dir.dirs:
if key == "." or key == "..":
continue
if dir.dirs[key].is_dir():
stat_dir(dir.dirs[key], pref, sep+1)
else:
stat_file(dir.dirs[key], sep+1)
if __name__ == '__main__':
root = "block10.png"
key = "zOaV0YzkcrwUfQg1Rh_XFpZoiItuP-c4C35RvWWNkh8="
pref = "common/test_imgs/"
inode = Inode(root, key, prefix=pref)
stat_dir(inode, pref)