...
[iramuteq] / webexport.py
1 import codecs
2 from shutil import copyfile
3 import os
4 from chemins import PathOut
5
6
7
8 class WebExport :
9     def __init__(self, parent, parametres) :
10         self.parent = parent
11         self.parametres = parametres
12         self.jspathin = os.path.join(self.parent.AppliPath, 'webexport','js')
13         self.csspathin = os.path.join(self.parent.AppliPath, 'webexport', 'css')
14         self.imgpathin = os.path.join(self.parent.AppliPath, 'webexport', 'images')
15         if not 'dirout' in self.parametres :
16             self.pathout = PathOut(filename = self.parametres['gexffile'], analyse_type='webexport')
17             dirout = self.pathout.mkdirout()
18             self.pathout.dirout = dirout
19         else :
20             self.pathout = PathOut(dirout = self.parametres['dirout'])
21         self.makedirout()
22
23     def makedirout(self) :
24         jss = os.listdir(self.jspathin)
25         css = os.listdir(self.csspathin)
26         img = os.listdir(self.imgpathin)
27         jspathout = os.path.join(self.pathout.dirout, 'js')
28         cssout =  os.path.join(self.pathout.dirout, 'css')
29         imgout = os.path.join(self.pathout.dirout, 'images')
30         os.makedirs(jspathout)
31         os.makedirs(cssout)
32         os.makedirs(imgout)
33         for f in jss :
34             copyfile(os.path.join(self.jspathin, f), os.path.join(jspathout, f))
35         for f in css :
36             copyfile(os.path.join(self.csspathin, f), os.path.join(cssout, f))
37         for f in img :
38             copyfile(os.path.join(self.imgpathin, f), os.path.join(imgout, f))
39
40     def exportafc(self) :
41         copyfile(self.parametres['gexffile'], os.path.join(self.pathout.dirout, os.path.basename(self.parametres['gexffile'])))
42         afcfile = os.path.join(self.parent.AppliPath, 'webexport', 'afc.html')
43         afcout = os.path.join(self.pathout.dirout, 'afc.html')
44         with codecs.open(afcfile, 'r', 'utf8') as f :
45             content = f.read()
46         self.parametres['gexffile'] = os.path.basename(self.parametres['gexffile'])
47         content = content % self.parametres
48         with open(afcout, 'w') as f :
49             f.write(content)
50         return afcout
51         
52     def exportsimi(self) :
53         simifile = os.path.join(self.parent.AppliPath, 'webexport', 'graphe.html')
54         simiout = os.path.join(self.pathout.dirout, 'graphe.html')
55         with codecs.open(simifile, 'r', 'utf8') as f :
56             content = f.read()
57         self.parametres['gexffile'] = os.path.basename(self.parametres['gexffile'])
58         content = content % self.parametres
59         with open(simiout, 'w') as f :
60             f.write(content)
61         return simiout             
62