@@ -24,6 +24,7 @@ def main():
24
24
parser .add_argument ('--print' , '-P' , action = 'store_true' , default = False , help = 'Whether to print to stdout.' )
25
25
parser .add_argument ('--depth' , '-d' , type = int , default = 0 , help = 'Set cutoff depth.' )
26
26
parser .add_argument ('--root' , '-r' , type = str , default = '/' , help = 'Set base root dir.' )
27
+ parser .add_argument ('--human' , action = 'store_true' , default = False , help = 'Make size human readable.' )
27
28
parser .add_argument ('path' , type = str , default = '' , help = 'Path' , nargs = '?' )
28
29
arguments = parser .parse_args ()
29
30
app (arguments )
@@ -39,19 +40,19 @@ def app(args):
39
40
print ('See: index-generator --help' )
40
41
sys .exit (0 )
41
42
if args .no_recursive :
42
- generate_once (args .template , args .path , os .listdir (args .path ), args .name , args .print , base = args .root )
43
+ generate_once (args .template , args .path , os .listdir (args .path ), args .name , args .print , base = args .root , human = args . human )
43
44
else :
44
- generate_recursively (args .template , args .path , args .name , args .print , args .depth , base = args .root )
45
+ generate_recursively (args .template , args .path , args .name , args .print , args .depth , base = args .root , human = args . human )
45
46
46
47
47
- def generate_once (template_dir , root , files , name , if_print , base = '/' ):
48
+ def generate_once (template_dir , root , files , name , if_print , base = '/' , human = False ):
48
49
environment = jinja2 .Environment (
49
50
loader = jinja2 .PackageLoader ('index_generator' , template_dir ),
50
51
autoescape = jinja2 .select_autoescape (['html' , 'htm' ])
51
52
)
52
53
template = environment .get_template (name )
53
54
54
- entries = list (map (lambda f1 : Entry (f1 , root , base = base ), files ))
55
+ entries = list (map (lambda f1 : Entry (f1 , root , base = base , human = human ), files ))
55
56
# entries.sort(key=lambda x: x.isDir, reverse=True)
56
57
57
58
filelist = []
@@ -83,7 +84,7 @@ def generate_once(template_dir, root, files, name, if_print, base='/'):
83
84
print (html , file = f )
84
85
85
86
86
- def generate_recursively (template_dir , path , name , if_print , max_depth = 0 , base = '/' ):
87
+ def generate_recursively (template_dir , path , name , if_print , max_depth = 0 , base = '/' , human = False ):
87
88
for root , dirs , files in os .walk (path ):
88
89
if max_depth != 0 and root .count (os .sep ) >= max_depth :
89
90
dirs .clear ()
@@ -99,7 +100,7 @@ def generate_recursively(template_dir, path, name, if_print, max_depth=0, base='
99
100
print ('files: {}' .format (files ))
100
101
print ('-----------------------------------------' )
101
102
102
- generate_once (template_dir , root , dirs + files , name , if_print , base = base )
103
+ generate_once (template_dir , root , dirs + files , name , if_print , base = base , human = human )
103
104
104
105
105
106
if __name__ == '__main__' :
0 commit comments