def _handleImportSitemaps(self): self.mainWindow.showLoading( self, u'Browsing for Sitemap File', u'Choose the Sitemap CSV file to import into the database') path = PyGlassBasicDialogManager.browseForFileOpen( parent=self, caption=u'Select CSV File to Import', defaultPath=self.mainWindow.appConfig.get(UserConfigEnum.LAST_BROWSE_PATH) ) self.mainWindow.hideLoading(self) if not path or not StringUtils.isStringType(path): self.mainWindow.toggleInteractivity(True) return # Store directory location as the last active directory self.mainWindow.appConfig.set( UserConfigEnum.LAST_BROWSE_PATH, FileUtils.getDirectoryOf(path) ) self.mainWindow.showStatus( self, u'Importing Sitemaps', u'Reading sitemap information into database') SitemapImporterRemoteThread( parent=self, path=path ).execute( callback=self._sitemapImportComplete, logCallback=self._handleImportStatusUpdate)
def _handleImport(self): label = u'CSV' importType = TrackImporterRemoteThread.CSV self.mainWindow.showLoading( self, u'Browsing for Track File', u'Choose the %s file to import into the database' % label) path = PyGlassBasicDialogManager.browseForFileOpen( parent=self, caption=u'Select %s File to Import' % label, defaultPath=self.mainWindow.appConfig.get(UserConfigEnum.LAST_BROWSE_PATH) ) self.mainWindow.hideLoading(self) if not path or not StringUtils.isStringType(path): self.mainWindow.toggleInteractivity(True) return # Store directory location as the last active directory self.mainWindow.appConfig.set( UserConfigEnum.LAST_BROWSE_PATH, FileUtils.getDirectoryOf(path) ) self.mainWindow.showStatus( self, u'Importing Tracks', u'Reading track information into database') TrackImporterRemoteThread( parent=self, path=path, verbose=self.verboseDisplayCheck.isChecked(), importType=importType, compressed=False ).execute( callback=self._handleImportComplete, logCallback=self._handleImportStatusUpdate )
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)