1 # -*- coding: utf-8 -*-
2 #Author: Pierre Ratinaud
3 #Copyright (c) 2008-2020 Pierre Ratinaud
4 #modification pour python 3 : Laurent Mérat, 6x7 - mai 2020
7 #------------------------------------
8 # import des modules python
9 #------------------------------------
13 from time import sleep
17 #------------------------------------
18 # import des modules wx
19 #------------------------------------
22 #------------------------------------
23 # import des fichiers du projet
24 #------------------------------------
25 from chemins import ConstructConfigPath, ConstructDicoPath
26 from functions import exec_rcode, exec_RCMD
27 from configparser import *
29 log = logging.getLogger('iramuteq.checkinstall')
33 version_glob = self.ConfigGlob.get('DEFAULT', 'version_nb').split('.')
35 version_user = self.pref.get('iramuteq','version_nb').split('.')
36 except NoOptionError :
41 version_user[0] = int(version_user[0])
42 version_user[1] = int(version_user[1])
43 version_glob[0] = int(version_glob[0])
44 version_glob[1] = int(version_glob[1])
45 if len(version_user) == 3 :
46 if 'a' in version_user[2] :
48 version_user[2] = int(version_user[2].replace('a', ''))
49 elif 'b' in version_user[2] :
51 version_user[2] = int(version_user[2].replace('b', ''))
53 version_user[2] = int(version_user[2])
54 if len(version_glob) == 3 :
55 if 'a' in version_glob[2] :
57 version_glob[2] = int(version_glob[2].replace('a', ''))
58 elif 'b' in version_glob[2] :
60 version_glob[2] = int(version_glob[2].replace('b', ''))
62 version_glob[2] = int(version_glob[2])
63 if len(version_user) == len(version_glob) :
64 if version_glob > version_user :
66 elif version_glob == version_user :
69 elif globab > userab :
76 if version_glob > version_user :
81 def UpgradeConf(self) :
82 log.info('upgrade conf')
83 dictuser = self.ConfigPath
84 dictappli = ConstructConfigPath(self.AppliPath, user = False)
85 for item,filein in dictuser.items():
86 if not item == 'global' and not item == 'history':
87 shutil.copyfile(dictappli[item], filein)
88 dicoUser = self.DictPath
89 dicoAppli = ConstructDicoPath(self.AppliPath)
91 if not os.path.exists(dicoUser[fi]) and os.path.exists(dicoAppli[fi]):
92 shutil.copyfile(dicoAppli[fi], dicoUser[fi])
94 def CreateIraDirectory(UserConfigPath,AppliPath):
95 if not os.path.exists(UserConfigPath):
96 os.mkdir(UserConfigPath)
97 if not os.path.exists(os.path.join(UserConfigPath, 'dictionnaires')) :
98 os.mkdir(os.path.join(UserConfigPath, 'dictionnaires'))
101 DictUser = self.ConfigPath
102 DictAppli = ConstructConfigPath(self.AppliPath,user=False)
103 for item, filein in DictUser.items():
104 if not item == 'global' and not item == 'path' and not item == 'preferences' and not item == 'history' :
105 shutil.copyfile(DictAppli[item],filein)
107 if not os.path.exists(filein):
108 shutil.copyfile(DictAppli[item],filein)
109 if item == 'preferences' :
110 if not os.path.exists(filein) :
111 shutil.copyfile(DictAppli[item],filein)
112 dicoUser = self.DictPath
113 dicoAppli = ConstructDicoPath(self.AppliPath)
115 if not os.path.exists(dicoUser[fi]) and os.path.exists(dicoAppli[fi]):
116 shutil.copyfile(dicoAppli[fi], dicoUser[fi])
118 def CheckRPath(PathPath):
119 if not os.path.exists(PathPath.get('PATHS','rpath')):
124 def FindRPAthWin32():
127 if 'ProgramFiles' in os.environ :
128 progpaths.append(os.environ['ProgramFiles'])
129 if 'ProgramFiles(x86)' in os.environ :
130 progpaths.append(os.environ['ProgramFiles(x86)'])
131 if 'ProgramW6432' in os.environ :
132 progpaths.append(os.environ['ProgramW6432'])
133 progpaths = list(set(progpaths))
135 for progpath in progpaths :
136 rpath = os.path.join(progpath, "R")
137 if os.path.exists(rpath) :
138 for maj in range(3,5) :
139 for i in range(0,30):
140 for j in range(0,20):
141 for poss in ['', 'i386', 'x64'] :
142 path=os.path.join(rpath,"R-%i.%i.%i" % (maj, i, j),'bin',poss,'R.exe')
143 if os.path.exists(path):
149 if os.path.exists('/usr/bin/R'):
150 BestPath='/usr/bin/R'
151 elif os.path.exists('/usr/local/bin/R'):
152 BestPath='/usr/local/bin/R'
155 def RLibsAreInstalled(self) :
156 rlibs = self.pref.get('iramuteq', 'rlibs')
157 if rlibs == 'false' or rlibs == 'False' :
162 def CheckRPackages(self):
163 listdep = ['ca', 'gee', 'ape', 'igraph','proxy', 'wordcloud', 'irlba', 'textometry', 'sna', 'network', 'intergraph', 'rgl']
166 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)
170 dlg.Update(i, "test de %s" % bib)
171 txt = """library("%s")""" % bib
172 tmpscript = tempfile.mktemp(dir=self.TEMPDIR)
173 with open(tmpscript, 'w') as f :
175 test = exec_rcode(self.RPath, tmpscript, wait = True)
177 log.info('packages %s : NOT INSTALLED' % bib)
180 log.info('packages %s : OK' % bib)
181 dlg.Update(len(listdep),'fini')
184 txt = '\n'.join(nolib)
185 msg = """Les bibliothèques de R suivantes sont manquantes :
188 Sans ces bibliothèques, IRamuteq ne fonctionnera pas.
190 - Vous pouvez installer ces bibliothèques manuellement :
193 Tapez install.packages('nom de la bibiothèque')
195 - ou laisser IRamuteq les installer automatiquement en cliquant sur VALIDER .
196 Les bibliothèques seront téléchargées depuis le site miroir de R %s.
197 """ % (txt, self.pref.get('iramuteq','rmirror'))
198 dial = wx.MessageDialog(self, msg, "Installation incomplète", wx.OK | wx.CANCEL | wx.ICON_WARNING)
199 dial.CenterOnParent()
200 val = dial.ShowModal()
202 dlg = wx.ProgressDialog("Installation",
203 "Veuillez patientez...",
204 maximum=len(nolib) + 1,
206 style=wx.PD_APP_MODAL | wx.PD_AUTO_HIDE | wx.PD_ELAPSED_TIME | wx.PD_CAN_ABORT
209 dlg.Update(1, "installation...")
214 dlg.Update(compt, "installation librairie %s" % bib)
216 userdir <- unlist(strsplit(Sys.getenv("R_LIBS_USER"), .Platform$path.sep))[1]
217 if (!file.exists(userdir)) {
218 if (!dir.create(userdir, recursive = TRUE))
219 print('pas possible')
221 .libPaths(c(userdir, .libPaths()))
227 install.packages("%s", repos = "%s")
228 """ % (bib, self.pref.get('iramuteq','rmirror'))
229 tmpscript = tempfile.mktemp(dir=self.TEMPDIR)
230 with open(tmpscript, 'w') as f :
232 test = exec_rcode(self.RPath, tmpscript, wait = False)
233 while test.poll() == None :
234 dlg.Pulse("installation librairie %s" % bib)
236 dlg.Update(len(nolib) + 1, 'fin')
240 self.pref.set('iramuteq', 'rlibs', True)
241 with open(self.ConfigPath['preferences'], 'w') as f :