From c0e66bf79b305e620e352f3aac05b9a1cdb3f60f Mon Sep 17 00:00:00 2001 From: Pierre Date: Tue, 11 Feb 2014 14:16:38 +0100 Subject: [PATCH] web export --- webexport.py | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 webexport.py diff --git a/webexport.py b/webexport.py new file mode 100644 index 0000000..4733d85 --- /dev/null +++ b/webexport.py @@ -0,0 +1,56 @@ +import codecs +from shutil import copyfile +import os +from chemins import PathOut + + + +class WebExport : + def __init__(self, parent, parametres) : + self.parent = parent + self.parametres = parametres + self.jspathin = os.path.join(self.parent.AppliPath, 'webexport','js') + self.csspathin = os.path.join(self.parent.AppliPath, 'webexport', 'css') + if not 'dirout' in self.parametres : + self.pathout = PathOut(filename = self.parametres['gexffile'], analyse_type='webexport') + dirout = self.pathout.mkdirout() + self.pathout.dirout = dirout + else : + self.pathout = PathOut(dirout = self.parametres['dirout']) + self.makedirout() + + def makedirout(self) : + jss = os.listdir(self.jspathin) + css = os.listdir(self.csspathin) + jspathout = os.path.join(self.pathout.dirout, 'js') + cssout = os.path.join(self.pathout.dirout, 'css') + os.makedirs(jspathout) + os.makedirs(cssout) + for f in jss : + copyfile(os.path.join(self.jspathin, f), os.path.join(jspathout, f)) + for f in css : + copyfile(os.path.join(self.csspathin, f), os.path.join(cssout, f)) + + def exportafc(self) : + copyfile(self.parametres['gexffile'], os.path.join(self.pathout.dirout, os.path.basename(self.parametres['gexffile']))) + afcfile = os.path.join(self.parent.AppliPath, 'webexport', 'afc.html') + afcout = os.path.join(self.pathout.dirout, 'afc.html') + with codecs.open(afcfile, 'r', 'utf8') as f : + content = f.read() + self.parametres['gexffile'] = os.path.basename(self.parametres['gexffile']) + content = content % self.parametres + with open(afcout, 'w') as f : + f.write(content) + return afcout + + def exportsimi(self) : + simifile = os.path.join(self.parent.AppliPath, 'webexport', 'graphe.html') + simiout = os.path.join(self.pathout.dirout, 'graphe.html') + with codecs.open(simifile, 'r', 'utf8') as f : + content = f.read() + self.parametres['gexffile'] = os.path.basename(self.parametres['gexffile']) + content = content % self.parametres + with open(simiout, 'w') as f : + f.write(content) + return simiout + \ No newline at end of file -- 2.7.4