new spanish dictionary
[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         if not 'dirout' in self.parametres :
15             self.pathout = PathOut(filename = self.parametres['gexffile'], analyse_type='webexport')
16             dirout = self.pathout.mkdirout()
17             self.pathout.dirout = dirout
18         else :
19             self.pathout = PathOut(dirout = self.parametres['dirout'])
20         self.makedirout()
21
22     def makedirout(self) :
23         jss = os.listdir(self.jspathin)
24         css = os.listdir(self.csspathin)
25         jspathout = os.path.join(self.pathout.dirout, 'js')
26         cssout =  os.path.join(self.pathout.dirout, 'css')
27         os.makedirs(jspathout)
28         os.makedirs(cssout)
29         for f in jss :
30             copyfile(os.path.join(self.jspathin, f), os.path.join(jspathout, f))
31         for f in css :
32             copyfile(os.path.join(self.csspathin, f), os.path.join(cssout, f))
33
34     def exportafc(self) :
35         copyfile(self.parametres['gexffile'], os.path.join(self.pathout.dirout, os.path.basename(self.parametres['gexffile'])))
36         afcfile = os.path.join(self.parent.AppliPath, 'webexport', 'afc.html')
37         afcout = os.path.join(self.pathout.dirout, 'afc.html')
38         with codecs.open(afcfile, 'r', 'utf8') as f :
39             content = f.read()
40         self.parametres['gexffile'] = os.path.basename(self.parametres['gexffile'])
41         content = content % self.parametres
42         with open(afcout, 'w') as f :
43             f.write(content)
44         return afcout
45         
46     def exportsimi(self) :
47         simifile = os.path.join(self.parent.AppliPath, 'webexport', 'graphe.html')
48         simiout = os.path.join(self.pathout.dirout, 'graphe.html')
49         with codecs.open(simifile, 'r', 'utf8') as f :
50             content = f.read()
51         self.parametres['gexffile'] = os.path.basename(self.parametres['gexffile'])
52         content = content % self.parametres
53         with open(simiout, 'w') as f :
54             f.write(content)
55         return simiout             
56