From: Pierre Date: Sun, 6 Jan 2013 14:11:36 +0000 (+0100) Subject: installation textometrieR X-Git-Url: http://iramuteq.org/git?a=commitdiff_plain;h=d33694ef233bd4a28e69d88e9eef3c5c129442fe;p=iramuteq installation textometrieR --- diff --git a/analysetxt.py b/analysetxt.py index afaf355..54f0c5c 100644 --- a/analysetxt.py +++ b/analysetxt.py @@ -52,6 +52,7 @@ class AnalyseText : self.dlg = dlg self.dialok = True self.parametres = parametres + self.val = False self.pathout = PathOut(corpus.parametres['originalpath'], analyse_type = parametres['type'], dirout = corpus.parametres['pathout']) self.parametres = self.make_config(parametres) log.info(self.pathout.dirout) @@ -125,7 +126,7 @@ class AnalyseText : sleep(0.2) else : sleep(0.2) - check_Rresult(self.ira, pid) + return check_Rresult(self.ira, pid) diff --git a/checkinstall.py b/checkinstall.py index c379287..38640ed 100644 --- a/checkinstall.py +++ b/checkinstall.py @@ -8,11 +8,14 @@ import os import sys import shutil from chemins import ConstructConfigPath -from functions import exec_rcode +from functions import exec_rcode, exec_RCMD import wx import tempfile from ConfigParser import * from time import sleep +import logging + +log = logging.getLogger('iramuteq.checkinstall') def IsNew(self): version_glob = self.ConfigGlob.get('DEFAULT', 'version_nb').split('.') @@ -100,18 +103,29 @@ def FindRPathNix(): BestPath='/usr/local/bin/R' return BestPath -def CheckRapp(Path): - return os.path.exists(Path) - def RLibsAreInstalled(self) : rlibs = self.pref.get('iramuteq', 'rlibs') - if rlibs == 'false' : + if rlibs == 'false' or rlibs == 'False' : return False else : return True +def install_textometrieR(self) : + dlg = wx.ProgressDialog("Installation de textometrieR", + "Veuillez patientez...", + maximum= 2, + parent=self, + style=wx.PD_APP_MODAL | wx.PD_AUTO_HIDE | wx.PD_ELAPSED_TIME | wx.PD_CAN_ABORT + ) + dlg.Center() + dlg.Update(1, 'Installation de textometrieR') + path = os.path.join(self.AppliPath, 'Rlib', 'textometrieR') + exec_RCMD(self.RPath, path) + dlg.Update(2,'fini') + dlg.Destroy() + def CheckRPackages(self): - listdep = ['ca', 'gee', 'ape', 'igraph','proxy', 'Matrix','wordcloud'] + listdep = ['ca', 'gee', 'ape', 'igraph','proxy', 'wordcloud', 'textometrieR'] nolib = [] i=0 dlg = wx.ProgressDialog("Test des librairies de R", "test en cours...", maximum = len(listdep), parent=self, style=wx.PD_APP_MODAL | wx.PD_AUTO_HIDE | wx.PD_ELAPSED_TIME | wx.PD_CAN_ABORT) @@ -121,14 +135,20 @@ def CheckRPackages(self): dlg.Update(i, "test de %s" % bib) txt = """library("%s")""" % bib tmpscript = tempfile.mktemp(dir=self.TEMPDIR) - file = open(tmpscript, 'w') - file.write(txt) - file.close() + with open(tmpscript, 'w') as f : + f.write(txt) test = exec_rcode(self.RPath, tmpscript, wait = True) if test : + log.info('packages %s : NOT INSTALLED' % bib) nolib.append(bib) + else : + log.info('packages %s : OK' % bib) dlg.Update(len(listdep),'fini') dlg.Destroy() + install_textoR = False + if 'textometrieR' in nolib : + nolib.pop(nolib.index('textometrieR')) + install_textoR = True if nolib != [] : txt = '\n'.join(nolib) msg = u"""Les bibliothèques de R suivantes sont manquantes : @@ -142,8 +162,8 @@ Sans ces bibliothèques, IRamuteq ne fonctionnera pas. Tapez install.packages('nom de la bibiothèque') - ou laisser IRamuteq les installer automatiquement en cliquant sur VALIDER . - Les bibliothèques seront téléchargées depuis le site miroir de R du CICT de Toulouse. - """ % txt + Les bibliothèques seront téléchargées depuis le site miroir de R %s. + """ % (txt, self.pref.get('iramuteq','rmirror')) dial = wx.MessageDialog(self, msg, u"Installation incomplète", wx.OK | wx.CANCEL | wx.NO_DEFAULT | wx.ICON_WARNING) dial.CenterOnParent() val = dial.ShowModal() @@ -157,6 +177,7 @@ Sans ces bibliothèques, IRamuteq ne fonctionnera pas. dlg.Center() dlg.Update(1, u"installation...") compt = 0 + for bib in nolib : compt += 1 dlg.Update(compt, u"installation librairie %s" % bib) @@ -172,22 +193,21 @@ Sans ces bibliothèques, IRamuteq ne fonctionnera pas. .libPaths """ txt += """ - install.packages("%s", repos = 'http://cran.cict.fr') - """ % bib + install.packages("%s", repos = "%s") + """ % (bib, self.pref.get('iramuteq','rmirror')) tmpscript = tempfile.mktemp(dir=self.TEMPDIR) - file = open(tmpscript, 'w') - file.write(txt) - file.close() + with open(tmpscript, 'w') as f : + f.write(txt) test = exec_rcode(self.RPath, tmpscript, wait = False) while test.poll() == None : dlg.Pulse(u"installation librairie %s" % bib) sleep(0.2) dlg.Update(len(nolib) + 1, 'fin') dlg.Destroy() - else : - pass dial.Destroy() - else : + if install_textoR : + install_textometrieR(self) + if nolib == [] and not install_textoR : self.pref.set('iramuteq', 'rlibs', True) with open(self.ConfigPath['preferences'], 'w') as f : self.pref.write(f) diff --git a/configuration/.corpus.cfg.swp b/configuration/.corpus.cfg.swp deleted file mode 100644 index 93eacb7..0000000 Binary files a/configuration/.corpus.cfg.swp and /dev/null differ diff --git a/configuration/path.cfg b/configuration/path.cfg index ec92226..46a7f61 100644 --- a/configuration/path.cfg +++ b/configuration/path.cfg @@ -1,4 +1,3 @@ [PATHS] rpath = lastpath = -rapp = /Applications/R.app/Contents/MacOS/R diff --git a/corpusNG.py b/corpusNG.py index 50f90e7..cbaefa3 100644 --- a/corpusNG.py +++ b/corpusNG.py @@ -526,7 +526,8 @@ class Corpus : lim -= 1 else : stop = nbmax - 1 - log.info('nb actives = %i - eff min = %i ' % (stop, lim)) + lim = effs[stop] + log.info('nb actives = %i - eff min = %i ' % (stop + 1, lim)) return [val[1] for val in allactives[0:stop + 1]], lim def make_and_write_profile(self, actives, ucecl, fileout) : diff --git a/functions.py b/functions.py index aee5d9b..8abda95 100644 --- a/functions.py +++ b/functions.py @@ -388,23 +388,14 @@ def BugReport(parent, error = None): txt += exc dial = BugDialog(parent) - #for line in formatExceptionInfo(): - # if type(line) == type([]): - # for don in line: - # txt += don.replace(' ', ' ') - # else: - # txt += line + '\n' if 'Rerror' in dir(parent) : txt += parent.Rerror parent.Rerror = '' - #if error is not None : - # txt += '\n%s\n' %error - print formatExceptionInfo() - log.error(txt) + log.info(txt) dial.text_ctrl_1.write(txt) dial.CenterOnParent() dial.ShowModal() - #raise Exception('Bug') + dial.Destroy() def PlaySound(parent): if parent.pref.getboolean('iramuteq', 'sound') : @@ -462,6 +453,12 @@ def ReadList(filein, encoding = sys.getdefaultencoding()): i += 1 return dict, first +def exec_RCMD(rpath, command) : + log.info('R CMD INSTALL %s' % command) + rpath = rpath.replace('\\','\\\\') + error = call(["%s" % rpath, 'CMD', 'INSTALL', "%s" % command]) + return error + def exec_rcode(rpath, rcode, wait = True, graph = False): log.info("R Script : %s" % rcode) needX11 = False @@ -518,16 +515,18 @@ def check_Rresult(parent, pid) : if error[1] is None : error[1] = 'None' parent.Rerror = '\n'.join([str(pid.returncode), '\n'.join(error)]) - try : - raise Exception('\n'.join(u'Erreur R', '\n'.join(error[1:]))) - except : - BugReport(parent) + #try : + raise Exception('\n'.join([u'Erreur R', '\n'.join(error[1:])])) + return False + #except : + # BugReport(parent) else : if pid != 0 : - try : - raise Exception(u'Erreur R') - except : - BugReport(parent) + #try : + raise Exception(u'Erreur R') + return False + #except : + # BugReport(parent) def print_liste(filename,liste): with open(filename,'w') as f : diff --git a/iramuteq.py b/iramuteq.py index 91cf8f0..a5d5d9a 100644 --- a/iramuteq.py +++ b/iramuteq.py @@ -61,7 +61,7 @@ from textcheckcorpus import checkcorpus from openanalyse import OpenAnalyse from corpusNG import BuildFromAlceste, Builder from sheet import MySheet -from checkinstall import CreateIraDirectory, CheckRPath, FindRPAthWin32, FindRPathNix, CheckRapp, CheckRPackages, IsNew, UpgradeConf, CopyConf, RLibsAreInstalled +from checkinstall import CreateIraDirectory, CheckRPath, FindRPAthWin32, FindRPathNix, CheckRPackages, IsNew, UpgradeConf, CopyConf, RLibsAreInstalled from chemins import ConstructRscriptsPath, ConstructConfigPath, ConstructDicoPath, ConstructGlobalPath, PathOut from parse_factiva_xml import ImportFactiva from tree import LeftTree @@ -127,6 +127,13 @@ fh.setFormatter(formatter) log.addHandler(ch) log.addHandler(fh) log.setLevel(logging.INFO) + + +class writer(object): + def write(self, data): + if data.strip() != '' : + log.info('BUG : %s' % data) +sys.stderr = writer() ConfigPath = ConstructConfigPath(UserConfigPath) ##################################################################### @@ -419,17 +426,13 @@ class IraFrame(wx.Frame): Le chemin de l'executable de R n'a pas été trouvé. Si R n'est pas installé, vous devez l'installer (http://www.r-project.org/). Si R n'est pas installé dans le répertoire par défaut -(C:\Program Files\R\R-2.x.x\R.exe sous windows ou /usr/bin/R sous linux ou Mac Os X) +(souvent C:\Program Files\R\R-2.x.x\R.exe sous windows ou /usr/bin/R sous linux ou Mac Os X) vous devez signaler le chemin de l'éxecutable de R dans les préférences.""" dlg = wx.MessageDialog(self, msg, u"Problème de configuration", wx.OK | wx.NO_DEFAULT | wx.ICON_WARNING) dlg.CenterOnParent() if dlg.ShowModal() in [wx.ID_NO, wx.ID_CANCEL]: evt.Veto() - else : - print 'ok' - if sys.platform == 'darwin': - self.Rapp = self.PathPath.get('PATHS', 'rapp') - RappOk = CheckRapp(self.Rapp) + dlg.Destroy() self.DataPop = False self.DataTxt = False self.Text = '' @@ -814,18 +817,22 @@ Voulez-vous fermer quand même ?""" BugReport(self) def OnSimiTxt(self, evt, corpus = None) : - print 'PLUS DE BUG SUR SIMITXT' - #try : + # print 'PLUS DE BUG SUR SIMITXT' + try : #self.Text = SimiTxt(self) + if corpus is None : + corpus = self.tree.getcorpus() self.Text = SimiTxt(self, corpus, parametres = {'type': 'simitxt'}, dlg = progressbar(self, 3)) if self.Text.val == wx.ID_OK : PlaySound(self) - #except : - # BugReport(self) + except : + BugReport(self) def OnWordCloud(self, evt, corpus = None) : # print 'PLUS DE BUG SUR WORDCLOUD' try : + if corpus is None : + corpus = self.tree.getcorpus() self.Text = WordCloud(self, corpus, parametres = {'type' : 'wordcloud'}, dlg = progressbar(self, 3)) if self.Text.val == wx.ID_OK : PlaySound(self) @@ -848,6 +855,8 @@ Voulez-vous fermer quand même ?""" def OnTextStat(self, event, corpus = None): print 'PAS DE BUG SUR TEXT STAT' #try: + if corpus is None : + corpus = self.tree.getcorpus() self.Text = Stat(self, corpus, parametres = {'type': 'stat'}, dlg = progressbar(self, 7)) if self.Text.val == wx.ID_OK : @@ -859,6 +868,8 @@ Voulez-vous fermer quand même ?""" #try: #self.Text = AsLexico(self) print('ATTENTION : PLUS DE BUG SUR LEXICO') + if corpus is None : + corpus = self.tree.getcorpus() self.Text = Lexico(self, corpus, parametres = {'type' : 'spec'}, dlg = progressbar(self, 3)) if self.Text.val == wx.ID_OK : PlaySound(self) @@ -879,16 +890,16 @@ Voulez-vous fermer quand même ?""" BugReport(self) def OnTextAlceste(self, event, corpus = None): - #try: - print('ATTENTION : PLUS DE BUG SUR ALCESTE') + try: + #print('ATTENTION : PLUS DE BUG SUR ALCESTE') #RunAnalyse(self, corpus, Alceste, OptAlceste) + if corpus is None : + corpus = self.tree.getcorpus() self.Text = Alceste(self, corpus, parametres = {'type': 'alceste'}, dlg = progressbar(self,6)) - #self.history.addtab(self.Text.parametres) - #OpenAnalyse(self, self.Text.parametres['ira']) if self.Text.val == wx.ID_OK: PlaySound(self) - #except: - # BugReport(self) + except: + BugReport(self) def OnPamSimple(self, event): try: diff --git a/profile_segment.py b/profile_segment.py index 639b660..3973d84 100644 --- a/profile_segment.py +++ b/profile_segment.py @@ -64,7 +64,7 @@ class ProfileSegment() : def do_layout(self) : SelectTab = self.parent.nb.GetSelection() page = self.parent.nb.GetPage(SelectTab).TabChdSim - prof_seg = ReadProfileAsDico(self, self.dictpathout['prof_seg'], True, self.parent.syscoding) + prof_seg = ReadProfileAsDico(self.dictpathout['prof_seg'], True, self.parent.syscoding) prof_seg_nb = aui.AuiNotebook(self.parent, -1, wx.DefaultPosition) for i in range(0,len(self.corpus.lc)) : ntab = ProfListctrlPanel(self.parent, self, prof_seg[str(i + 1)], False, i + 1) @@ -139,7 +139,7 @@ class ProfilType() : page = self.parent.nb.GetPage(SelectTab).TabChdSim prof_seg_nb = aui.AuiNotebook(self.parent, -1, wx.DefaultPosition) if alceste : - prof_seg = ReadProfileAsDico(self, self.outprof, True) + prof_seg = ReadProfileAsDico(self.outprof, True) for i in range(0,len(self.corpus.lc)) : ntab = ProfListctrlPanel(self.parent, self, prof_seg[str(i + 1)], False, i + 1) prof_seg_nb.AddPage(ntab, 'classe %i' % (i + 1)) diff --git a/textsimi.py b/textsimi.py index 9a68ac3..a5b8c7b 100644 --- a/textsimi.py +++ b/textsimi.py @@ -48,7 +48,8 @@ class SimiTxt(AnalyseText): self.makefiles() script = PrintSimiScript(self) script.make_script() - self.doR(script.scriptout) + if not self.doR(script.scriptout) : + return False if self.parametres['type_graph'] == 1: if os.path.exists(self.pathout['liste_graph']): graph_simi = read_list_file(self.pathout['liste_graph']) diff --git a/tree.py b/tree.py index 9d69efc..ef324e0 100644 --- a/tree.py +++ b/tree.py @@ -303,6 +303,7 @@ class LeftTree(CT.CustomTreeCtrl): itemtype = self.GetItemType(item) text = self.GetItemText(item) pydata = self.GetPyData(item) + self.pydata = pydata self.current = item self.itemdict = {"ishtml": ishtml, "back": back, "fore": fore, "isbold": isbold, @@ -377,29 +378,36 @@ class LeftTree(CT.CustomTreeCtrl): self.PopupMenu(menu) menu.Destroy() - def getcorpus(self, itemdict): - if itemdict['pydata']['uuid'] in self.parent.history.openedcorpus : - return copycorpus(self.parent.history.openedcorpus[itemdict['pydata']['uuid']]) + def getcorpus(self): + if self.pydata['uuid'] in self.parent.history.openedcorpus : + return copycorpus(self.parent.history.openedcorpus[self.pydata['uuid']]) + elif 'corpus_name' in self.pydata : + return Corpus(self.parent, parametres = DoConf(self.pydata['ira']).getoptions('corpus'), read = True) else : - return Corpus(self.parent, parametres = DoConf(itemdict['pydata']['ira']).getoptions('corpus'), read = True) + cuuid = self.pydata['corpus'] + if cuuid in self.parent.history.openedcorpus : + return copycorpus(self.parent.history.openedcorpus[cuuid]) + else : + irapath = self.parent.history.corpus[cuuid]['ira'] + return Corpus(self.parent, parametres = DoConf(irapath).getoptions('corpus'), read = True) def OnSpec(self, evt) : - self.parent.OnTextSpec(evt, self.getcorpus(self.itemdict)) + self.parent.OnTextSpec(evt, self.getcorpus()) def OnStat(self, evt) : - self.parent.OnTextStat(evt, self.getcorpus(self.itemdict)) + self.parent.OnTextStat(evt, self.getcorpus()) def OnAlceste(self, evt) : - self.parent.OnTextAlceste(evt, self.getcorpus(self.itemdict)) + self.parent.OnTextAlceste(evt, self.getcorpus()) def OnPam(self, evt) : print 'rien' def OnSimiTxt(self, evt) : - self.parent.OnSimiTxt(evt, self.getcorpus(self.itemdict)) + self.parent.OnSimiTxt(evt, self.getcorpus()) def OnWordCloud(self, evt) : - self.parent.OnWordCloud(evt, self.getcorpus(self.itemdict)) + self.parent.OnWordCloud(evt, self.getcorpus()) def OnProfSR(self, evt) : ProfileSegment(self.parent, self.page.dictpathout, self.page.parametres, self.page.corpus) @@ -787,6 +795,7 @@ class LeftTree(CT.CustomTreeCtrl): item = event.GetItem() pydata = self.GetPyData(item) if pydata is not None : + self.pydata = pydata if pydata['uuid'] in self.parent.history.opened : for i in range(self.parent.nb.GetPageCount()) : self.page = self.parent.nb.GetPage(i)