def showUpdateDialog(self, auto=False): if not redREnviron.checkInternetConnection(): if not auto: self.createDialog(_('No Internet Connection'), False) return today = date.today() if redREnviron.settings['checkedForUpdates'] != 0: diff = today - redREnviron.settings['checkedForUpdates'] if int(diff.days) < 2 and auto: return redREnviron.settings['checkedForUpdates'] = today redREnviron.saveSettings() avaliable = self.checkForUpdate() if avaliable: html = _("<h2>Red-R %s</h2><h4>Revision:%s; Date: %s</h4><br>%s" ) % (self.availableUpdate['redRVerion'], self.availableUpdate['SVNVersion'], self.availableUpdate['date'], self.availableUpdate['changeLog']) self.createDialog(html, True) elif not avaliable and not auto: self.createDialog( _('You have the most current version of Red-R %s.') % self.version, False)
def loadMirrors(self): self.libMessageBox.clear() if not redREnviron.checkInternetConnection(): self.libMessageBox.setText(_('No Internet Connection, please try again')) return self.libs = RSession.Rcommand('getCRANmirrors()') self.libListBox.update(self.libs['Name'])
def loadMirrors(self): self.libMessageBox.clear() if not redREnviron.checkInternetConnection(): self.libMessageBox.setText( _('No Internet Connection, please try again')) return self.libs = RSession.Rcommand('getCRANmirrors()') self.libListBox.update(self.libs['Name'])
def checkForUpdate(self, auto=True): today = date.today() if not redREnviron.checkInternetConnection(): return if redREnviron.settings['lastUpdateCheck'] != 0: diff = today - redREnviron.settings['lastUpdateCheck'] if int(diff.days) < 7 and auto: return url =redREnviron.settings['updatesRepository'] +'/currentVersion.xml' print 'theurl:', url print 'thesavefile', self.updateFile try: f = urllib2.urlopen(url) output = open(self.updateFile,'wb') output.write(f.read()) output.close() except: redREnviron.settings['updateAvailable'] = False redRLog.log(redRLog.REDRCORE,redRLog.ERROR,'Could not find updates from web.') redREnviron.settings['lastUpdateCheck'] = today redREnviron.saveSettings() self.availableUpdate = self.parseUpdatesXML(self.updateFile) print 'avaliable', self.availableUpdate if self.availableUpdate and (self.availableUpdate['redRVersion'] == redREnviron.version['REDRVERSION'] and self.availableUpdate['SVNVersion'] > redREnviron.version['SVNVERSION']): print auto, self.availableUpdate['SVNVersion'] in redREnviron.settings['ignoredUpdates'] if auto and self.availableUpdate['SVNVersion'] in redREnviron.settings['ignoredUpdates']: redREnviron.settings['updateAvailable'] = False else: redREnviron.settings['updateAvailable'] = True else: redREnviron.settings['updateAvailable'] = False print 'is available', redREnviron.settings['updateAvailable'] redREnviron.saveSettings()
def loadPackagesLists(self, force=True): if force: self.packageManager.updatePackagesFromRepository() self.tabsArea.setCurrentIndex(2) ask = False elif self.packageManager.sitePackages == None or redREnviron.settings[ 'red-RPackagesUpdated'] == 0: ask = True else: from datetime import date today = date.today() diff = today - redREnviron.settings['red-RPackagesUpdated'] if int(diff.days) > 10: ask = True else: ask = False if ask and redREnviron.checkInternetConnection(): if self.isHidden: parent = qApp.canvasDlg else: parent = self mb = QMessageBox("Update Package Repository", "Update package repository for Red-R.org?", QMessageBox.Information, QMessageBox.Ok | QMessageBox.Default, QMessageBox.No | QMessageBox.Escape, QMessageBox.NoButton, parent) if mb.exec_() == QMessageBox.Ok: self.packageManager.updatePackagesFromRepository() self.tabsArea.setCurrentIndex(2) (self.updates, self.localPackages, self.availablePackages) = self.packageManager.getPackages() self.updatesTab.setEnabled(True) self.availableTab.setEnabled(True) self.setUpdates(self.updates) self.setPackageList(self.treeViewInstalled, self.localPackages) self.setPackageList(self.treeViewAvailable, self.availablePackages)
def install_libraries(librarys, repository = 'http://cran.r-project.org'): installedRPackages = getInstalledLibraries() newLibs = [l for l in librarys if l not in installedRPackages] if len(newLibs) == 0: return True if redREnviron.checkInternetConnection(): mb = QMessageBox(_("Download R Library"), _("You are missing some key files for this widget or package.\nYou must install these files to use the widget or package you requested.\nIf you click No or Cancel you will likely see many errors.\nIf you are loading a package the package loading will be aborted.\n\n%s\n\nWould you like to download the Files (Hint: say Yes)?" ) % unicode(','.join(newLibs)), QMessageBox.Information, QMessageBox.Ok | QMessageBox.Default, QMessageBox.Cancel | QMessageBox.Escape, QMessageBox.NoButton) if mb.exec_() == QMessageBox.Ok: try: #updatePackages(repository) redRLog.log(redRLog.R, redRLog.INFO, _('Installing library(s) %s.') % ','.join(newLibs)) Rcommand('setRepositories(ind=1:7)', wantType = 'NoConversion') Rcommand('install.packages(c(%s))' % ','.join(['"%s"' % l for l in newLibs]), wantType = 'NoConversion') except: redRLog.log(redRLog.REDRCORE, redRLog.CRITICAL,_('Library load failed') +"<br>"+ redRLog.formatException()) return False else: return False return True else: return False
def require_librarys(librarys, repository='http://cran.r-project.org'): # if sys.platform=="win32": # libPath = '\"'+os.path.join(redREnviron.directoryNames['RDir'],'library').replace('\\','/')+'\"' # else: # libPath = '\"'+personalLibDir+'\"' #Rcommand('Sys.chmod('+libPath+', mode = "7777")') ## set the file permissions loadedOK = True # print 'libPath', libPath installedRPackages = getInstalledLibraries() Rcommand('local({r <- getOption("repos"); r["CRAN"] <- "' + repository + '"; options(repos=r)})') if type(librarys) == str: # convert to list if it isn't already librarys = [librarys] # print _('librarys'), librarys # print _('installedRPackages'), installedRPackages for library in librarys: if library in loadedLibraries: redRLog.log(redRLog.R, redRLog.DEBUG, _('Library already loaded')) continue # print _('in loop'), library, library in installedRPackages # print installedRPackages if installedRPackages and library and (library in installedRPackages): redRLog.log(redRLog.R, redRLog.DEBUG, 'Loading library %s.' % library) Rcommand('require(' + library + ')') #, lib.loc=' + libPath + ')') loadedLibraries.append(library) elif library: if redREnviron.checkInternetConnection(): mb = QMessageBox( _("Download R Library"), _("You are missing some key files for this widget.\n\n%s\n\nWould you like to download it?" ) % unicode(library), QMessageBox.Information, QMessageBox.Ok | QMessageBox.Default, QMessageBox.Cancel | QMessageBox.Escape, QMessageBox.NoButton, qApp.canvasDlg) if mb.exec_() == QMessageBox.Ok: try: redRLog.log(redRLog.R, redRLog.INFO, _('Installing library %s.') % library) Rcommand('setRepositories(ind=1:7)', wantType='NoConversion') Rcommand( 'install.packages("' + library + '")', wantType='NoConversion') #, lib=' + libPath + ')') loadedOK = Rcommand('require(' + library + ')', wantType='NoConversion' ) # lib.loc=' + libPath + ')') installedRPackages = getInstalledLibraries( ) ## remake the installedRPackages list except: redRLog.log(redRLog.REDRCORE, redRLog.ERROR, redRLog.formatException()) redRLog.log(redRLog.R, redRLog.CRITICAL, _('Library load failed')) loadedOK = False else: loadedOK = False else: loadedOK = False if loadedOK: loadedLibraries.append(library) return loadedOK
def downloadPackages(self, packages, window=None): if not redREnviron.checkInternetConnection(): return False if not window: window = qApp.canvasDlg progressBar = QProgressDialog(window) progressBar.setCancelButtonText(QString()) progressBar.setWindowTitle(_('Installing Packages')) progressBar.setLabelText(_('Installing Packages ...')) progressBar.setMaximum(len(packages.keys()) + 1) i = 0 progressBar.setValue(i) progressBar.show() OK = True for package, status in packages.items(): if status['installed']: continue if not package in self.sitePackages: continue i = i + 1 progressBar.setValue(i) progressBar.setLabelText(_('Installing: %s') % package) try: packageName = unicode( package + '-' + self.sitePackages[package]['Version']['Number'] + '.zip') url = unicode(self.repository + '/' + package + '/' + packageName) path = os.path.join(redREnviron.directoryNames['downloadsDir'], unicode(packageName)) #print url self.urlOpener.retrieve(url, path) #print path self.installRRP(package, path) redRLog.log( redRLog.REDRCORE, redRLog.INFO, _('Installing package %(PACKAGENAME)s from URL %(URL)s into path %(PATH)s' ) % { 'PACKAGENAME': packageName, 'URL': url, 'PATH': path }) except: redRLog.log(redRLog.REDRCORE, redRLog.ERROR, redRLog.formatException()) try: packageName = unicode( package + '-' + self.sitePackages[package]['Version']['Number'] + '.zip') url = unicode(self.repository + '/' + package + '/' + packageName) path = os.path.join( redREnviron.directoryNames['downloadsDir'], unicode(packageName)) #print url self.urlOpener.retrieve(url, path) #print path self.installRRP(package, path) except: redRLog.log(redRLog.REDRCORE, redRLog.ERROR, redRLog.formatException()) OK = False qApp.canvasDlg.reloadWidgets() progressBar.hide() return OK