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'))
62 DictUser = self.ConfigPath
63 DictAppli = ConstructConfigPath(self.AppliPath,user=False)
64 for item, filein in DictUser.iteritems():
65 if not item == u'global' and not item == u'path' and not item == u'preferences' and not item == u'history' :
66 shutil.copyfile(DictAppli[item],filein)
68 if not os.path.exists(filein):
69 shutil.copyfile(DictAppli[item],filein)
70 if item == u'preferences' :
71 if not os.path.exists(filein) :
72 shutil.copyfile(DictAppli[item],filein)
73 dicoUser = self.DictPath
74 dicoAppli = ConstructDicoPath(self.AppliPath)
77 if not os.path.exists(dicoUser[fi]) and os.path.exists(dicoAppli[fi]):
78 shutil.copyfile(dicoAppli[fi], dicoUser[fi])
80 def CheckRPath(PathPath):
81 if not os.path.exists(PathPath.get('PATHS','rpath')):
89 if 'ProgramFiles' in os.environ :
90 progpaths.append(os.environ['ProgramFiles'])
91 if 'ProgramFiles(x86)' in os.environ :
92 progpaths.append(os.environ['ProgramFiles(x86)'])
93 if 'ProgramW6432' in os.environ :
94 progpaths.append(os.environ['ProgramW6432'])
95 progpaths = list(set(progpaths))
97 for progpath in progpaths :
98 rpath = os.path.join(progpath, "R")
99 if os.path.exists(rpath) :
100 for i in range(7,20):
101 for j in range(0,15):
102 path=os.path.join(rpath,"R-2."+str(i)+"."+str(j),'bin','R.exe')
103 if os.path.exists(path):
109 if os.path.exists('/usr/bin/R'):
110 BestPath='/usr/bin/R'
111 elif os.path.exists('/usr/local/bin/R'):
112 BestPath='/usr/local/bin/R'
115 def RLibsAreInstalled(self) :
116 rlibs = self.pref.get('iramuteq', 'rlibs')
117 if rlibs == 'false' or rlibs == 'False' :
122 def install_textometrieR(self) :
123 dlg = wx.ProgressDialog("Installation de textometrieR",
124 "Veuillez patientez...",
127 style=wx.PD_APP_MODAL | wx.PD_AUTO_HIDE | wx.PD_ELAPSED_TIME | wx.PD_CAN_ABORT
130 dlg.Update(1, 'Installation de textometrieR')
131 path = os.path.join(self.AppliPath, 'Rlib', 'textometrieR')
132 exec_RCMD(self.RPath, path)
136 def CheckRPackages(self):
137 listdep = ['ca', 'gee', 'ape', 'igraph','proxy', 'wordcloud', 'textometrieR']
140 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)
144 dlg.Update(i, "test de %s" % bib)
145 txt = """library("%s")""" % bib
146 tmpscript = tempfile.mktemp(dir=self.TEMPDIR)
147 with open(tmpscript, 'w') as f :
149 test = exec_rcode(self.RPath, tmpscript, wait = True)
151 log.info('packages %s : NOT INSTALLED' % bib)
154 log.info('packages %s : OK' % bib)
155 dlg.Update(len(listdep),'fini')
157 install_textoR = False
158 if 'textometrieR' in nolib :
159 nolib.pop(nolib.index('textometrieR'))
160 install_textoR = True
162 txt = '\n'.join(nolib)
163 msg = u"""Les bibliothèques de R suivantes sont manquantes :
166 Sans ces bibliothèques, IRamuteq ne fonctionnera pas.
168 - Vous pouvez installer ces bibliothèques manuellement :
171 Tapez install.packages('nom de la bibiothèque')
173 - ou laisser IRamuteq les installer automatiquement en cliquant sur VALIDER .
174 Les bibliothèques seront téléchargées depuis le site miroir de R %s.
175 """ % (txt, self.pref.get('iramuteq','rmirror'))
176 dial = wx.MessageDialog(self, msg, u"Installation incomplète", wx.OK | wx.CANCEL | wx.NO_DEFAULT | wx.ICON_WARNING)
177 dial.CenterOnParent()
178 val = dial.ShowModal()
180 dlg = wx.ProgressDialog("Installation",
181 "Veuillez patientez...",
182 maximum=len(nolib) + 1,
184 style=wx.PD_APP_MODAL | wx.PD_AUTO_HIDE | wx.PD_ELAPSED_TIME | wx.PD_CAN_ABORT
187 dlg.Update(1, u"installation...")
192 dlg.Update(compt, u"installation librairie %s" % bib)
194 userdir <- unlist(strsplit(Sys.getenv("R_LIBS_USER"), .Platform$path.sep))[1]
195 if (!file.exists(userdir)) {
196 if (!dir.create(userdir, recursive = TRUE))
197 print('pas possible')
199 .libPaths(c(userdir, .libPaths()))
205 install.packages("%s", repos = "%s")
206 """ % (bib, self.pref.get('iramuteq','rmirror'))
207 tmpscript = tempfile.mktemp(dir=self.TEMPDIR)
208 with open(tmpscript, 'w') as f :
210 test = exec_rcode(self.RPath, tmpscript, wait = False)
211 while test.poll() == None :
212 dlg.Pulse(u"installation librairie %s" % bib)
214 dlg.Update(len(nolib) + 1, 'fin')
218 install_textometrieR(self)
219 if nolib == [] and not install_textoR :
220 self.pref.set('iramuteq', 'rlibs', True)
221 with open(self.ConfigPath['preferences'], 'w') as f :