Browse Source

cleaning class names for css, fixing video, attribution in template

package-it-up
RRA 8 years ago
parent
commit
16a0577026
  1. 12
      distribusi.py
  2. 2
      page_template.py

12
distribusi.py

@ -24,16 +24,17 @@ else:
mime_type = magic.Magic(mime=True)
file_types = {'image':'<img class="image" src="{}"></img>', 'pdf':'<a href="{}" class="pdf">{}</a>',
'text':'<a href="{}" class="text">{}</a>', 'video':'<video class="video" src="{}"></video>', 'audio':'<audio controls class="audio"> <source src="{}"></source></audio>','html':'<a href="{}">{}</a>'}
'text':'<a href="{}" class="text">{}</a>', 'video':'<video class="video" controls><source src="{}"></source></video>', 'audio':'<audio controls class="audio"> <source src="{}"></source></audio>','html':'<a href="{}">{}</a>'}
def dict_by_value(dictionary, value):
return(list(dictionary.keys())[list(dictionary.values()).index(value)]) # returns the key for the given value
def div(mime, tag, *values):
#name, full_path
class_name = values[0].split('.')[0].replace(' ', '_')
if 'image' in mime:
html ='<div class="{}">'.format(values[0])+tag+'</br><span class="filename">{}</span></div>'.format(values[0])
html ='<div class="{}">'.format(class_name)+tag+'</br><span class="filename">{}</span></div>'.format(values[0])
else:
html = '<div class="{}">'.format(values[0])+tag+'</div>'.format(values[0])
html = '<div class="{}">'.format(class_name)+tag+'</div>'.format(values[0])
return html
for root, dirs, files in os.walk(directory):
@ -48,6 +49,9 @@ for root, dirs, files in os.walk(directory):
mime = mime_type.from_file(full_path)
mime, format = mime.split('/') #example: text plain
if args.verbose:
print(mime, format)
if mime in file_types:
if name.endswith('.html'):
a = open(full_path).read()
@ -60,7 +64,7 @@ for root, dirs, files in os.walk(directory):
if mime not in file_types and format not in file_types: #to catch exceptions we haven't defined in file_types before
a = "<a href='{}'>{}</a>"
if args.verbose:
print ('Unrecognized mime-type: \n', mime,format, name)
print ('mime-type not in list, adding as href: \n', mime,format, name)
a = a.replace('{}',name)
html.append(div(mime,a,name))

2
page_template.py

@ -4,10 +4,12 @@ html_head = """
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Generated with distribusi http://git.homebrewserver.club/distribusi/log.html -->
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<style>
.image{max-width: 100%;}
div{width: 640px;float:left;}
video {width:640px;}
.dir::before{content:"📁";font-size:18px;}
</style>
</head>

Loading…
Cancel
Save