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)
53 dicoUser = self.DictPath
54 dicoAppli = ConstructDicoPath(self.AppliPath)
56 if not os.path.exists(dicoUser[fi]) and os.path.exists(dicoAppli[fi]):
57 shutil.copyfile(dicoAppli[fi], dicoUser[fi])
59 def CreateIraDirectory(UserConfigPath,AppliPath):
60 if not os.path.exists(UserConfigPath):
61 os.mkdir(UserConfigPath)
62 if not os.path.exists(os.path.join(UserConfigPath, 'dictionnaires')) :
63 os.mkdir(os.path.join(UserConfigPath, 'dictionnaires'))
66 DictUser = self.ConfigPath
67 DictAppli = ConstructConfigPath(self.AppliPath,user=False)
68 for item, filein in DictUser.iteritems():
69 if not item == u'global' and not item == u'path' and not item == u'preferences' and not item == u'history' :
70 shutil.copyfile(DictAppli[item],filein)
72 if not os.path.exists(filein):
73 shutil.copyfile(DictAppli[item],filein)
74 if item == u'preferences' :
75 if not os.path.exists(filein) :
76 shutil.copyfile(DictAppli[item],filein)
77 dicoUser = self.DictPath
78 dicoAppli = ConstructDicoPath(self.AppliPath)
80 if not os.path.exists(dicoUser[fi]) and os.path.exists(dicoAppli[fi]):
81 shutil.copyfile(dicoAppli[fi], dicoUser[fi])
83 def CheckRPath(PathPath):
84 if not os.path.exists(PathPath.get('PATHS','rpath')):
92 if 'ProgramFiles' in os.environ :
93 progpaths.append(os.environ['ProgramFiles'])
94 if 'ProgramFiles(x86)' in os.environ :
95 progpaths.append(os.environ['ProgramFiles(x86)'])
96 if 'ProgramW6432' in os.environ :
97 progpaths.append(os.environ['ProgramW6432'])
98 progpaths = list(set(progpaths))
100 for progpath in progpaths :
101 rpath = os.path.join(progpath, "R")
102 if os.path.exists(rpath) :
103 for i in range(7,20):
104 for j in range(0,15):
105 path=os.path.join(rpath,"R-2."+str(i)+"."+str(j),'bin','R.exe')
106 if os.path.exists(path):
112 if os.path.exists('/usr/bin/R'):
113 BestPath='/usr/bin/R'
114 elif os.path.exists('/usr/local/bin/R'):
115 BestPath='/usr/local/bin/R'
118 def RLibsAreInstalled(self) :
119 rlibs = self.pref.get('iramuteq', 'rlibs')
120 if rlibs == 'false' or rlibs == 'False' :
125 def install_textometrieR(self) :
126 dlg = wx.ProgressDialog("Installation de textometrieR",
127 "Veuillez patientez...",
130 style=wx.PD_APP_MODAL | wx.PD_AUTO_HIDE | wx.PD_ELAPSED_TIME | wx.PD_CAN_ABORT
133 dlg.Update(1, 'Installation de textometrieR')
134 path = os.path.join(self.AppliPath, 'Rlib', 'textometrieR')
135 exec_RCMD(self.RPath, path)
139 def CheckRPackages(self):
140 listdep = ['ca', 'gee', 'ape', 'igraph','proxy', 'wordcloud', 'textometrieR']
143 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)
147 dlg.Update(i, "test de %s" % bib)
148 txt = """library("%s")""" % bib
149 tmpscript = tempfile.mktemp(dir=self.TEMPDIR)
150 with open(tmpscript, 'w') as f :
152 test = exec_rcode(self.RPath, tmpscript, wait = True)
154 log.info('packages %s : NOT INSTALLED' % bib)
157 log.info('packages %s : OK' % bib)
158 dlg.Update(len(listdep),'fini')
160 install_textoR = False
161 if 'textometrieR' in nolib :
162 nolib.pop(nolib.index('textometrieR'))
163 install_textoR = True
165 txt = '\n'.join(nolib)
166 msg = u"""Les bibliothèques de R suivantes sont manquantes :
169 Sans ces bibliothèques, IRamuteq ne fonctionnera pas.
171 - Vous pouvez installer ces bibliothèques manuellement :
174 Tapez install.packages('nom de la bibiothèque')
176 - ou laisser IRamuteq les installer automatiquement en cliquant sur VALIDER .
177 Les bibliothèques seront téléchargées depuis le site miroir de R %s.
178 """ % (txt, self.pref.get('iramuteq','rmirror'))
179 dial = wx.MessageDialog(self, msg, u"Installation incomplète", wx.OK | wx.CANCEL | wx.NO_DEFAULT | wx.ICON_WARNING)
180 dial.CenterOnParent()
181 val = dial.ShowModal()
183 dlg = wx.ProgressDialog("Installation",
184 "Veuillez patientez...",
185 maximum=len(nolib) + 1,
187 style=wx.PD_APP_MODAL | wx.PD_AUTO_HIDE | wx.PD_ELAPSED_TIME | wx.PD_CAN_ABORT
190 dlg.Update(1, u"installation...")
195 dlg.Update(compt, u"installation librairie %s" % bib)
197 userdir <- unlist(strsplit(Sys.getenv("R_LIBS_USER"), .Platform$path.sep))[1]
198 if (!file.exists(userdir)) {
199 if (!dir.create(userdir, recursive = TRUE))
200 print('pas possible')
202 .libPaths(c(userdir, .libPaths()))
208 install.packages("%s", repos = "%s")
209 """ % (bib, self.pref.get('iramuteq','rmirror'))
210 tmpscript = tempfile.mktemp(dir=self.TEMPDIR)
211 with open(tmpscript, 'w') as f :
213 test = exec_rcode(self.RPath, tmpscript, wait = False)
214 while test.poll() == None :
215 dlg.Pulse(u"installation librairie %s" % bib)
217 dlg.Update(len(nolib) + 1, 'fin')
221 install_textometrieR(self)
222 if nolib == [] and not install_textoR :
223 self.pref.set('iramuteq', 'rlibs', True)
224 with open(self.ConfigPath['preferences'], 'w') as f :