def write(self, iface, dest_folder, feedback=None): if not feedback: feedback = Feedback() feedback.showFeedback('Creating Leaflet map...') self.preview_file = self.writeLeaflet(iface, feedback, layer_list=self.layers, popup=self.popup, visible=self.visible, json=self.json, cluster=self.cluster, params=self.params, folder=dest_folder) result = WriterResult() result.index_file = self.preview_file result.folder = os.path.dirname(self.preview_file) for dirpath, dirnames, filenames in os.walk(result.folder): result.files.extend([os.path.join(dirpath, f) for f in filenames]) return result
def write(self, iface, dest_folder, feedback=None): if not feedback: feedback = Feedback() feedback.showFeedback('Creating OpenLayers map...') self.preview_file = self.writeOL(iface, feedback, layers=self.layers, groups=self.groups, popup=self.popup, visible=self.visible, json=self.json, clustered=self.cluster, getFeatureInfo=self.getFeatureInfo, settings=self.params, folder=dest_folder) result = WriterResult() result.index_file = self.preview_file result.folder = os.path.dirname(self.preview_file) for dirpath, dirnames, filenames in os.walk(result.folder): result.files.extend([os.path.join(dirpath, f) for f in filenames]) return result
def postProcess(self, results, feedback=None): if not feedback: feedback = Feedback() self.export_file = results.index_file file_count = max(len(results.files), 1) # generate a new temp_folder for next export self.temp_folder = self.newTempFolder(tempFolder()) source_folder = results.folder if not self.host or not self.username or not self.port: return False # get password password = self.password if password is None: password, ok = QInputDialog.getText(None, 'Enter FTP password', 'Password', QLineEdit.Password) if not password or not ok: feedback.setFatalError('User cancelled') return False feedback.showFeedback('Connecting to {} on port {}...'.format( self.host, self.port)) ftp = ftplib.FTP() try: ftp.connect(self.host, self.port) except: feedback.setFatalError('Could not connect to server!') return False feedback.showFeedback('Connected!') feedback.showFeedback('Logging in as {}...'.format(self.username)) if feedback.cancelled(): feedback.acceptCancel() return False try: ftp.login(self.username, password) except: feedback.setFatalError('Login failed for user {}!'.format( self.username)) return False feedback.showFeedback('Logged in to {}'.format(self.host)) def cwd_and_create(p): """ recursively changes directory to an ftp target, creating new folders as required. """ if not p: return try: ftp.cwd(p) except: parent, base = os.path.split(p) cwd_and_create(parent) if base: feedback.showFeedback('Creating {}'.format(base)) ftp.mkd(base) ftp.cwd(base) cwd_and_create(self.remote_folder) feedback.uploaded_count = 0.0 def uploadPath(path): if feedback.cancelled(): feedback.acceptCancel() return False files = os.listdir(path) os.chdir(path) for f in files: if feedback.cancelled(): feedback.acceptCancel() return False current_path = os.path.join(path, f) if os.path.isfile(current_path): feedback.showFeedback('Uploading {}'.format(f)) fh = open(f, 'rb') ftp.storbinary('STOR %s' % f, fh) fh.close() feedback.uploaded_count += 1 feedback.setProgress(100 * feedback.uploaded_count / file_count) elif os.path.isdir(current_path): feedback.showFeedback('Creating folder {}'.format(f)) try: ftp.mkd(f) except: pass ftp.cwd(f) if not uploadPath(current_path): return False ftp.cwd('..') os.chdir('..') return True if not uploadPath(os.path.join('.', source_folder)): return False feedback.setCompleted('Upload complete!') ftp.close() return True
def postProcess(self, results, feedback=None): if not feedback: feedback = Feedback() self.export_file = results.index_file feedback.setCompleted('Exported to {}'.format(unicode(self.folder))) return True