Add file compression
This commit is contained in:
parent
e327a1ff35
commit
4f4e464843
2
TODO
2
TODO
|
@ -4,7 +4,7 @@ doc auto generation
|
|||
doc enhancement
|
||||
Limit hits/pages/downloads by rate
|
||||
Automatic tests
|
||||
quiet mode
|
||||
Add Licence
|
||||
Free memory as soon as possible
|
||||
gzip output files
|
||||
different debug output levels
|
2
conf.py
2
conf.py
|
@ -24,3 +24,5 @@ hit_to_page_conf = [r'^.+/category/.+$', r'^.+/tag/.+$', r'^.+/archive/.+$', r'^
|
|||
# Because it's too long to build HTML when there is too much entries
|
||||
max_hits_displayed = 100
|
||||
max_downloads_displayed = 100
|
||||
|
||||
compress_output_files = ['html', 'css', 'js']
|
||||
|
|
|
@ -48,3 +48,6 @@ resources_path = ['resources']
|
|||
icon_path = '%s/%s' % (os.path.basename(resources_path[0]), 'icon')
|
||||
# CSS path (you can add yours)
|
||||
css_path = ['%s/%s/%s' % (os.path.basename(resources_path[0]), 'css', 'iwla.css')]
|
||||
|
||||
# Extensions to compress in gzip during display build
|
||||
compress_output_files = []
|
||||
|
|
25
iwla.py
25
iwla.py
|
@ -31,6 +31,7 @@ from display import *
|
|||
# Conf values needed :
|
||||
# analyzed_filename
|
||||
# domain_name
|
||||
# compress_output_files*
|
||||
#
|
||||
# Output files :
|
||||
# DB_ROOT/meta.db
|
||||
|
@ -40,7 +41,7 @@ from display import *
|
|||
#
|
||||
# Statistics creation :
|
||||
#
|
||||
# meta =>
|
||||
# meta :
|
||||
# last_time
|
||||
# start_analysis_time
|
||||
# stats =>
|
||||
|
@ -441,11 +442,33 @@ class IWLA(object):
|
|||
|
||||
self.display.addPage(page)
|
||||
|
||||
def _compressFile(self, build_time, root, filename):
|
||||
path = os.path.join(root, filename)
|
||||
gz_path = path + '.gz'
|
||||
#print 'Compress %s => %s' % (path, gz_path)
|
||||
if not os.path.exists(gz_path) or\
|
||||
os.stat(filename).st_mtime > build_time:
|
||||
with open(path, 'rb') as f_in:
|
||||
with gzip.open(gz_path, 'wb') as f_out:
|
||||
f_out.write(f_in.read())
|
||||
|
||||
def _compressFiles(self, build_time, root):
|
||||
if not conf.compress_output_files: return
|
||||
print root
|
||||
for rootdir, subdirs, files in os.walk(root, followlinks=True):
|
||||
for f in files:
|
||||
for ext in conf.compress_output_files:
|
||||
if f.endswith(ext):
|
||||
self._compressFile(build_time, rootdir, f)
|
||||
break
|
||||
|
||||
def _generateDisplay(self):
|
||||
self._generateDisplayDaysStats()
|
||||
self._callPlugins(conf.DISPLAY_HOOK_DIRECTORY)
|
||||
self._generateDisplayWholeMonthStats()
|
||||
build_time = time.localtime()
|
||||
self.display.build(conf.DISPLAY_ROOT)
|
||||
self._compressFiles(build_time, conf.DISPLAY_ROOT)
|
||||
|
||||
def _createEmptyStats(self):
|
||||
stats = {}
|
||||
|
|
Loading…
Reference in New Issue
Block a user