2 # -*- coding: utf-8 -*-
3 #Author: Pierre Ratinaud
4 #Copyright (c) 2008 Pierre Ratinaud
10 from chemins import ConstructConfigPath, ConstructDicoPath
11 from functions import exec_rcode, exec_RCMD
14 from ConfigParser import *
15 from time import sleep
18 log = logging.getLogger('iramuteq.checkinstall')
21 version_glob = self.ConfigGlob.get('DEFAULT', 'version_nb').split('.')
23 version_user = self.pref.get('iramuteq','version_nb').split('.')
24 except NoOptionError :
27 version_user[0] = int(version_user[0])
28 version_user[1] = int(version_user[1])
29 version_glob[0] = int(version_glob[0])
30 version_glob[1] = int(version_glob[1])
31 if len(version_user) == len(version_glob) :
32 if version_glob > version_user :
36 if len(version_glob) == 2 :
37 if version_glob[:2] >= version_user[:2] :
41 elif len(version_glob) == 3 :
42 if version_glob[:2] <= version_user[:2] :
47 def UpgradeConf(self) :
48 dictuser = self.ConfigPath
49 dictappli = ConstructConfigPath(self.AppliPath, user = False)
50 for item,filein in dictuser.iteritems():
51 if not item == u'global' and not item == u'history':
52 shutil.copyfile(dictappli[item], filein)
54 def CreateIraDirectory(UserConfigPath,AppliPath):
55 if not os.path.exists(UserConfigPath):
56 os.mkdir(UserConfigPath)
57 if not os.path.exists(os.path.join(UserConfigPath, 'dictionnaires')) :
58 os.mkdir(os.path.join(UserConfigPath, 'dictionnaires'))
61 DictUser = self.ConfigPath
62 DictAppli = ConstructConfigPath(self.AppliPath,user=False)
63 for item, filein in DictUser.iteritems():
64 if not item == u'global' and not item == u'path' and not item == u'preferences' and not item == u'history' :
65 shutil.copyfile(DictAppli[item],filein)
67 if not os.path.exists(filein):
68 shutil.copyfile(DictAppli[item],filein)
69 if item == u'preferences' :
70 if not os.path.exists(filein) :
71 shutil.copyfile(DictAppli[item],filein)
72 dicoUser = self.DictPath
73 dicoAppli = ConstructDicoPath(self.AppliPath)
75 if not os.path.exists(dicoUser[fi]) and os.path.exists(dicoAppli[fi]):
76 shutil.copyfile(dicoAppli[fi], dicoUser[fi])
78 def CheckRPath(PathPath):
79 if not os.path.exists(PathPath.get('PATHS','rpath')):
87 if 'ProgramFiles' in os.environ :
88 progpaths.append(os.environ['ProgramFiles'])
89 if 'ProgramFiles(x86)' in os.environ :
90 progpaths.append(os.environ['ProgramFiles(x86)'])
91 if 'ProgramW6432' in os.environ :
92 progpaths.append(os.environ['ProgramW6432'])
93 progpaths = list(set(progpaths))
95 for progpath in progpaths :
96 rpath = os.path.join(progpath, "R")
97 if os.path.exists(rpath) :
100 path=os.path.join(rpath,"R-2."+str(i)+"."+str(j),'bin','R.exe')
101 if os.path.exists(path):
107 if os.path.exists('/usr/bin/R'):
108 BestPath='/usr/bin/R'
109 elif os.path.exists('/usr/local/bin/R'):
110 BestPath='/usr/local/bin/R'
113 def RLibsAreInstalled(self) :
114 rlibs = self.pref.get('iramuteq', 'rlibs')
115 if rlibs == 'false' or rlibs == 'False' :
120 def install_textometrieR(self) :
121 dlg = wx.ProgressDialog("Installation de textometrieR",
122 "Veuillez patientez...",
125 style=wx.PD_APP_MODAL | wx.PD_AUTO_HIDE | wx.PD_ELAPSED_TIME | wx.PD_CAN_ABORT
128 dlg.Update(1, 'Installation de textometrieR')
129 path = os.path.join(self.AppliPath, 'Rlib', 'textometrieR')
130 exec_RCMD(self.RPath, path)
134 def CheckRPackages(self):
135 listdep = ['ca', 'gee', 'ape', 'igraph','proxy', 'wordcloud', 'textometrieR']
138 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)
142 dlg.Update(i, "test de %s" % bib)
143 txt = """library("%s")""" % bib
144 tmpscript = tempfile.mktemp(dir=self.TEMPDIR)
145 with open(tmpscript, 'w') as f :
147 test = exec_rcode(self.RPath, tmpscript, wait = True)
149 log.info('packages %s : NOT INSTALLED' % bib)
152 log.info('packages %s : OK' % bib)
153 dlg.Update(len(listdep),'fini')
155 install_textoR = False
156 if 'textometrieR' in nolib :
157 nolib.pop(nolib.index('textometrieR'))
158 install_textoR = True
160 txt = '\n'.join(nolib)
161 msg = u"""Les bibliothèques de R suivantes sont manquantes :
164 Sans ces bibliothèques, IRamuteq ne fonctionnera pas.
166 - Vous pouvez installer ces bibliothèques manuellement :
169 Tapez install.packages('nom de la bibiothèque')
171 - ou laisser IRamuteq les installer automatiquement en cliquant sur VALIDER .
172 Les bibliothèques seront téléchargées depuis le site miroir de R %s.
173 """ % (txt, self.pref.get('iramuteq','rmirror'))
174 dial = wx.MessageDialog(self, msg, u"Installation incomplète", wx.OK | wx.CANCEL | wx.NO_DEFAULT | wx.ICON_WARNING)
175 dial.CenterOnParent()
176 val = dial.ShowModal()
178 dlg = wx.ProgressDialog("Installation",
179 "Veuillez patientez...",
180 maximum=len(nolib) + 1,
182 style=wx.PD_APP_MODAL | wx.PD_AUTO_HIDE | wx.PD_ELAPSED_TIME | wx.PD_CAN_ABORT
185 dlg.Update(1, u"installation...")
190 dlg.Update(compt, u"installation librairie %s" % bib)
192 userdir <- unlist(strsplit(Sys.getenv("R_LIBS_USER"), .Platform$path.sep))[1]
193 if (!file.exists(userdir)) {
194 if (!dir.create(userdir, recursive = TRUE))
195 print('pas possible')
197 .libPaths(c(userdir, .libPaths()))
203 install.packages("%s", repos = "%s")
204 """ % (bib, self.pref.get('iramuteq','rmirror'))
205 tmpscript = tempfile.mktemp(dir=self.TEMPDIR)
206 with open(tmpscript, 'w') as f :
208 test = exec_rcode(self.RPath, tmpscript, wait = False)
209 while test.poll() == None :
210 dlg.Pulse(u"installation librairie %s" % bib)
212 dlg.Update(len(nolib) + 1, 'fin')
216 install_textometrieR(self)
217 if nolib == [] and not install_textoR :
218 self.pref.set('iramuteq', 'rlibs', True)
219 with open(self.ConfigPath['preferences'], 'w') as f :