From 81c3aa8099d37a0c6d73e77f2366f36e7272f9f8 Mon Sep 17 00:00:00 2001 From: Gregory Soutade Date: Sun, 30 Nov 2014 19:05:17 +0100 Subject: [PATCH] Try to manage CSS path --- default_conf.py | 11 +++++++++-- display.py | 16 +++++++++++++--- iwla.py | 14 ++++++++++---- plugins/display/all_visits.py | 2 +- plugins/display/referers.py | 4 ++-- plugins/display/top_downloads.py | 2 +- plugins/display/top_hits.py | 2 +- plugins/display/top_pages.py | 2 +- resources/icon/vh.png | Bin 0 -> 239 bytes resources/icon/vk.png | Bin 0 -> 236 bytes resources/icon/vp.png | Bin 0 -> 248 bytes resources/icon/vu.png | Bin 0 -> 239 bytes resources/icon/vv.png | Bin 0 -> 239 bytes 13 files changed, 38 insertions(+), 15 deletions(-) create mode 100644 resources/icon/vh.png create mode 100644 resources/icon/vk.png create mode 100644 resources/icon/vp.png create mode 100644 resources/icon/vu.png create mode 100644 resources/icon/vv.png diff --git a/default_conf.py b/default_conf.py index 48ce1df..1d5e1b4 100644 --- a/default_conf.py +++ b/default_conf.py @@ -1,7 +1,9 @@ +import os + # Default configuration -DB_ROOT = './output/' -DISPLAY_ROOT = './output/' +DB_ROOT = './output' +DISPLAY_ROOT = './output' HOOKS_ROOT = 'plugins' PRE_HOOK_DIRECTORY = HOOKS_ROOT + '.pre_analysis' @@ -27,3 +29,8 @@ count_hit_only_visitors = True multimedia_files = ['png', 'jpg', 'jpeg', 'gif', 'ico', 'css', 'js'] + +resources_path = ['resources'] +css_path = [os.path.join( '/', + os.path.basename(resources_path[0]), + os.path.join('css', 'iwla.css'))] diff --git a/display.py b/display.py index bcecc3c..6750309 100644 --- a/display.py +++ b/display.py @@ -140,10 +140,11 @@ class DisplayHTMLBlockTable(DisplayHTMLBlock): class DisplayHTMLPage(object): - def __init__(self, title, filename): + def __init__(self, title, filename, css_path): self.title = title self.filename = filename self.blocks = [] + self.css_path = css_path def getFilename(self): return self.filename; @@ -169,7 +170,8 @@ class DisplayHTMLPage(object): f.write('') f.write('') f.write('') - f.write('') + for css in self.css_path: + f.write('' % (css)) if self.title: f.write('%s' % (self.title)) f.write('') @@ -180,8 +182,9 @@ class DisplayHTMLPage(object): class DisplayHTMLBuild(object): - def __init__(self): + def __init__(self, iwla): self.pages = [] + self.iwla = iwla def getPage(self, filename): for page in self.pages: @@ -193,6 +196,13 @@ class DisplayHTMLBuild(object): self.pages.append(page) def build(self, root): + display_root = self.iwla.getConfValue('DISPLAY_ROOT', '') + for res_path in self.iwla.getResourcesPath(): + target = os.path.abspath(res_path) + link_name = os.path.join(display_root, res_path) + if not os.path.exists(link_name): + os.symlink(target, link_name) + for page in self.pages: page.build(root) diff --git a/iwla.py b/iwla.py index d4fff1e..5896422 100755 --- a/iwla.py +++ b/iwla.py @@ -28,7 +28,7 @@ class IWLA(object): self.analyse_started = False self.current_analysis = {} self.cache_plugins = {} - self.display = DisplayHTMLBuild() + self.display = DisplayHTMLBuild(self) self.valid_visitors = None self.log_format_extracted = re.sub(r'([^\$\w])', r'\\\g<1>', conf.log_format) @@ -89,6 +89,12 @@ class IWLA(object): cur_time = self.meta_infos['last_time'] return os.path.join(str(cur_time.tm_year), str(cur_time.tm_mon), filename) + def getResourcesPath(self): + return conf.resources_path + + def getCSSPath(self): + return conf.css_path + def _clearMeta(self): self.meta_infos = { 'last_time' : None @@ -96,7 +102,7 @@ class IWLA(object): return self.meta_infos def _clearDisplay(self): - self.display = DisplayHTMLBuild() + self.display = DisplayHTMLBuild(self) return self.display def getDBFilename(self, time): @@ -108,7 +114,7 @@ class IWLA(object): os.makedirs(base) # TODO : remove return - #return + return with open(filename + '.tmp', 'wb+') as f: pickle.dump(obj, f) @@ -232,7 +238,7 @@ class IWLA(object): title = 'Stats %d/%d' % (cur_time.tm_mon, cur_time.tm_year) filename = self.getCurDisplayPath('index.html') print '==> Generate display (%s)' % (filename) - page = DisplayHTMLPage(title, filename) + page = DisplayHTMLPage(title, filename, conf.css_path) days = DisplayHTMLBlockTable('By day', ['Day', 'Visits', 'Pages', 'Hits', 'Bandwidth', 'Not viewed Bandwidth']) days.setColsCSSClass(['', 'iwla_visit', 'iwla_page', 'iwla_hit', 'iwla_bandwidth', 'iwla_bandwidth']) diff --git a/plugins/display/all_visits.py b/plugins/display/all_visits.py index ef5e71c..42a5b3c 100644 --- a/plugins/display/all_visits.py +++ b/plugins/display/all_visits.py @@ -20,7 +20,7 @@ class IWLADisplayAllVisits(IPlugin): filename = 'all_visits.html' path = self.iwla.getCurDisplayPath(filename) - page = DisplayHTMLPage(title, path) + page = DisplayHTMLPage(title, path, self.iwla.getConfValue('css_path', [])) table = DisplayHTMLBlockTable('Last seen', ['Host', 'Pages', 'Hits', 'Bandwidth', 'Last seen']) table.setColsCSSClass(['', 'iwla_page', 'iwla_hit', 'iwla_bandwidth', '']) diff --git a/plugins/display/referers.py b/plugins/display/referers.py index 60bc154..36381bc 100644 --- a/plugins/display/referers.py +++ b/plugins/display/referers.py @@ -38,7 +38,7 @@ class IWLADisplayReferers(IPlugin): filename = 'referers.html' path = self.iwla.getCurDisplayPath(filename) - page = DisplayHTMLPage(title, path) + page = DisplayHTMLPage(title, path, self.iwla.getConfValue('css_path', [])) table = DisplayHTMLBlockTable('Connexion from', ['Origin', 'Pages', 'Hits']) table.setColsCSSClass(['', 'iwla_page', 'iwla_hit']) @@ -93,7 +93,7 @@ class IWLADisplayReferers(IPlugin): filename = 'key_phrases.html' path = self.iwla.getCurDisplayPath(filename) - page = DisplayHTMLPage(title, path) + page = DisplayHTMLPage(title, path, self.iwla.getConfValue('css_path', [])) table = DisplayHTMLBlockTable('Top key phrases', ['Key phrase', 'Search']) table.setColsCSSClass(['', 'iwla_search']) for phrase in top_key_phrases: diff --git a/plugins/display/top_downloads.py b/plugins/display/top_downloads.py index 727c138..baf6a1b 100644 --- a/plugins/display/top_downloads.py +++ b/plugins/display/top_downloads.py @@ -19,7 +19,7 @@ class IWLADisplayTopDownloads(IPlugin): path = self.iwla.getCurDisplayPath(filename) title = time.strftime('All Downloads - %B %Y', self.iwla.getCurTime()) - page = DisplayHTMLPage(title, path) + page = DisplayHTMLPage(title, path, self.iwla.getConfValue('css_path', [])) table = DisplayHTMLBlockTable('All Downloads', ['URI', 'Hit']) table.setColsCSSClass(['', 'iwla_hit']) for (uri, entrance) in top_downloads: diff --git a/plugins/display/top_hits.py b/plugins/display/top_hits.py index 9beecd1..05b74eb 100644 --- a/plugins/display/top_hits.py +++ b/plugins/display/top_hits.py @@ -19,7 +19,7 @@ class IWLADisplayTopHits(IPlugin): filename = 'top_hits.html' path = self.iwla.getCurDisplayPath(filename) - page = DisplayHTMLPage(title, path) + page = DisplayHTMLPage(title, path, self.iwla.getConfValue('css_path', [])) table = DisplayHTMLBlockTable('All Hits', ['URI', 'Entrance']) table.setColsCSSClass(['', 'iwla_hit']) for (uri, entrance) in top_hits: diff --git a/plugins/display/top_pages.py b/plugins/display/top_pages.py index bf7c907..5533166 100644 --- a/plugins/display/top_pages.py +++ b/plugins/display/top_pages.py @@ -19,7 +19,7 @@ class IWLADisplayTopPages(IPlugin): filename = 'top_pages.html' path = self.iwla.getCurDisplayPath(filename) - page = DisplayHTMLPage(title, path) + page = DisplayHTMLPage(title, path, self.iwla.getConfValue('css_path', [])) table = DisplayHTMLBlockTable('All Pages', ['URI', 'Entrance']) table.setColsCSSClass(['', 'iwla_hit']) for (uri, entrance) in top_pages: diff --git a/resources/icon/vh.png b/resources/icon/vh.png new file mode 100644 index 0000000000000000000000000000000000000000..13e52f9ef9a675349c93b1eeeef2ea1388a3bdc6 GIT binary patch literal 239 zcmeAS@N?(olHy`uVBq!ia0vp@K+MR(3?#p^TbckV{Sw!R66d1S#FEVXJcW?V+*F3F z)KWbKLoTn9*sC$qb+%OS+@4BLl<6e(pbstU$hcfKP}k$FXyY=dL+De_#Fo z|D5mtTb{o!zV|%&+P$D-=M1;*WmvkFVagPNwQD^ta>oF*2za_UhE&{2P6#RUeIHW` Yw7Z?@X!#7GUZ5OmdKI;Vst0F_-zU;qFB literal 0 HcmV?d00001 diff --git a/resources/icon/vk.png b/resources/icon/vk.png new file mode 100644 index 0000000000000000000000000000000000000000..ac1bc63b7f1b1566abc0986fc6a8d5f0c70aff44 GIT binary patch literal 236 zcmeAS@N?(olHy`uVBq!ia0vp@K+MR(3?#p^TbckV{Sw!R66d1S#FEVXJcW?V+*F3F z)KWbKLoi7I;J!Gca&{0AWU_H6}BFf-LEdzK#qG8~eHcB(eheDgizrt_%%<3>{$%3kp@Y z&aq#;NN>qh;i}1Cxn#wzK_`}!@!=$ Vv?lgUttn8B!PC{xWt~$(695VHJjDP2 literal 0 HcmV?d00001 diff --git a/resources/icon/vp.png b/resources/icon/vp.png new file mode 100644 index 0000000000000000000000000000000000000000..8ebf70216123ac0fd386005e511f20f42be2d5ca GIT binary patch literal 248 zcmeAS@N?(olHy`uVBq!ia0vp@K+MR(3?#p^TbckV{Sw!R66d1S#FEVXJcW?V+*F3F z)KWbKLo*8o|0J>k`33<#A+8)==M=V@SoV21sUuG2GF=Z-H zdhh`##981GS*8o|0J>k`RV~aA+DEChTJ%o^5SmQ z=V$Xizg_q8@#4pKXWYBqclm7diG6wdw)(G|<-c!TPZ!6Kid)GEA!WYr cV`^m>*!!5ylr{#t0p%DxUHx3vIVCg!0ItzYF#rGn literal 0 HcmV?d00001