|
|
@ -69,7 +69,11 @@ def div(args, type_, subtype, tag, name): |
|
|
|
|
|
|
|
|
|
|
|
def check_distribusi_index(args, index): |
|
|
|
""" |
|
|
|
check whether a index.html file is generated by distribusi |
|
|
|
""" |
|
|
|
|
|
|
|
if not args.force: |
|
|
|
with open(index, 'r') as f: |
|
|
|
if '<meta name="generator" content="distribusi" />' in f.read(): |
|
|
|
return True |
|
|
@ -77,6 +81,25 @@ def check_distribusi_index(args, index): |
|
|
|
if args.verbose: |
|
|
|
print(index, 'not generated by distribusi, skipping') |
|
|
|
return False |
|
|
|
elif args.force: |
|
|
|
return True |
|
|
|
|
|
|
|
def write_index(args,index, html, html_head, html_footer): |
|
|
|
with open(index, 'w') as f: |
|
|
|
if not args.no_template: |
|
|
|
if args.style: |
|
|
|
fs = open(args.style, "r") |
|
|
|
style = fs.read() |
|
|
|
styled_html_head = html_head % style |
|
|
|
else: |
|
|
|
styled_html_head = html_head % '' |
|
|
|
f.write(styled_html_head) |
|
|
|
|
|
|
|
for line in html: |
|
|
|
f.write(line + '\n') |
|
|
|
|
|
|
|
if not args.no_template: |
|
|
|
f.write(html_footer) |
|
|
|
|
|
|
|
|
|
|
|
def distribusify(args, directory): # noqa |
|
|
@ -153,23 +176,11 @@ def distribusify(args, directory): # noqa |
|
|
|
index = os.path.join(root, 'index.html') |
|
|
|
if os.path.exists(index): |
|
|
|
if check_distribusi_index(args, index): |
|
|
|
pass |
|
|
|
else: |
|
|
|
with open(os.path.join(root, 'index.html'), 'w') as f: |
|
|
|
if not args.no_template: |
|
|
|
if args.style: |
|
|
|
fs = open(args.style, "r") |
|
|
|
style = fs.read() |
|
|
|
styled_html_head = html_head % style |
|
|
|
else: |
|
|
|
styled_html_head = html_head % '' |
|
|
|
f.write(styled_html_head) |
|
|
|
write_index(args,index,html, html_head, html_footer) |
|
|
|
elif not os.path.exists(index): |
|
|
|
write_index(args,index,html, html_head, html_footer) |
|
|
|
|
|
|
|
for line in html: |
|
|
|
f.write(line + '\n') |
|
|
|
|
|
|
|
if not args.no_template: |
|
|
|
f.write(html_footer) |
|
|
|
|
|
|
|
if args.remove_index: |
|
|
|
index = os.path.join(root, 'index.html') |
|
|
|