def update(self): self.preview.settings().clearMemoryCaches() layers, groups, popup, visible = self.getLayersAndGroups() params = self.getParameters() writeOL(layers, groups, popup, visible, params, utils.tempFolder()) self.preview.setUrl(QUrl(self.tempIndexFile())) self.labelPreview.setText('Preview <a href="open">Open in external browser</a>')
def previewLeaflet(self): self.preview.settings().clearMemoryCaches() layers, groups, popup, visible, json, cluster, labels = self.getLayersAndGroups() params = self.getParameters() previewFile = writeLeaflet( self.iface, utils.tempFolder(), 500, 700, 1, layers, visible, "", cluster, "", "", "", labels, 0, 0, json, params, popup, ) self.preview.setUrl(QUrl.fromLocalFile(previewFile))
def previewLeaflet(self): self.preview.settings().clearMemoryCaches() layers, groups, popup, visible, json, cluster, labels = self.getLayersAndGroups() params = self.getParameters() previewFile = writeLeaflet(self.iface, utils.tempFolder(), 500, 700, 1, layers, visible, "", cluster, "", "", "", "", labels, 0, 0, json, params, popup) self.preview.setUrl(QUrl.fromLocalFile(previewFile)) self.labelPreview.setText('Preview <a href="open">Open in external browser</a>')
def postProcess(self, export_file): self.export_file = export_file # generate a new temp_folder for next export self.temp_folder = self.newTempFolder(tempFolder()) source_folder = os.path.dirname(export_file) if not self.host or not self.username or not self.port: return # 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: return ftp = ftplib.FTP() ftp.connect(self.host, self.port) ftp.login(self.username, password) 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: ftp.mkd(base) ftp.cwd(base) cwd_and_create(self.remote_folder) def uploadPath(path): files = os.listdir(path) os.chdir(path) for f in files: current_path = os.path.join(path, f) if os.path.isfile(current_path): fh = open(f, 'rb') ftp.storbinary('STOR %s' % f, fh) fh.close() elif os.path.isdir(current_path): ftp.mkd(f) ftp.cwd(f) uploadPath(current_path) ftp.cwd('..') os.chdir('..') uploadPath(os.path.join('.', source_folder)) ftp.close()
def previewLeaflet(self): self.preview.settings().clearMemoryCaches() (layers, groups, popup, timefrom, timeto, visible, json, cluster) = self.getLayersAndGroups() params = self.getParameters() previewFile = writeLeaflet(self.iface, utils.tempFolder(), layers, visible, cluster, json, params, popup, timefrom, timeto) self.preview.setUrl(QUrl.fromLocalFile(previewFile))
def previewOL3(self): self.preview.settings().clearMemoryCaches() (layers, groups, popup, visible, json, cluster) = self.getLayersAndGroups() params = self.getParameters() previewFile = writeOL(self.iface, layers, groups, popup, visible, json, cluster, params, utils.tempFolder()) self.preview.setUrl(QUrl.fromLocalFile(previewFile))
def previewLeaflet(self): self.preview.settings().clearMemoryCaches() (layers, groups, popup, visible, json, cluster) = self.getLayersAndGroups() params = self.getParameters() previewFile = writeLeaflet(self.iface, utils.tempFolder(), layers, visible, cluster, json, params, popup) self.preview.setUrl(QUrl.fromLocalFile(previewFile))
def previewOL3(self): self.preview.settings().clearMemoryCaches() layers, groups, popup, visible, json, cluster, labels = self.getLayersAndGroups( ) params = self.getParameters() previewFile = writeOL(self.iface, layers, groups, popup, visible, json, cluster, labels, params, utils.tempFolder()) self.preview.setUrl(QUrl.fromLocalFile(previewFile))
def update(self): self.preview.settings().clearMemoryCaches() layers, groups, popup, visible = self.getLayersAndGroups() params = self.getParameters() writeOL(layers, groups, popup, visible, params, utils.tempFolder()) self.preview.setUrl(QUrl(self.tempIndexFile())) self.labelPreview.setText( 'Preview <a href="open">Open in external browser</a>' )
def __init__(self): super(Exporter, self).__init__() # some default values self.host = 'myhost.com' self.username = '******' self.remote_folder = 'public_html/' self.port = 21 # if none, user will be prompted for password self.password = None self.temp_folder = self.newTempFolder(tempFolder())
def createServer(): """ Create a simple (insecure!) ftp server for testing """ global FTP_FOLDER global TEST_PORT global FTP_USER_FOLDER global SERVER_RUNNING if SERVER_RUNNING: return SERVER_RUNNING = True FTP_FOLDER = os.path.join(tempFolder(), 'ftp') if os.path.exists(FTP_FOLDER): shutil.rmtree(FTP_FOLDER) os.makedirs(FTP_FOLDER) FTP_USER_FOLDER = os.path.join(FTP_FOLDER, 'testuser') os.makedirs(FTP_USER_FOLDER) c = checkers.InMemoryUsernamePasswordDatabaseDontUse() c.addUser('testuser', 'pw') def makeService(config): f = ftp.FTPFactory() r = ftp.FTPRealm(config['root'], userHome=config['userhome']) p = portal.Portal(r, config.get('credCheckers', [])) f.tld = config['root'] f.userAnonymous = config['userAnonymous'] f.portal = p f.protocol = ftp.FTP try: portno = int(config['port']) except KeyError: portno = 2121 return internet.TCPServer(portno, f) svc = makeService({ 'root': FTP_FOLDER, 'userhome': FTP_FOLDER, 'userAnonymous': 'anon', 'port': TEST_PORT, 'credCheckers': [c] }) reactor.callWhenRunning(svc.startService) Thread(target=reactor.run, args=(False, )).start()
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
if f.endswith("html")) paramsOL = { "Appearance": { "Add layers list": False, "Match project CRS": False, "Add address search": False, "Layer search": ("None", "placeholder"), "Measure tool": ("None", "Metric", "Imperial"), "Show popups on hover": False, "Highlight on hover": False, "Geolocate user": False, "Template": getTemplates() }, "Data export": { "Export folder": tempFolder(), "Precision": ("maintain", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15"), "Minify GeoJSON files": True, "Mapping library location": ("Local", "CDN") }, "Scale/Zoom": { "Extent": ("Canvas extent", "Fit to layers extent"), "Restrict to extent": False, "Max zoom level": ("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28"), "Min zoom level": ("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21",
def tempIndexFile(self): folder = utils.tempFolder() url = "file:///" + os.path.join(folder, "index.html").replace( "\\", "/") return url
def __init__(self): super(Exporter, self).__init__() self.folder = tempFolder() self.export_file = None
def tempIndexFile(self): folder = utils.tempFolder() url = "file:///"+ os.path.join(folder, "index.html").replace("\\","/") return url
def createPreview(self): writer = self.createWriter() return writer.write(self.iface, dest_folder=utils.tempFolder())
paramsOL = { "Appearance": { "Add layers list": False, "Match project CRS": False, "Add scale bar": False, "Add address search": False, "Measure tool": ("None", "Metric", "Imperial"), "Show popups on hover": False, "Highlight on hover": False, "Geolocate user": False, "Template": getTemplates() }, "Data export": { "Export folder": tempFolder(), "Precision": ("maintain", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15"), "Minify GeoJSON files": True, "Delete unused fields": True, "Mapping library location": ("Local", "CDN") }, "Scale/Zoom": { "Extent": ("Canvas extent", "Fit to layers extent"), "Restrict to extent": False, "Max zoom level": ("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24",