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
14 from ConfigParser import *
15 from time import sleep
18 version_glob = self.ConfigGlob.get('DEFAULT', 'version_nb').split('.')
20 version_user = self.pref.get('iramuteq','version_nb').split('.')
21 except NoOptionError :
24 version_user[0] = int(version_user[0])
25 version_user[1] = int(version_user[1])
26 version_glob[0] = int(version_glob[0])
27 version_glob[1] = int(version_glob[1])
28 if len(version_user) == len(version_glob) :
29 if version_glob > version_user :
33 if len(version_glob) == 2 :
34 if version_glob[:2] >= version_user[:2] :
38 elif len(version_glob) == 3 :
39 if version_glob[:2] <= version_user[:2] :
44 def UpgradeConf(self) :
45 dictuser = self.ConfigPath
46 dictappli = ConstructConfigPath(self.AppliPath, user = False)
47 for item,filein in dictuser.iteritems():
48 if not item == u'global' and not item == u'history':
49 shutil.copyfile(dictappli[item], filein)
51 def CreateIraDirectory(UserConfigPath,AppliPath):
52 if not os.path.exists(UserConfigPath):
53 os.mkdir(UserConfigPath)
56 DictUser = self.ConfigPath
57 DictAppli = ConstructConfigPath(self.AppliPath,user=False)
58 for item, filein in DictUser.iteritems():
59 if not item == u'global' and not item == u'path' and not item == u'preferences' and not item == u'history' :
60 shutil.copyfile(DictAppli[item],filein)
62 if not os.path.exists(filein):
63 shutil.copyfile(DictAppli[item],filein)
64 if item == u'preferences' :
65 if not os.path.exists(filein) :
66 shutil.copyfile(DictAppli[item],filein)
68 def CheckRPath(PathPath):
69 if not os.path.exists(PathPath.get('PATHS','rpath')):
77 if 'ProgramFiles' in os.environ :
78 progpaths.append(os.environ['ProgramFiles'])
79 if 'ProgramFiles(x86)' in os.environ :
80 progpaths.append(os.environ['ProgramFiles(x86)'])
81 if 'ProgramW6432' in os.environ :
82 progpaths.append(os.environ['ProgramW6432'])
83 progpaths = list(set(progpaths))
85 for progpath in progpaths :
86 rpath = os.path.join(progpath, "R")
87 if os.path.exists(rpath) :
90 path=os.path.join(rpath,"R-2."+str(i)+"."+str(j),'bin','R.exe')
91 if os.path.exists(path):
97 if os.path.exists('/usr/bin/R'):
99 elif os.path.exists('/usr/local/bin/R'):
100 BestPath='/usr/local/bin/R'
104 return os.path.exists(Path)
106 def RLibsAreInstalled(self) :
107 rlibs = self.pref.get('iramuteq', 'rlibs')
108 if rlibs == 'false' :
113 def CheckRPackages(self):
114 listdep = ['ca', 'gee', 'ape', 'igraph','proxy', 'Matrix','wordcloud']
117 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)
121 dlg.Update(i, "test de %s" % bib)
122 txt = """library("%s")""" % bib
123 tmpscript = tempfile.mktemp(dir=self.TEMPDIR)
124 file = open(tmpscript, 'w')
127 test = exec_rcode(self.RPath, tmpscript, wait = True)
130 dlg.Update(len(listdep),'fini')
133 txt = '\n'.join(nolib)
134 msg = u"""Les bibliothèques de R suivantes sont manquantes :
137 Sans ces bibliothèques, IRamuteq ne fonctionnera pas.
139 - Vous pouvez installer ces bibliothèques manuellement :
142 Tapez install.packages('nom de la bibiothèque')
144 - ou laisser IRamuteq les installer automatiquement en cliquant sur VALIDER .
145 Les bibliothèques seront téléchargées depuis le site miroir de R du CICT de Toulouse.
147 dial = wx.MessageDialog(self, msg, u"Installation incomplète", wx.OK | wx.CANCEL | wx.NO_DEFAULT | wx.ICON_WARNING)
148 dial.CenterOnParent()
149 val = dial.ShowModal()
151 dlg = wx.ProgressDialog("Installation",
152 "Veuillez patientez...",
153 maximum=len(nolib) + 1,
155 style=wx.PD_APP_MODAL | wx.PD_AUTO_HIDE | wx.PD_ELAPSED_TIME | wx.PD_CAN_ABORT
158 dlg.Update(1, u"installation...")
162 dlg.Update(compt, u"installation librairie %s" % bib)
164 userdir <- unlist(strsplit(Sys.getenv("R_LIBS_USER"), .Platform$path.sep))[1]
165 if (!file.exists(userdir)) {
166 if (!dir.create(userdir, recursive = TRUE))
167 print('pas possible')
169 .libPaths(c(userdir, .libPaths()))
175 install.packages("%s", repos = 'http://cran.cict.fr')
177 tmpscript = tempfile.mktemp(dir=self.TEMPDIR)
178 file = open(tmpscript, 'w')
181 test = exec_rcode(self.RPath, tmpscript, wait = False)
182 while test.poll() == None :
183 dlg.Pulse(u"installation librairie %s" % bib)
185 dlg.Update(len(nolib) + 1, 'fin')
191 self.pref.set('iramuteq', 'rlibs', True)
192 with open(self.ConfigPath['preferences'], 'w') as f :