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