|
@ -68,6 +68,17 @@ def div(args, type_, subtype, tag, name): |
|
|
return html.format(id_name, subtype, tag) |
|
|
return html.format(id_name, subtype, tag) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def check_distribusi_index(args, index): |
|
|
|
|
|
|
|
|
|
|
|
with open(index, 'r') as f: |
|
|
|
|
|
if '<meta name="generator" content="distribusi" />' in f.read(): |
|
|
|
|
|
return True |
|
|
|
|
|
else: |
|
|
|
|
|
if args.verbose: |
|
|
|
|
|
print(index, 'not generated by distribusi, skipping') |
|
|
|
|
|
return False |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def distribusify(args, directory): # noqa |
|
|
def distribusify(args, directory): # noqa |
|
|
for root, dirs, files in os.walk(directory): |
|
|
for root, dirs, files in os.walk(directory): |
|
|
|
|
|
|
|
@ -76,8 +87,6 @@ def distribusify(args, directory): # noqa |
|
|
print('Excluding directory:', ", ".join(args.exclude_directory)) |
|
|
print('Excluding directory:', ", ".join(args.exclude_directory)) |
|
|
dirs[:] = [d for d in dirs if d not in args.exclude_directory] |
|
|
dirs[:] = [d for d in dirs if d not in args.exclude_directory] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if not args.remove_index: |
|
|
if not args.remove_index: |
|
|
html = [] |
|
|
html = [] |
|
|
|
|
|
|
|
@ -141,28 +150,34 @@ def distribusify(args, directory): # noqa |
|
|
a = "<a href='{}'>{}/</a>".replace('{}', name) |
|
|
a = "<a href='{}'>{}/</a>".replace('{}', name) |
|
|
html.append(div(args, 'dir', 'dir', a, 'folder')) |
|
|
html.append(div(args, 'dir', 'dir', a, 'folder')) |
|
|
|
|
|
|
|
|
with open(os.path.join(root, 'index.html'), 'w') as f: |
|
|
index = os.path.join(root, 'index.html') |
|
|
if not args.no_template: |
|
|
if os.path.exists(index): |
|
|
if args.style: |
|
|
if check_distribusi_index(args, index): |
|
|
fs = open(args.style, "r") |
|
|
pass |
|
|
style = fs.read() |
|
|
else: |
|
|
styled_html_head = html_head % style |
|
|
with open(os.path.join(root, 'index.html'), 'w') as f: |
|
|
else: |
|
|
if not args.no_template: |
|
|
styled_html_head = html_head % '' |
|
|
if args.style: |
|
|
f.write(styled_html_head) |
|
|
fs = open(args.style, "r") |
|
|
|
|
|
style = fs.read() |
|
|
for line in html: |
|
|
styled_html_head = html_head % style |
|
|
f.write(line + '\n') |
|
|
else: |
|
|
|
|
|
styled_html_head = html_head % '' |
|
|
if not args.no_template: |
|
|
f.write(styled_html_head) |
|
|
f.write(html_footer) |
|
|
|
|
|
|
|
|
for line in html: |
|
|
|
|
|
f.write(line + '\n') |
|
|
|
|
|
|
|
|
|
|
|
if not args.no_template: |
|
|
|
|
|
f.write(html_footer) |
|
|
|
|
|
|
|
|
if args.remove_index: |
|
|
if args.remove_index: |
|
|
index = os.path.join(root, 'index.html') |
|
|
index = os.path.join(root, 'index.html') |
|
|
if 'index.html' in files: |
|
|
if 'index.html' in files: |
|
|
if args.verbose: |
|
|
|
|
|
print('Removing index.html from', root) |
|
|
|
|
|
try: |
|
|
try: |
|
|
os.remove(index) |
|
|
if check_distribusi_index(args, index): |
|
|
|
|
|
if args.verbose: |
|
|
|
|
|
print('Removing index.html from', root) |
|
|
|
|
|
os.remove(index) |
|
|
except Exception as e: |
|
|
except Exception as e: |
|
|
print(e) |
|
|
print(e) |
|
|