2 # -*- coding: utf-8 -*-
3 #Author: Pierre Ratinaud
4 #Copyright (c) 2008 Pierre Ratinaud
10 from chemins import ConstructConfigPath
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)
59 DictUser = self.ConfigPath
60 DictAppli = ConstructConfigPath(self.AppliPath,user=False)
61 for item, filein in DictUser.iteritems():
62 if not item == u'global' and not item == u'path' and not item == u'preferences' and not item == u'history' :
63 shutil.copyfile(DictAppli[item],filein)
65 if not os.path.exists(filein):
66 shutil.copyfile(DictAppli[item],filein)
67 if item == u'preferences' :
68 if not os.path.exists(filein) :
69 shutil.copyfile(DictAppli[item],filein)
71 def CheckRPath(PathPath):
72 if not os.path.exists(PathPath.get('PATHS','rpath')):
80 if 'ProgramFiles' in os.environ :
81 progpaths.append(os.environ['ProgramFiles'])
82 if 'ProgramFiles(x86)' in os.environ :
83 progpaths.append(os.environ['ProgramFiles(x86)'])
84 if 'ProgramW6432' in os.environ :
85 progpaths.append(os.environ['ProgramW6432'])
86 progpaths = list(set(progpaths))
88 for progpath in progpaths :
89 rpath = os.path.join(progpath, "R")
90 if os.path.exists(rpath) :
93 path=os.path.join(rpath,"R-2."+str(i)+"."+str(j),'bin','R.exe')
94 if os.path.exists(path):
100 if os.path.exists('/usr/bin/R'):
101 BestPath='/usr/bin/R'
102 elif os.path.exists('/usr/local/bin/R'):
103 BestPath='/usr/local/bin/R'
106 def RLibsAreInstalled(self) :
107 rlibs = self.pref.get('iramuteq', 'rlibs')
108 if rlibs == 'false' or rlibs == 'False' :
113 def install_textometrieR(self) :
114 dlg = wx.ProgressDialog("Installation de textometrieR",
115 "Veuillez patientez...",
118 style=wx.PD_APP_MODAL | wx.PD_AUTO_HIDE | wx.PD_ELAPSED_TIME | wx.PD_CAN_ABORT
121 dlg.Update(1, 'Installation de textometrieR')
122 path = os.path.join(self.AppliPath, 'Rlib', 'textometrieR')
123 exec_RCMD(self.RPath, path)
127 def CheckRPackages(self):
128 listdep = ['ca', 'gee', 'ape', 'igraph','proxy', 'wordcloud', 'textometrieR']
131 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)
135 dlg.Update(i, "test de %s" % bib)
136 txt = """library("%s")""" % bib
137 tmpscript = tempfile.mktemp(dir=self.TEMPDIR)
138 with open(tmpscript, 'w') as f :
140 test = exec_rcode(self.RPath, tmpscript, wait = True)
142 log.info('packages %s : NOT INSTALLED' % bib)
145 log.info('packages %s : OK' % bib)
146 dlg.Update(len(listdep),'fini')
148 install_textoR = False
149 if 'textometrieR' in nolib :
150 nolib.pop(nolib.index('textometrieR'))
151 install_textoR = True
153 txt = '\n'.join(nolib)
154 msg = u"""Les bibliothèques de R suivantes sont manquantes :
157 Sans ces bibliothèques, IRamuteq ne fonctionnera pas.
159 - Vous pouvez installer ces bibliothèques manuellement :
162 Tapez install.packages('nom de la bibiothèque')
164 - ou laisser IRamuteq les installer automatiquement en cliquant sur VALIDER .
165 Les bibliothèques seront téléchargées depuis le site miroir de R %s.
166 """ % (txt, self.pref.get('iramuteq','rmirror'))
167 dial = wx.MessageDialog(self, msg, u"Installation incomplète", wx.OK | wx.CANCEL | wx.NO_DEFAULT | wx.ICON_WARNING)
168 dial.CenterOnParent()
169 val = dial.ShowModal()
171 dlg = wx.ProgressDialog("Installation",
172 "Veuillez patientez...",
173 maximum=len(nolib) + 1,
175 style=wx.PD_APP_MODAL | wx.PD_AUTO_HIDE | wx.PD_ELAPSED_TIME | wx.PD_CAN_ABORT
178 dlg.Update(1, u"installation...")
183 dlg.Update(compt, u"installation librairie %s" % bib)
185 userdir <- unlist(strsplit(Sys.getenv("R_LIBS_USER"), .Platform$path.sep))[1]
186 if (!file.exists(userdir)) {
187 if (!dir.create(userdir, recursive = TRUE))
188 print('pas possible')
190 .libPaths(c(userdir, .libPaths()))
196 install.packages("%s", repos = "%s")
197 """ % (bib, self.pref.get('iramuteq','rmirror'))
198 tmpscript = tempfile.mktemp(dir=self.TEMPDIR)
199 with open(tmpscript, 'w') as f :
201 test = exec_rcode(self.RPath, tmpscript, wait = False)
202 while test.poll() == None :
203 dlg.Pulse(u"installation librairie %s" % bib)
205 dlg.Update(len(nolib) + 1, 'fin')
209 install_textometrieR(self)
210 if nolib == [] and not install_textoR :
211 self.pref.set('iramuteq', 'rlibs', True)
212 with open(self.ConfigPath['preferences'], 'w') as f :