Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 50 additions & 7 deletions mfr/extensions/zip/render.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import os
import zipfile

import markupsafe
from mako.lookup import TemplateLookup

from mfr.core import extension
Expand All @@ -17,15 +16,55 @@ class ZipRenderer(extension.BaseRenderer):

def render(self):
zip_file = zipfile.ZipFile(self.file_path, 'r')
files = [file for file in zip_file.filelist if not file.filename.startswith('__MACOSX')]

filelist = [{'name': markupsafe.escape(file.filename),
'size': sizeof_fmt(int(file.file_size)),
'date': "%d-%02d-%02d %02d:%02d:%02d" % file.date_time[:6]} for file in zip_file.filelist
if not file.filename.startswith('__MACOSX')]
data = self.filelist_to_tree(files)

message = '' if filelist else 'This zip file is empty.'
return self.TEMPLATE.render(data=data, base=self.assets_url)

return self.TEMPLATE.render(zipped_filenames=filelist, message=message)
def filelist_to_tree(self, files):

self.icons_url = self.assets_url + '/img'

tree_data = [{
'text': self.metadata.name + self.metadata.ext,
'icon': self.icons_url + '/file_extension_zip.png',
'children': []
}]

for file in files:
node_path = tree_data[0]
paths = [path for path in file.filename.split('/') if path]
for path in paths:
if not len(node_path['children']) or node_path['children'][-1]['text'] != path:
# Add a child
new_node = {'text': path, 'children': []}

if new_node['text']: # If not a placeholder/"root" directory.
date = '%d-%02d-%02d %02d:%02d:%02d' % file.date_time[:6]
size = sizeof_fmt(int(file.file_size)) if file.file_size else ''

# create new node
new_node['data'] = {'date': date, 'size': size}

if file.filename[-1] == '/':
new_node['icon'] = self.icons_url + '/folder.png'
else:
ext = os.path.splitext(file.filename)[1].lstrip('.')
if check_icon_ext(ext):
new_node['icon'] = \
self.icons_url + '/file_extension_{}.png'.format(ext)
else:
new_node['icon'] = self.icons_url + '/generic-file.png'

node_path['children'].append(new_node)

node_path = new_node
else:
# "go deeper" to get children of children.
node_path = node_path['children'][-1]

return tree_data

@property
def file_required(self):
Expand All @@ -34,3 +73,7 @@ def file_required(self):
@property
def cache_result(self):
return True

def check_icon_ext(ext):
return os.path.isfile(os.path.join(os.path.dirname(__file__), 'static', 'img', 'icons',
'file_extension_{}.png'.format(ext)))
Empty file.
Binary file added mfr/extensions/zip/static/img/delete.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added mfr/extensions/zip/static/img/file_extension_3gp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added mfr/extensions/zip/static/img/file_extension_7z.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added mfr/extensions/zip/static/img/file_extension_ace.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added mfr/extensions/zip/static/img/file_extension_ai.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added mfr/extensions/zip/static/img/file_extension_aif.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added mfr/extensions/zip/static/img/file_extension_amr.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added mfr/extensions/zip/static/img/file_extension_asf.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added mfr/extensions/zip/static/img/file_extension_asx.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added mfr/extensions/zip/static/img/file_extension_bat.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added mfr/extensions/zip/static/img/file_extension_bin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added mfr/extensions/zip/static/img/file_extension_bmp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added mfr/extensions/zip/static/img/file_extension_bup.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added mfr/extensions/zip/static/img/file_extension_cab.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added mfr/extensions/zip/static/img/file_extension_cbr.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added mfr/extensions/zip/static/img/file_extension_cda.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added mfr/extensions/zip/static/img/file_extension_cdl.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added mfr/extensions/zip/static/img/file_extension_cdr.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added mfr/extensions/zip/static/img/file_extension_chm.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added mfr/extensions/zip/static/img/file_extension_dat.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added mfr/extensions/zip/static/img/file_extension_dll.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added mfr/extensions/zip/static/img/file_extension_dmg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added mfr/extensions/zip/static/img/file_extension_doc.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added mfr/extensions/zip/static/img/file_extension_dss.png
Binary file added mfr/extensions/zip/static/img/file_extension_dvf.png
Binary file added mfr/extensions/zip/static/img/file_extension_dwg.png
Binary file added mfr/extensions/zip/static/img/file_extension_eml.png
Binary file added mfr/extensions/zip/static/img/file_extension_eps.png
Binary file added mfr/extensions/zip/static/img/file_extension_exe.png
Binary file added mfr/extensions/zip/static/img/file_extension_fla.png
Binary file added mfr/extensions/zip/static/img/file_extension_flv.png
Binary file added mfr/extensions/zip/static/img/file_extension_gif.png
Binary file added mfr/extensions/zip/static/img/file_extension_gz.png
Binary file added mfr/extensions/zip/static/img/file_extension_hqx.png
Binary file added mfr/extensions/zip/static/img/file_extension_htm.png
Binary file added mfr/extensions/zip/static/img/file_extension_ifo.png
Binary file added mfr/extensions/zip/static/img/file_extension_iso.png
Binary file added mfr/extensions/zip/static/img/file_extension_jar.png
Binary file added mfr/extensions/zip/static/img/file_extension_jpg.png
Binary file added mfr/extensions/zip/static/img/file_extension_lnk.png
Binary file added mfr/extensions/zip/static/img/file_extension_log.png
Binary file added mfr/extensions/zip/static/img/file_extension_m4a.png
Binary file added mfr/extensions/zip/static/img/file_extension_m4b.png
Binary file added mfr/extensions/zip/static/img/file_extension_m4p.png
Binary file added mfr/extensions/zip/static/img/file_extension_m4v.png
Binary file added mfr/extensions/zip/static/img/file_extension_mcd.png
Binary file added mfr/extensions/zip/static/img/file_extension_mdb.png
Binary file added mfr/extensions/zip/static/img/file_extension_mid.png
Binary file added mfr/extensions/zip/static/img/file_extension_mov.png
Binary file added mfr/extensions/zip/static/img/file_extension_mp2.png
Binary file added mfr/extensions/zip/static/img/file_extension_mp3.png
Binary file added mfr/extensions/zip/static/img/file_extension_mp4.png
Binary file added mfr/extensions/zip/static/img/file_extension_mpg.png
Binary file added mfr/extensions/zip/static/img/file_extension_msi.png
Binary file added mfr/extensions/zip/static/img/file_extension_ogg.png
Binary file added mfr/extensions/zip/static/img/file_extension_pdf.png
Binary file added mfr/extensions/zip/static/img/file_extension_png.png
Binary file added mfr/extensions/zip/static/img/file_extension_pps.png
Binary file added mfr/extensions/zip/static/img/file_extension_ps.png
Binary file added mfr/extensions/zip/static/img/file_extension_psd.png
Binary file added mfr/extensions/zip/static/img/file_extension_pst.png
Binary file added mfr/extensions/zip/static/img/file_extension_ptb.png
Binary file added mfr/extensions/zip/static/img/file_extension_pub.png
Binary file added mfr/extensions/zip/static/img/file_extension_qbb.png
Binary file added mfr/extensions/zip/static/img/file_extension_qbw.png
Binary file added mfr/extensions/zip/static/img/file_extension_qxd.png
Binary file added mfr/extensions/zip/static/img/file_extension_ram.png
Binary file added mfr/extensions/zip/static/img/file_extension_rar.png
Binary file added mfr/extensions/zip/static/img/file_extension_rm.png
Binary file added mfr/extensions/zip/static/img/file_extension_rtf.png
Binary file added mfr/extensions/zip/static/img/file_extension_sea.png
Binary file added mfr/extensions/zip/static/img/file_extension_ses.png
Binary file added mfr/extensions/zip/static/img/file_extension_sit.png
Binary file added mfr/extensions/zip/static/img/file_extension_ss.png
Binary file added mfr/extensions/zip/static/img/file_extension_swf.png
Binary file added mfr/extensions/zip/static/img/file_extension_tgz.png
Binary file added mfr/extensions/zip/static/img/file_extension_thm.png
Binary file added mfr/extensions/zip/static/img/file_extension_tif.png
Binary file added mfr/extensions/zip/static/img/file_extension_tmp.png
Binary file added mfr/extensions/zip/static/img/file_extension_ttf.png
Binary file added mfr/extensions/zip/static/img/file_extension_txt.png
Binary file added mfr/extensions/zip/static/img/file_extension_vcd.png
Binary file added mfr/extensions/zip/static/img/file_extension_vob.png
Binary file added mfr/extensions/zip/static/img/file_extension_wav.png
Binary file added mfr/extensions/zip/static/img/file_extension_wma.png
Binary file added mfr/extensions/zip/static/img/file_extension_wmv.png
Binary file added mfr/extensions/zip/static/img/file_extension_wps.png
Binary file added mfr/extensions/zip/static/img/file_extension_xls.png
Binary file added mfr/extensions/zip/static/img/file_extension_xpi.png
Binary file added mfr/extensions/zip/static/img/file_extension_zip.png
Binary file added mfr/extensions/zip/static/img/folder.png
Binary file added mfr/extensions/zip/static/img/folder_delete.png
Binary file added mfr/extensions/zip/static/img/generic-file.png
4 changes: 4 additions & 0 deletions mfr/extensions/zip/static/js/jstree.min.js

Large diffs are not rendered by default.

Loading