def _move(self, source, destination): if not SystemUtils.move(source, destination): print 'FAILED TO MOVE: %s -> %s' % (source, destination) return False print 'MOVED: %s -> %s' % (source, destination) return True
def _createEngineJs(self): cb = CoffeescriptBuilder( 'sflow.api.SFlowApi-exec', FileUtils.createPath(StaticFlowEnvironment.rootResourcePath, '..', 'js', isDir=True), buildOnly=True) target = cb.construct()[0] targetFolder = FileUtils.createPath( StaticFlowEnvironment.rootResourcePath, 'web', 'js', isDir=True) result = SiteProcessUtils.compileCoffeescriptFile(target.assembledPath, targetFolder) if result['code']: print 'ERROR: Failed compilation of the Static Flow engine' print result return False sourcePath = FileUtils.createPath(targetFolder, target.name + '.js', isFile=True) destPath = FileUtils.createPath(targetFolder, 'engine.js', isFile=True) SystemUtils.move(sourcePath, destPath) return True
def _handleReplaceDatabase(self): self.mainWindow.showLoading( self, u'Browsing for Database File', u'Choose a valid database (*.vcd) file') defaultPath = self.appConfig.get(UserConfigEnum.DATABASE_IMPORT_PATH) if not defaultPath: defaultPath = self.appConfig.get(UserConfigEnum.LAST_BROWSE_PATH) path = PyGlassBasicDialogManager.browseForFileOpen( parent=self, caption=u'Select Database File', defaultPath=defaultPath) self.mainWindow.hideLoading(self) if not path: self.mainWindow.toggleInteractivity(True) return # Store directory for later use self.appConfig.set( UserConfigEnum.DATABASE_IMPORT_PATH, FileUtils.getDirectoryOf(path) ) self.mainWindow.showStatus( self, u'Replacing Database File', u'Removing existing database file and replacing it with selection') sourcePath = getattr(Tracks_Track, 'URL')[len(u'sqlite:'):].lstrip(u'/') if not OsUtils.isWindows(): sourcePath = u'/' + sourcePath savePath = '%s.store' % sourcePath try: if os.path.exists(savePath): SystemUtils.remove(savePath, throwError=True) except Exception as err: self.mainWindow.appendStatus( self, u'<span style="color:#CC3333">ERROR: Unable to access database save location.</span>') self.mainWindow.showStatusDone(self) return try: SystemUtils.move(sourcePath, savePath) except Exception as err: self.mainWindow.appendStatus( self, u'<span style="color:#CC3333;">ERROR: Unable to modify existing database file.</span>') self.mainWindow.showStatusDone(self) return try: SystemUtils.copy(path, sourcePath) except Exception as err: SystemUtils.move(savePath, sourcePath) self.mainWindow.appendStatus( self, u'<span style="color:#CC3333;">ERROR: Unable to copy new database file.</span>') self.mainWindow.showStatusDone(self) return if os.path.exists(savePath): SystemUtils.remove(savePath) self.mainWindow.appendStatus(self, u'<span style="color:#33CC33;">Database Replaced</span>') self.mainWindow.showStatusDone(self)