def getLayerNames(self, refresh=False): '''Returns configured layers for respective layer properties file''' #gdal.SetConfigOption('CPL_DEBUG','ON') #gdal.SetConfigOption('CPL_LOG_ERRORS','ON') if refresh or not self.namelist: self.namelist = [] layer = self.lcfname.ds.GetLayer( self.lcfname.LDS_CONFIG_TABLE) ###fname -> lcfname if layer: layer.SetIgnoredFields(('OGR_GEOMETRY', )) layer.ResetReading() #HACK Win7 layer.GetFeatureCount() feat = layer.GetNextFeature() while feat: try: lcid = feat.GetField('id') lcname = feat.GetField('name') lccats = [ LU.recode(f) if f else None for f in feat.GetField('category').split(',') ] self.namelist += ((LU.recode(lcid) if lcid else None, LU.recode(lcname) if lcname else None, lccats), ) #self.namelist += ((feat.GetField('id').encode('utf8'),feat.GetField('name').encode('utf8'),[f.encode('utf8').strip() for f in feat.GetField('category').split(',')]),) feat = layer.GetNextFeature() except UnicodeEncodeError as uee: raise except UnicodeDecodeError as ude: raise else: ldslog.error('REMINDER! TRIGGER CONF BUILD') #print '>>>>> NAMELIST',self.namelist return self.namelist
def getLayerNames(self,refresh=False): '''Returns configured layers for respective layer properties file''' #gdal.SetConfigOption('CPL_DEBUG','ON') #gdal.SetConfigOption('CPL_LOG_ERRORS','ON') if refresh or not self.namelist: self.namelist = [] layer = self.lcfname.ds.GetLayer(self.lcfname.LDS_CONFIG_TABLE)###fname -> lcfname if layer: layer.SetIgnoredFields(('OGR_GEOMETRY',)) layer.ResetReading() #HACK Win7 layer.GetFeatureCount() feat = layer.GetNextFeature() while feat: try: lcid = feat.GetField('id') lcname = feat.GetField('name') lccats = [LU.recode(f) if f else None for f in feat.GetField('category').split(',')] self.namelist += ((LU.recode(lcid) if lcid else None, LU.recode(lcname) if lcname else None,lccats),) #self.namelist += ((feat.GetField('id').encode('utf8'),feat.GetField('name').encode('utf8'),[f.encode('utf8').strip() for f in feat.GetField('category').split(',')]),) feat = layer.GetNextFeature() except UnicodeEncodeError as uee: raise except UnicodeDecodeError as ude: raise else: ldslog.error('REMINDER! TRIGGER CONF BUILD') #print '>>>>> NAMELIST',self.namelist return self.namelist
def buildLayerGroupList(self,groups=None,layers=None): '''Sets the array storing values displayed in the Layer/Group combo; format is ((lyr/grp, name, displaystring),)''' from lds.TransferProcessor import LORG #self.lgcombo.addItems(('',TransferProcessor.LG_PREFIX['g'])) self.lglist = [] # lorg,value,display for g in sorted(groups if groups else self.assigned): self.lglist += ((LORG.GROUP,LU.recode(g),u'{} (group)'.format(LU.recode(g))),) for l in sorted(layers if layers else self.vlayers): #if re.search('Electoral',l[0]): if not isinstance(l,(tuple,list)): raise LayerConfigInitialisationException('Layer init value error. {} is not a list/tuple'.format(l)) self.lglist += ((LORG.LAYER,l[0],u'{} ({})'.format(l[1],l[0])),)
def doRejectClickAction(self): '''Takes available selected and moves to selection''' #ktext = LU.recode(self.keywordcombo.lineEdit().text().toUtf8().data()) ktext = LU.recode( LQ.readWidgetText(self.keywordcombo.lineEdit().text())) if not self.checkKeyword(ktext): return #------------------------------ select = self.selection.selectionModel() if select.hasSelection(): tlist = self.transferSelectedRows(select.selectedRows(), self.selection_sfpm, self.available_sfpm) #------------------------------ kindex = self.keywordcombo.findText(ktext) remainder = self.parent.deleteKeysFromLayerConfig( [ll[1][0] for ll in tlist], ktext) if remainder > 0 and kindex == -1: #items+newkey -> add self.parent.writeKeysToLayerConfig(ktext) self.keywordcombo.addItem(ktext) elif remainder == 0 and kindex > -1: #empty+oldkey -> del self.keywordcombo.removeItem(kindex) self.keywordcombo.clearEditText() else: ldslog.warn('R2L < Transfer action without selection') #TRACE# #pdb.set_trace() self.selection.clearSelection()
def buildLayerGroupList(self, groups=None, layers=None): '''Sets the array storing values displayed in the Layer/Group combo; format is ((lyr/grp, name, displaystring),)''' from lds.TransferProcessor import LORG #self.lgcombo.addItems(('',TransferProcessor.LG_PREFIX['g'])) self.lglist = [] # lorg,value,display for g in sorted(groups if groups else self.assigned): self.lglist += ((LORG.GROUP, LU.recode(g), u'{} (group)'.format(LU.recode(g))), ) for l in sorted(layers if layers else self.vlayers): #if re.search('Electoral',l[0]): if not isinstance(l, (tuple, list)): raise LayerConfigInitialisationException( 'Layer init value error. {} is not a list/tuple'.format(l)) self.lglist += ((LORG.LAYER, l[0], u'{} ({})'.format(l[1], l[0])), )
def deleteKeysFromLayerConfig(self, layerlist, ckey): '''Remove custom keys from selected layers''' replacementlist = () dep = self.parent.confconn.reg.openEndPoint( self.parent.confconn.destname, self.parent.confconn.uconf) #print 'opening',dep#DEBUG self.parent.confconn.reg.setupLayerConfig(self.parent.confconn.tp, None, dep, initlc=False) categorylist = [ f.encode('utf8').strip() for f in dep.getLayerConf().readLayerProperty( layerlist, 'category') if f ] for cat in categorylist: #replacementlist += (re.sub(',+',',',''.join(cat.split(ckey)).strip(',')),) try: cat = cat.split(',') cat.remove(LU.recode(ckey, uflag='encode')) except ValueError: pass replacementlist += (','.join(cat), ) dep.getLayerConf().writeLayerProperty(layerlist, 'category', replacementlist) #----------------------------------- self.parent.confconn.setupCompleteLayerList(dep) self.parent.confconn.setupAssignedLayerList() self.parent.confconn.buildLayerGroupList() #self.refreshLayers(dep,customkey) self.parent.confconn.reg.closeEndPoint(self.parent.confconn.destname) #print 'closing', dep,self.parent.confconn.reg#DEBUG dep = None return self.selection_model.rowCount()
def doRejectClickAction(self): '''Takes available selected and moves to selection''' #ktext = LU.recode(self.keywordcombo.lineEdit().text().toUtf8().data()) ktext = LU.recode(LQ.readWidgetText(self.keywordcombo.lineEdit().text())) if not self.checkKeyword(ktext): return #------------------------------ select = self.selection.selectionModel() if select.hasSelection(): tlist = self.transferSelectedRows(select.selectedRows(),self.selection_sfpm,self.available_sfpm) #------------------------------ kindex = self.keywordcombo.findText(ktext) remainder = self.parent.deleteKeysFromLayerConfig([ll[1][0] for ll in tlist],ktext) if remainder > 0 and kindex == -1: #items+newkey -> add self.parent.writeKeysToLayerConfig(ktext) self.keywordcombo.addItem(ktext) elif remainder == 0 and kindex > -1: #empty+oldkey -> del self.keywordcombo.removeItem(kindex) self.keywordcombo.clearEditText() else: ldslog.warn('R2L < Transfer action without selection') #TRACE# #pdb.set_trace() self.selection.clearSelection()
def closeEvent(self, event): '''Intercept close event to signal parent to update status''' self.parent.controls.setStatus(self.parent.controls.STATUS.IDLE, 'Done') #return last group selection #lastgroup = LU.recode(self.page.keywordcombo.lineEdit().text().toUtf8().data()) lastgroup = LU.recode( LQ.readWidgetText(self.page.keywordcombo.lineEdit().text())) #self.parent.controls.gpr.writeline('lgvalue',lastgroup) if LU.assessNone(lastgroup): dep = self.parent.confconn.reg.openEndPoint( self.parent.confconn.destname, self.parent.confconn.uconf) #sep = self.parent.confconn.reg.openEndPoint('WFS',self.parent.confconn.uconf) self.parent.confconn.reg.setupLayerConfig(self.parent.confconn.tp, None, dep) self.parent.confconn.setupCompleteLayerList(dep) self.parent.confconn.setupAssignedLayerList() self.parent.confconn.buildLayerGroupList() lgindex = self.parent.confconn.getLayerGroupIndex(lastgroup, col=1) self.parent.controls.refreshLGCombo() #current index wont be available in parent if this is the init run self.parent.controls.lgcombo.setCurrentIndex( lgindex if lgindex else 0) #self.parent.confconn.reg.closeEndPoint('WFS') self.parent.confconn.reg.closeEndPoint( self.parent.confconn.destname) sep, dep = None, None
def deleteKeysFromLayerConfig(self,layerlist,ckey): '''Remove custom keys from selected layers''' replacementlist = () dep = self.parent.confconn.reg.openEndPoint(self.parent.confconn.destname,self.parent.confconn.uconf) #print 'opening',dep#DEBUG self.parent.confconn.reg.setupLayerConfig(self.parent.confconn.tp,None,dep,initlc=False) categorylist = [f.encode('utf8').strip() for f in dep.getLayerConf().readLayerProperty(layerlist, 'category') if f] for cat in categorylist: #replacementlist += (re.sub(',+',',',''.join(cat.split(ckey)).strip(',')),) try: cat = cat.split(',') cat.remove(LU.recode(ckey,uflag='encode')) except ValueError: pass replacementlist += (','.join(cat),) dep.getLayerConf().writeLayerProperty(layerlist, 'category', replacementlist) #----------------------------------- self.parent.confconn.setupCompleteLayerList(dep) self.parent.confconn.setupAssignedLayerList() self.parent.confconn.buildLayerGroupList() #self.refreshLayers(dep,customkey) self.parent.confconn.reg.closeEndPoint(self.parent.confconn.destname) #print 'closing', dep,self.parent.confconn.reg#DEBUG dep = None return self.selection_model.rowCount()
def _reTag(self,layerlist,tagname,addtag): '''Add/Delete a keyword from all the layers in the provided list''' for layer in layerlist: keywords = set([LU.recode(f,uflag='encode') for f in self.readLayerProperty(layer, 'Category').split(',')]) if addtag: keywords.add(tagname) else: keywords.remove(tagname) self.writeLayerProperty(layer, 'Category', ','.join(keywords))
def readLayerProperty(self,pkey,field): '''Single property reader''' plist = () layer = self.lcfname.ds.GetLayer(self.lcfname.LDS_CONFIG_TABLE)###fname -> lcfname layer.ResetReading() #HACK Win7 layer.GetFeatureCount() if isinstance(pkey,tuple) or isinstance(pkey,list): for p in pkey: f = self.lcfname._findMatchingFeature(layer, 'id', p)###fname -> lcfname #plist += ('' if f is None else f.GetField(field).encode('utf8'),) plist += ('' if f is None else LU.recode(f.GetField(field)),) return plist else: feat = self.lcfname._findMatchingFeature(layer, 'id', pkey) if feat is None: return None prop = feat.GetField(field) return LU.recode(prop) if LU.assessNone(prop) else None#.encode('utf8')
def _reTag(self, layerlist, tagname, addtag): '''Add/Delete a keyword from all the layers in the provided list''' for layer in layerlist: keywords = set([ LU.recode(f, uflag='encode') for f in self.readLayerProperty(layer, 'Category').split(',') ]) if addtag: keywords.add(tagname) else: keywords.remove(tagname) self.writeLayerProperty(layer, 'Category', ','.join(keywords))
def readLayerProperty(self, pkey, field): '''Single property reader''' plist = () layer = self.lcfname.ds.GetLayer( self.lcfname.LDS_CONFIG_TABLE) ###fname -> lcfname layer.ResetReading() #HACK Win7 layer.GetFeatureCount() if isinstance(pkey, tuple) or isinstance(pkey, list): for p in pkey: f = self.lcfname._findMatchingFeature(layer, 'id', p) ###fname -> lcfname #plist += ('' if f is None else f.GetField(field).encode('utf8'),) plist += ('' if f is None else LU.recode(f.GetField(field)), ) return plist else: feat = self.lcfname._findMatchingFeature(layer, 'id', pkey) if feat is None: return None prop = feat.GetField(field) return LU.recode(prop) if LU.assessNone( prop) else None #.encode('utf8')
def getLayerGroupIndex(self,dispval,col=2): '''Finds a matching group/layer entry from its displayed name''' #0=lorg,1=value,2=display compval = LU.recode(dispval) if not LU.assessNone(compval): ldslog.warn('No attempt made to find index for empty group/layer request, "{}"'.format(compval)) return None# or 0? try: #print 'lgl',[type(i[1]) for i in self.lglist],'\ncv',type(compval) index = [i[col] for i in self.lglist].index(compval) except ValueError as ve: ldslog.warn(u'Cannot find an index in column {} for the requested group/layer, "{}", from {} layers. Returning None index'.format(col,compval,len(self.lglist))) index = None return index
def doChooseAllClickAction(self): '''Moves the lot to Selected''' #ktext = LU.recode(self.keywordcombo.lineEdit().text().toUtf8().data()) ktext = LU.recode(LQ.readWidgetText(self.keywordcombo.lineEdit().text())) if not self.checkKeyword(ktext): return #------------------------------ self.parent.signalModels(self.parent.STEP.PRE) #self.parent.selection_model.mdata += self.parent.available_model.mdata self.parent.selection_model.initData(self.confconn_link.complete) self.parent.available_model.initData([]) self.parent.signalModels(self.parent.STEP.POST) #------------------------------ self.parent.writeKeysToLayerConfig(ktext) #self.confconn_link.setupAssignedLayerList() if self.keywordcombo.findText(ktext) == -1: self.keywordcombo.addItem(ktext)
def doKeyComboChangeAction(self): '''Reset the available pane and if there is anything in the keyword box use this to init the selection pane''' #HACK #if self.keywordbypass: # self.keywordbypass = False # return #------------------------------ #ktext = LU.recode(self.keywordcombo.lineEdit().text().toUtf8().data()) ktext = LU.recode(LQ.readWidgetText(self.keywordcombo.lineEdit().text())) #------------------------------ av_sl = self.parent.splitData(ktext,self.confconn_link.complete) #av_sl = self.parent.splitData(ktext,self.confconn_link.complete) self.parent.signalModels(self.parent.STEP.PRE) self.parent.available_model.initData(av_sl[0]) self.parent.selection_model.initData(av_sl[1]) self.parent.signalModels(self.parent.STEP.POST)
def doKeyComboChangeAction(self): '''Reset the available pane and if there is anything in the keyword box use this to init the selection pane''' #HACK #if self.keywordbypass: # self.keywordbypass = False # return #------------------------------ #ktext = LU.recode(self.keywordcombo.lineEdit().text().toUtf8().data()) ktext = LU.recode( LQ.readWidgetText(self.keywordcombo.lineEdit().text())) #------------------------------ av_sl = self.parent.splitData(ktext, self.confconn_link.complete) #av_sl = self.parent.splitData(ktext,self.confconn_link.complete) self.parent.signalModels(self.parent.STEP.PRE) self.parent.available_model.initData(av_sl[0]) self.parent.selection_model.initData(av_sl[1]) self.parent.signalModels(self.parent.STEP.POST)
def doRejectAllClickAction(self): #ktext = LU.recode(self.keywordcombo.lineEdit().text().toUtf8().data()) ktext = LU.recode(LQ.readWidgetText(self.keywordcombo.lineEdit().text())) if not self.checkKeyword(ktext): return #------------------------------ self.parent.deleteKeysFromLayerConfig([ll[0] for ll in self.parent.selection_model.mdata],ktext) #------------------------------ self.parent.signalModels(self.parent.STEP.PRE) #self.parent.available_model.mdata += self.parent.selection_model.mdata self.parent.available_model.initData(self.confconn_link.complete) self.parent.selection_model.initData([]) self.parent.signalModels(self.parent.STEP.POST) #------------------------------ #self.confconn_link.setupAssignedLayerList() #self.keywordbypass = True self.keywordcombo.removeItem(self.keywordcombo.findText(ktext)) self.keywordcombo.clearEditText()
def doChooseAllClickAction(self): '''Moves the lot to Selected''' #ktext = LU.recode(self.keywordcombo.lineEdit().text().toUtf8().data()) ktext = LU.recode( LQ.readWidgetText(self.keywordcombo.lineEdit().text())) if not self.checkKeyword(ktext): return #------------------------------ self.parent.signalModels(self.parent.STEP.PRE) #self.parent.selection_model.mdata += self.parent.available_model.mdata self.parent.selection_model.initData(self.confconn_link.complete) self.parent.available_model.initData([]) self.parent.signalModels(self.parent.STEP.POST) #------------------------------ self.parent.writeKeysToLayerConfig(ktext) #self.confconn_link.setupAssignedLayerList() if self.keywordcombo.findText(ktext) == -1: self.keywordcombo.addItem(ktext)
def getLayerGroupIndex(self, dispval, col=2): '''Finds a matching group/layer entry from its displayed name''' #0=lorg,1=value,2=display compval = LU.recode(dispval) if not LU.assessNone(compval): ldslog.warn( 'No attempt made to find index for empty group/layer request, "{}"' .format(compval)) return None # or 0? try: #print 'lgl',[type(i[1]) for i in self.lglist],'\ncv',type(compval) index = [i[col] for i in self.lglist].index(compval) except ValueError as ve: ldslog.warn( u'Cannot find an index in column {} for the requested group/layer, "{}", from {} layers. Returning None index' .format(col, compval, len(self.lglist))) index = None return index
def doRejectAllClickAction(self): #ktext = LU.recode(self.keywordcombo.lineEdit().text().toUtf8().data()) ktext = LU.recode( LQ.readWidgetText(self.keywordcombo.lineEdit().text())) if not self.checkKeyword(ktext): return #------------------------------ self.parent.deleteKeysFromLayerConfig( [ll[0] for ll in self.parent.selection_model.mdata], ktext) #------------------------------ self.parent.signalModels(self.parent.STEP.PRE) #self.parent.available_model.mdata += self.parent.selection_model.mdata self.parent.available_model.initData(self.confconn_link.complete) self.parent.selection_model.initData([]) self.parent.signalModels(self.parent.STEP.POST) #------------------------------ #self.confconn_link.setupAssignedLayerList() #self.keywordbypass = True self.keywordcombo.removeItem(self.keywordcombo.findText(ktext)) self.keywordcombo.clearEditText()
def closeEvent(self,event): '''Intercept close event to signal parent to update status''' self.parent.controls.setStatus(self.parent.controls.STATUS.IDLE,'Done') #return last group selection #lastgroup = LU.recode(self.page.keywordcombo.lineEdit().text().toUtf8().data()) lastgroup = LU.recode(LQ.readWidgetText(self.page.keywordcombo.lineEdit().text())) #self.parent.controls.gpr.writeline('lgvalue',lastgroup) if LU.assessNone(lastgroup): dep = self.parent.confconn.reg.openEndPoint(self.parent.confconn.destname,self.parent.confconn.uconf) #sep = self.parent.confconn.reg.openEndPoint('WFS',self.parent.confconn.uconf) self.parent.confconn.reg.setupLayerConfig(self.parent.confconn.tp,None,dep) self.parent.confconn.setupCompleteLayerList(dep) self.parent.confconn.setupAssignedLayerList() self.parent.confconn.buildLayerGroupList() lgindex = self.parent.confconn.getLayerGroupIndex(lastgroup,col=1) self.parent.controls.refreshLGCombo() #current index wont be available in parent if this is the init run self.parent.controls.lgcombo.setCurrentIndex(lgindex if lgindex else 0) #self.parent.confconn.reg.closeEndPoint('WFS') self.parent.confconn.reg.closeEndPoint(self.parent.confconn.destname) sep,dep = None,None
def __init__(self,parent=None): '''Main entry point for the Layer selection dialog''' super(LayerConfigSelector, self).__init__(parent) self.parent = parent #Build models splitting by keyword if necessary #print 'LGVAL in LCS',self.parent.confconn.lgval av_sl = self.splitData(LU.recode(self.parent.confconn.lgval),self.parent.confconn.complete) #if self.parent.confconn.lgval and self.parent.confconn.complete else (list(self.parent.confconn.complete),[]) self.available_model = LayerTableModel('L::available',self) self.available_model.initData(av_sl[0],self.parent.confconn.inclayers) self.selection_model = LayerTableModel('R::selection',self) self.selection_model.initData(av_sl[1],self.parent.confconn.inclayers) self.page = LayerSelectionPage(self) self.setCentralWidget(self.page) self.setWindowTitle("LDS Layer Selection") self.resize(725,480)
def doChooseClickAction(self): '''Takes available selected and moves to selection''' #ktext = LU.recode(self.keywordcombo.lineEdit().text().toUtf8().data()) ktext = LU.recode(LQ.readWidgetText(self.keywordcombo.lineEdit().text())) #ktext = str(self.keywordcombo.lineEdit().text()) if not self.checkKeyword(ktext): return #------------------------------ select = self.available.selectionModel() if select.hasSelection(): self.transferSelectedRows(select.selectedRows(),self.available_sfpm,self.selection_sfpm) #------------------------------ self.parent.writeKeysToLayerConfig(ktext) #self.confconn_link.assigned = self.confconn_link.setupAssignedLayerList() # -1 to indicate no index since 0,1,... are valid if self.keywordcombo.findText(ktext) == -1: self.keywordcombo.addItem(ktext) else: ldslog.warn('L2R > Transfer action without selection') #TRACE# #pdb.set_trace() self.available.clearSelection()
def doChooseClickAction(self): '''Takes available selected and moves to selection''' #ktext = LU.recode(self.keywordcombo.lineEdit().text().toUtf8().data()) ktext = LU.recode( LQ.readWidgetText(self.keywordcombo.lineEdit().text())) #ktext = str(self.keywordcombo.lineEdit().text()) if not self.checkKeyword(ktext): return #------------------------------ select = self.available.selectionModel() if select.hasSelection(): self.transferSelectedRows(select.selectedRows(), self.available_sfpm, self.selection_sfpm) #------------------------------ self.parent.writeKeysToLayerConfig(ktext) #self.confconn_link.assigned = self.confconn_link.setupAssignedLayerList() # -1 to indicate no index since 0,1,... are valid if self.keywordcombo.findText(ktext) == -1: self.keywordcombo.addItem(ktext) else: ldslog.warn('L2R > Transfer action without selection') #TRACE# #pdb.set_trace() self.available.clearSelection()
def __init__(self, parent=None): '''Main entry point for the Layer selection dialog''' super(LayerConfigSelector, self).__init__(parent) self.parent = parent #Build models splitting by keyword if necessary #print 'LGVAL in LCS',self.parent.confconn.lgval av_sl = self.splitData( LU.recode(self.parent.confconn.lgval), self.parent.confconn.complete ) #if self.parent.confconn.lgval and self.parent.confconn.complete else (list(self.parent.confconn.complete),[]) self.available_model = LayerTableModel('L::available', self) self.available_model.initData(av_sl[0], self.parent.confconn.inclayers) self.selection_model = LayerTableModel('R::selection', self) self.selection_model.initData(av_sl[1], self.parent.confconn.inclayers) self.page = LayerSelectionPage(self) self.setCentralWidget(self.page) self.setWindowTitle("LDS Layer Selection") self.resize(725, 480)
def _setFeatureValue(self,layer,p,field,value): feat = self.lcfname._findMatchingFeature(layer, 'id', p)###fname -> lcfname feat.SetField(field,LU.recode(value,uflag='encode')) layer.SetFeature(feat)
def initializePage(self): '''Override initpage''' super(ConfirmationPage, self).initializePage() hfont = QFont() #hfont.setPointSize(11) hfont.setBold(True) vbox = QVBoxLayout() sec1 = QLabel('LDS') sec1.setFont(hfont) vbox.addWidget(sec1) self.ldsfile = LU.recode(self.field("ldsfile")) hbox1 = QHBoxLayout() hbox1.addWidget(QLabel('LDS File Name')) hbox1.addWidget(QLabel(self.ldsfile)) vbox.addLayout(hbox1) hbox2 = QHBoxLayout() hbox2.addWidget(QLabel('LDS API Key')) #hbox2.addWidget(QLabel(self.field("ldsapikey").toString())) hbox2.addWidget(QLabel(LU.recode(self.field("ldsapikey")))) vbox.addLayout(hbox2) hbox7 = QHBoxLayout() hbox7.addWidget(QLabel('In/Ex Config')) #hbox7.addWidget(QLabel('Internal' if self.field("ldsinternal").toBool() else 'External')) hbox7.addWidget(QLabel('Internal' if self.field("ldsinternal") else 'External')) vbox.addLayout(hbox7) sec2 = QLabel('Proxy') sec2.setFont(hfont) vbox.addWidget(sec2) if self.field("proxy"+WFSDataStore.PROXY_TYPE[2]): #if self.field("proxyproxy").toBool(): hboxp = QHBoxLayout() hboxp.addWidget(QLabel('Proxy Type')) hboxp.addWidget(QLabel(WFSDataStore.PROXY_TYPE[2])) hbox3 = QHBoxLayout() hbox3.addWidget(QLabel('Proxy Server')) #hbox3.addWidget(QLabel(self.field("proxyhost").toString())) hbox3.addWidget(QLabel(LU.recode(self.field("proxyhost")))) vbox.addLayout(hbox3) hbox4 = QHBoxLayout() hbox4.addWidget(QLabel('Proxy Port')) #hbox4.addWidget(QLabel(self.field("proxyport").toString())) hbox4.addWidget(QLabel(LU.recode(self.field("proxyport")))) vbox.addLayout(hbox4) hbox5 = QHBoxLayout() hbox5.addWidget(QLabel('Proxy Auth')) #hbox5.addWidget(QLabel(self.field("proxyauth").toString())) hbox5.addWidget(QLabel(LU.recode(self.field("proxyauth")))) vbox.addLayout(hbox5) hbox6 = QHBoxLayout() hbox6.addWidget(QLabel('Proxy User')) #hbox6.addWidget(QLabel(self.field("proxyusr").toString())) hbox6.addWidget(QLabel(LU.recode(self.field("proxyusr")))) vbox.addLayout(hbox6) elif self.field("proxy"+WFSDataStore.PROXY_TYPE[1]): hbox3 = QHBoxLayout() hbox3.addWidget(QLabel('Proxy Type')) hbox3.addWidget(QLabel(WFSDataStore.PROXY_TYPE[1])) vbox.addLayout(hbox3) elif self.field("proxy"+WFSDataStore.PROXY_TYPE[0]): hbox3 = QHBoxLayout() hbox3.addWidget(QLabel('Proxy Type')) hbox3.addWidget(QLabel(WFSDataStore.PROXY_TYPE[0])) vbox.addLayout(hbox3) else: ldslog.error('No Proxy defined') #select dest from index of destcombo ie PostgreSQL, FileGDB etc self.selected = self.destlist.get(self.field("ldsdest")) sec3 = QLabel(self.selected[0]) sec3.setFont(hfont) vbox.addWidget(sec3) self.selectedfields = self.selected[1]() for f in self.selectedfields: if f[0] is not 'pass': name = QLabel(f[1]) value = QLabel(f[2]) hbox = QHBoxLayout() hbox.addWidget(name) hbox.addWidget(value) vbox.addLayout(hbox) self.setLayout(vbox)
def setActiveFilter(self,text): #self.ftext = LU.recode(text.toUtf8().data()) self.ftext = LU.recode(LQ.readWidgetText(text).toUtf8().data()) self.invalidateFilter()
def report(self,pct,lyr=None): # tp cc repl con ldslog.info('Progress: '+str(pct)+'%') self.pgbar.emit(pct) if lyr: self.status.emit(2,'Replicating Layer '+LU.recode(lyr),'')
def _setFeatureValue(self, layer, p, field, value): feat = self.lcfname._findMatchingFeature(layer, 'id', p) ###fname -> lcfname feat.SetField(field, LU.recode(value, uflag='encode')) layer.SetFeature(feat)
def setActiveFilter(self, text): #self.ftext = LU.recode(text.toUtf8().data()) #self.ftext = LU.recode(LQ.readWidgetText(text).toUtf8().data()) self.ftext = LU.recode(LQ.readWidgetText(text)) self.invalidateFilter()
def report(self, pct, lyr=None): # tp cc repl con ldslog.info('Progress: ' + str(pct) + '%') self.pgbar.emit(pct) if lyr: self.status.emit(2, 'Replicating Layer ' + LU.recode(lyr), '')
def processLDS(self): '''Process with LDS as a source and the destination supplied as an argument''' #fname = dst.DRIVER_NAME.lower()+self.LP_SUFFIX self.dst.applyConfigOptions() self.dst.setSRS(self.epsg) #might as well initds here, its going to be needed eventually if not self.dst.getDS(): ldslog.info('Initialising absent DST.DS. This is not recommended in GUI/threaded mode') self.dst.setDS(self.dst.initDS(self.dst.destinationURI(None)))#DataStore.LDS_CONFIG_TABLE)) self.dst.versionCheck() (self.sixtyfourlayers,self.partitionlayers,self.partitionsize,self.prefetchsize) = self.dst.confwrap.readDSParameters('Misc',{'idp':self.src.idp}) if not self.dst.getLayerConf(): self.dst.setLayerConf(TransferProcessor.getNewLayerConf(self.dst)) #still used on command line if self.getInitConfig(): TransferProcessor.initialiseLayerConfig(self.src,self.dst) if self.dst.getLayerConf() is None: raise LayerConfigurationException("Cannot initialise Layer-Configuration file/table, "+str(self.dst.getConfInternal())) #------------------------------------------------------------------------------------------ #Valid layers are those that exist in LDS and are also configured in the LC self.readCapsDoc(self.src) lds_valid = [i[0] for i in self.assembleLayerList(intersect=True)] #if layer provided, check that layer is in valid list #else if group then intersect valid and group members lgid = self.idLayerOrGroup(self.lgval) if lgid == LORG.GROUP: self.lnl = set() group = set(self.lgval.split(',')) for lid in lds_valid: cats = self.dst.getLayerConf().readLayerProperty(lid,'category') #if cats and set([f.encode('utf8').strip() for f in cats.split(',')]).intersection(group): if cats and set([LU.recode(f) for f in cats.split(',')]).intersection(group): self.lnl.update((lid,)) if not len(self.lnl): ldslog.warn('Possible mis-identified Group, {}'.format(group)) lgid = LORG.LAYER if lgid == LORG.LAYER: layer = LU.checkLayerName(self.dst.getLayerConf(),self.lgval) if layer in lds_valid: self.lnl = (layer,) else: raise InputMisconfigurationException('Layer '+str(layer)+' invalid') #override config file dates with command line dates if provided ldslog.debug("SelectedLayers={}".format(len(self.lnl))) #ldslog.debug("Layer List:"+str(self.lnl)) #------------------------------------------------------------------------------------------ #Before we go any further, if this is a cleaning job, no point doing anymore setup. Start deleting if self.getCleanConfig(): for cleanlayer in self.lnl: self.cleanLayer(cleanlayer,truncate=False) return #build a list of layers with corresponding lastmodified/incremental flags fd = LU.checkDateFormat(self.fromdate)#if date format wrong treated as None td = LU.checkDateFormat(self.todate) self.layer_total = len(self.lnl) self.layer_count = 0 for each_layer in self.lnl: ldslog.debug('BENCHMARK '+each_layer) lm = LU.checkDateFormat(self.dst.getLastModified(each_layer)) srs = self.dst.getEPSGConversion(each_layer) pk = self.hasPrimaryKey(each_layer) filt = self.dst.getLayerConf().readLayerProperty(each_layer,'cql') #Set (cql) filters in URI call using layer picking the one with highest precedence self.src.setFilter(LU.precedence(self.cql,self.dst.getFilter(),filt)) #SRS are set in the DST since the conversion takes place during the write process. Needed here to trigger bypass to featureCopy #print 'tp.epsg=',self.epsg,'srs=',srs,'!getsrs=',self.dst.getSRS() self.dst.setSRS(LU.precedence(self.epsg,srs,None)) #Destination URI won't change because of incremental so set it here self.dst.setURI(self.dst.destinationURI(each_layer)) #RB dst (not implemented) #self.dst.setURI(self.dst.requestbuilder.destinationURI(each_layer)) #if PK is none do paging since page index uses pk (can't lookup matching FIDs for updates/deletes?) if pk: gdal.SetConfigOption('OGR_WFS_PAGING_ALLOWED','ON') else: gdal.SetConfigOption('OGR_WFS_PAGING_ALLOWED','OFF') #check dates -> check incr read -> incr or non nonincr = False if any(i for i in [lm, fd, td]) and pk: ldslog.debug('lm={}, fd={}, td={}'.format(lm,fd,td)) final_fd = (DataStore.EARLIEST_INIT_DATE if lm is None else lm) if fd is None else fd final_td = self.dst.getCurrent() if td is None else td if (datetime.strptime(final_td,'%Y-%m-%dT%H:%M:%S')-datetime.strptime(final_fd,'%Y-%m-%dT%H:%M:%S')).days>0: #self.src.setURI(self.src.sourceURIIncremental(each_layer,final_fd,final_td)) #RB srci self.src.setURI(self.src.requestbuilder.sourceURIIncremental(each_layer,final_fd,final_td)) if self.readLayer(): self.dst.setIncremental() self.dst.setPrefetchSize(self.prefetchsize) ldslog.info('Layer='+str(each_layer)+' lastmodified='+str(final_td)) ldslog.info('Layer='+str(each_layer)+' epsg='+str(self.dst.getSRS())) self.dst.write(self.src, self.dst.getURI(), each_layer, self.getSixtyFour(each_layer)) #---------------------------------------------------------- #self.dst.getLayerConf().writeLayerProperty(each_layer,'lastmodified',final_td) #self.dst.getLayerConf().writeLayerProperty(each_layer,'epsg',self.dst.getSRS()) self.dst.setLastModified(each_layer,final_td) self.dst.saveEPSGConversion(each_layer,self.dst.getSRS()) else: ldslog.warn('Incremental Read failed. Switching to Non-Incremental') nonincr = True else: ldslog.warning("No update required for layer "+each_layer+" since [start:"+final_fd+" >= finish:"+final_td+"] by at least 1 day") continue else: nonincr = True #-------------------------------------------------- if nonincr: #self.src.setURI(self.src.sourceURI(each_layer)) #RB src self.src.setURI(self.src.requestbuilder.sourceURI(each_layer)) if self.readLayer(): self.dst.clearIncremental() self.cleanLayer(each_layer,truncate=True) ldslog.info('Cleaning Layer={} epsg={}'.format(each_layer,self.dst.getSRS())) self.dst.write(self.src, self.dst.getURI(), each_layer, self.getSixtyFour(each_layer)) #since no date provided defaults to current #self.dst.getLayerConf().writeLayerProperty(each_layer,'epsg',self.dst.getSRS()) self.dst.setLastModified(each_layer) self.dst.saveEPSGConversion(each_layer,self.dst.getSRS()) else: ldslog.warn('Non-Incremental Read failed') raise DatasourceInitialisationException('Unable to read from data source with URI '+self.src.getURI()) self.layer_count += 1 self.dst.src_feat_count = 0