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 :
29 print len(version_user), len(version_glob)
30 version_user[0] = int(version_user[0])
31 version_user[1] = int(version_user[1])
32 version_glob[0] = int(version_glob[0])
33 version_glob[1] = int(version_glob[1])
34 if len(version_user) == 3 :
35 if 'a' in version_user[2] :
37 version_user[2] = int(version_user[2].replace('a', ''))
38 elif 'b' in version_user[2] :
40 version_user[2] = int(version_user[2].replace('b', ''))
42 version_user[2] = int(version_user[2])
43 if len(version_glob) == 3 :
44 if 'a' in version_glob[2] :
46 version_glob[2] = int(version_glob[2].replace('a', ''))
47 elif 'b' in version_glob[2] :
49 version_glob[2] = int(version_glob[2].replace('b', ''))
51 version_glob[2] = int(version_glob[2])
52 if len(version_user) == len(version_glob) :
53 if version_glob > version_user :
55 elif version_glob == version_user :
58 elif globab > userab :
65 if version_glob > version_user :
70 def UpgradeConf(self) :
71 log.info('upgrade conf')
72 dictuser = self.ConfigPath
73 dictappli = ConstructConfigPath(self.AppliPath, user = False)
74 for item,filein in dictuser.iteritems():
75 if not item == u'global' and not item == u'history':
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 CreateIraDirectory(UserConfigPath,AppliPath):
84 if not os.path.exists(UserConfigPath):
85 os.mkdir(UserConfigPath)
86 if not os.path.exists(os.path.join(UserConfigPath, 'dictionnaires')) :
87 os.mkdir(os.path.join(UserConfigPath, 'dictionnaires'))
90 DictUser = self.ConfigPath
91 DictAppli = ConstructConfigPath(self.AppliPath,user=False)
92 for item, filein in DictUser.iteritems():
93 if not item == u'global' and not item == u'path' and not item == u'preferences' and not item == u'history' :
94 shutil.copyfile(DictAppli[item],filein)
96 if not os.path.exists(filein):
97 shutil.copyfile(DictAppli[item],filein)
98 if item == u'preferences' :
99 if not os.path.exists(filein) :
100 shutil.copyfile(DictAppli[item],filein)
101 dicoUser = self.DictPath
102 dicoAppli = ConstructDicoPath(self.AppliPath)
104 if not os.path.exists(dicoUser[fi]) and os.path.exists(dicoAppli[fi]):
105 shutil.copyfile(dicoAppli[fi], dicoUser[fi])
107 def CheckRPath(PathPath):
108 if not os.path.exists(PathPath.get('PATHS','rpath')):
113 def FindRPAthWin32():
116 if 'ProgramFiles' in os.environ :
117 progpaths.append(os.environ['ProgramFiles'])
118 if 'ProgramFiles(x86)' in os.environ :
119 progpaths.append(os.environ['ProgramFiles(x86)'])
120 if 'ProgramW6432' in os.environ :
121 progpaths.append(os.environ['ProgramW6432'])
122 progpaths = list(set(progpaths))
124 for progpath in progpaths :
125 rpath = os.path.join(progpath, "R")
126 if os.path.exists(rpath) :
127 for maj in range(2,4) :
128 for i in range(0,30):
129 for j in range(0,20):
130 for poss in ['', 'i386', 'x64'] :
131 path=os.path.join(rpath,"R-%i.%i.%i" % (maj, i, j),'bin',poss,'R.exe')
132 if os.path.exists(path):
138 if os.path.exists('/usr/bin/R'):
139 BestPath='/usr/bin/R'
140 elif os.path.exists('/usr/local/bin/R'):
141 BestPath='/usr/local/bin/R'
144 def RLibsAreInstalled(self) :
145 rlibs = self.pref.get('iramuteq', 'rlibs')
146 if rlibs == 'false' or rlibs == 'False' :
151 def CheckRPackages(self):
152 listdep = ['ca', 'rgl', 'gee', 'ape', 'igraph','proxy', 'wordcloud', 'irlba', 'textometry']
155 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)
159 dlg.Update(i, "test de %s" % bib)
160 txt = """library("%s")""" % bib
161 tmpscript = tempfile.mktemp(dir=self.TEMPDIR)
162 with open(tmpscript, 'w') as f :
164 test = exec_rcode(self.RPath, tmpscript, wait = True)
166 log.info('packages %s : NOT INSTALLED' % bib)
169 log.info('packages %s : OK' % bib)
170 dlg.Update(len(listdep),'fini')
173 txt = '\n'.join(nolib)
174 msg = u"""Les bibliothèques de R suivantes sont manquantes :
177 Sans ces bibliothèques, IRamuteq ne fonctionnera pas.
179 - Vous pouvez installer ces bibliothèques manuellement :
182 Tapez install.packages('nom de la bibiothèque')
184 - ou laisser IRamuteq les installer automatiquement en cliquant sur VALIDER .
185 Les bibliothèques seront téléchargées depuis le site miroir de R %s.
186 """ % (txt, self.pref.get('iramuteq','rmirror'))
187 dial = wx.MessageDialog(self, msg, u"Installation incomplète", wx.OK | wx.CANCEL | wx.ICON_WARNING)
188 dial.CenterOnParent()
189 val = dial.ShowModal()
191 dlg = wx.ProgressDialog("Installation",
192 "Veuillez patientez...",
193 maximum=len(nolib) + 1,
195 style=wx.PD_APP_MODAL | wx.PD_AUTO_HIDE | wx.PD_ELAPSED_TIME | wx.PD_CAN_ABORT
198 dlg.Update(1, u"installation...")
203 dlg.Update(compt, u"installation librairie %s" % bib)
205 userdir <- unlist(strsplit(Sys.getenv("R_LIBS_USER"), .Platform$path.sep))[1]
206 if (!file.exists(userdir)) {
207 if (!dir.create(userdir, recursive = TRUE))
208 print('pas possible')
210 .libPaths(c(userdir, .libPaths()))
216 install.packages("%s", repos = "%s")
217 """ % (bib, self.pref.get('iramuteq','rmirror'))
218 tmpscript = tempfile.mktemp(dir=self.TEMPDIR)
219 with open(tmpscript, 'w') as f :
221 test = exec_rcode(self.RPath, tmpscript, wait = False)
222 while test.poll() == None :
223 dlg.Pulse(u"installation librairie %s" % bib)
225 dlg.Update(len(nolib) + 1, 'fin')
229 self.pref.set('iramuteq', 'rlibs', True)
230 with open(self.ConfigPath['preferences'], 'w') as f :