Skip to content

Commit

Permalink
updatet networkproxy handling
Browse files Browse the repository at this point in the history
  • Loading branch information
warrieka committed Nov 24, 2015
1 parent 1e96006 commit 6f6b725
Show file tree
Hide file tree
Showing 18 changed files with 637 additions and 559 deletions.
8 changes: 5 additions & 3 deletions .gitignore
Expand Up @@ -206,7 +206,6 @@ $RECYCLE.BIN/
*.egg
*.egg-info
dist/
build/
eggs/
parts/
var/
Expand All @@ -224,8 +223,11 @@ pip-log.txt
#Translations
*.mo

#Mr Developer
.mr.developer.cfg

.idea/
doc/*.pdf
doc/*.docx
doc/*.xlsx



22 changes: 12 additions & 10 deletions Makefile
Expand Up @@ -23,7 +23,7 @@ PLUGIN_UPLOAD = $(CURDIR)/utils/plugin_upload.py
QGISDIR=.qgis2

# translation
SOURCES = geopunt4qgis.py \
SOURCES = geopunt4qgis.py \
geopunt4QgisPoidialog.py \
geopunt4QgisAdresdialog.py \
geopunt4QgisAbout.py \
Expand All @@ -32,34 +32,34 @@ SOURCES = geopunt4qgis.py \
geopunt4QgisGipod.py \
geopunt4QgisElevation.py \
geopunt4QgisDataCatalog.py \
geopunt4qgisParcel.py \
geopunt4QgisParcel.py \
versionChecker.py

FORMS = ui_geopunt4qgis.ui \
FORMS = ui_geopunt4qgis.ui \
ui_geopunt4QgisPoi.ui \
ui_geopunt4QgisAbout.ui \
ui_geopunt4QgisSettings.ui \
ui_geopunt4QgisBatchGeoCode.ui \
ui_geopunt4QgisGIPOD.ui \
ui_geopunt4QgisElevation.ui \
ui_geopunt4QgisDataCatalog.ui \
ui_geopunt4qgisParcel.ui
ui_geopunt4QgisParcel.ui

TRANSLATIONS = i18n/geopunt4qgis_en.ts i18n/geopunt4qgis_nl.ts

# plugin
PLUGINNAME = geopunt4Qgis

PY_FILES = __init__.py geometryhelper.py geopunt.py \
geopunt4qgis.py geopunt4QgisAbout.py geopunt4qgisAdresdialog.py \
geopunt4qgis.py geopunt4QgisAbout.py geopunt4QgisAdresdialog.py \
geopunt4QgisPoidialog.py geopunt4QgisSettingsdialog.py \
geopunt4QgisBatchGeoCode.py batchGeoHelper.py reverseAdresMapTool.py \
geopunt4QgisGipod.py gipodHelper.py geopunt4qgisParcel.py \
geopunt4QgisGipod.py gipodHelper.py geopunt4QgisParcel.py \
geopunt4QgisElevation.py elevationHelper.py elevationProfileMapTool.py \
metadata.py geopunt4QgisDataCatalog.py versionChecker.py poiHelper.py \
parcelHelper.py
metadataParser.py geopunt4QgisDataCatalog.py versionChecker.py poiHelper.py \
parcelHelper.py settings.py

EXTRAS = images metadata.txt i18n/about-en.html i18n/about-nl.html ext-libs
EXTRAS = images metadata.txt i18n/about-en.html i18n/about-nl.html ext-libs data

UI_FILES = ui_geopunt4qgis.py ui_geopunt4QgisPoi.py ui_geopunt4QgisAbout.py \
ui_geopunt4QgisSettings.py ui_geopunt4QgisBatchGeoCode.py ui_geopunt4QgisGIPOD.py \
Expand All @@ -76,6 +76,7 @@ compile: $(UI_FILES) $(RESOURCE_FILES)

%.py : %.ui
pyuic4 -o $@ $<
# python C:\OSGeo4W64\apps\Python27\lib\site-packages\PyQt4\uic\pyuic.py -o $@ $<

# [KW]: extra command with my own python script, that I can also use on windows
# workflow testPlugin.py: pack -> extract at QGISDIR -> start QGIS
Expand All @@ -85,7 +86,8 @@ runplugin: compile transup
# The deploy target only works on unix like operating system where
# the Python plugin directory is located at: $HOME/$(QGISDIR)/python/plugins
# [KW]: use "make runplugin" instead on windows
deploy: compile transup
deploy: compile
if [ -d "$(HOME)/$(QGISDIR)/python/plugins/$(PLUGINNAME)" ]; then rm -r $(HOME)/$(QGISDIR)/python/plugins/$(PLUGINNAME); fi
mkdir -p $(HOME)/$(QGISDIR)/python/plugins/$(PLUGINNAME)
cp -vf $(PY_FILES) $(HOME)/$(QGISDIR)/python/plugins/$(PLUGINNAME)
cp -vf $(UI_FILES) $(HOME)/$(QGISDIR)/python/plugins/$(PLUGINNAME)
Expand Down
63 changes: 25 additions & 38 deletions geopunt.py
Expand Up @@ -19,16 +19,15 @@
* *
***************************************************************************/
"""
import urllib2, urllib, json, sys, os.path, datetime
import urllib2, urllib, json, sys, datetime

class Adres:
def __init__(self, timeout=15, proxyUrl="", port="" ):
def __init__(self, timeout=15, proxyUrl=""):
self.timeout = timeout
self._locUrl = "http://loc.api.geopunt.be/geolocation/Location?"
self._sugUrl = "http://loc.api.geopunt.be/geolocation/Suggestion?"
if (isinstance( proxyUrl, unicode ) or isinstance( proxyUrl, str )) & proxyUrl.startswith("http://"):
netLoc = proxyUrl.strip() + ":" + port
proxy = urllib2.ProxyHandler({'http': netLoc })
if (isinstance(proxyUrl, unicode) or isinstance(proxyUrl, str)) and proxyUrl:
proxy = urllib2.ProxyHandler({'http': proxyUrl, 'https': proxyUrl })
self.opener = urllib2.build_opener(proxy)
else:
self.opener = None
Expand Down Expand Up @@ -78,19 +77,18 @@ def fetchSuggestion(self, q, c=5):
return suggestion["SuggestionResult"]

class Poi:
def __init__(self, timeout=15, proxyUrl="", port=""):
def __init__(self, timeout=15, proxyUrl=""):
self.timeout = timeout
self._poiUrl = "http://poi.api.geopunt.be/v1/core"
self.resultCount = 0

if (isinstance(proxyUrl, unicode) or isinstance(proxyUrl, str)) & proxyUrl.startswith("http://"):
netLoc = proxyUrl.strip() + ":" + port
proxy = urllib2.ProxyHandler({'http': netLoc })
self.opener = urllib2.build_opener(proxy)
if (isinstance(proxyUrl, unicode) or isinstance(proxyUrl, str)) and proxyUrl:
proxy = urllib2.ProxyHandler({'http': proxyUrl, 'https': proxyUrl })
self.opener = urllib2.build_opener(proxy)
else:
self.opener = None
self.opener = None

#TODO: What if no WGS coordinates as input???
#REMARK: WGS coordinates as input!
self.maxBounds = [1.17, 49.77, 7.29, 52.35]
self.resultBounds = [1.17, 49.77, 7.29, 52.35]
self.PoiResult = []
Expand Down Expand Up @@ -138,15 +136,11 @@ def listPoiCategories(self, themeid=""):
return categories

def listPoitypes(self, themeid="", categoriename=""):
"http://{base}/{path}/themes/{themeid}/categories/{categoriename}/POITypes"
if themeid and categoriename:
url = self._poiUrl + "/themes/" + themeid + "/categories/" + categoriename +"/poitypes"
#elif categoriename :
#url = self._poiUrl + "/categories/" + categoriename +"/poitypes"
else:
url = self._poiUrl + "/poitypes"

poitypes = None

try:
if self.opener: response = self.opener.open(url, timeout=self.timeout)
else: response = urllib2.urlopen(url, timeout=self.timeout)
Expand Down Expand Up @@ -196,10 +190,10 @@ def _createPoiUrl(self, q, c=30, srs=31370, maxModel=False, bbox=None, theme='',
result = poiUrl + "?" + values
return result

def fetchPoi(self, q, c=30, srs=31370, maxModel=True , updateResults=True, bbox=None, theme='', category='', POItype='', region='', clustering=True):
def fetchPoi(self, q, c=30, srs=31370, maxModel=True , updateResults=True,
bbox=None, theme='', category='', POItype='', region='', clustering=True):
url = self._createPoiUrl( q, c, srs, maxModel, bbox, theme, category, POItype, region, clustering)

poi = None
try:
if self.opener: response = self.opener.open(url, timeout=self.timeout)
else: response = urllib2.urlopen(url, timeout=self.timeout)
Expand Down Expand Up @@ -297,13 +291,12 @@ def _getBounds(self, poiResult ):
return [ minX, minY, maxX, maxY]

class gipod:
def __init__(self, timeout=15, proxyUrl="", port="" ):
def __init__(self, timeout=15, proxyUrl=""):
self.timeout = timeout
self.baseUri = 'http://gipod.api.agiv.be/ws/v1/'

if (isinstance(proxyUrl, unicode) or isinstance(proxyUrl, str)) & proxyUrl.startswith("http://"):
netLoc = proxyUrl.strip() + ":" + port
proxy = urllib2.ProxyHandler({'http': netLoc })
if (isinstance(proxyUrl, unicode) or isinstance(proxyUrl, str)) and proxyUrl:
proxy = urllib2.ProxyHandler({'http': proxyUrl, 'https': proxyUrl })
self.opener = urllib2.build_opener(proxy)
else:
self.opener = None
Expand Down Expand Up @@ -470,13 +463,12 @@ def allManifestations(self, owner="", eventtype="", startdate=None, enddate=None
return mAs

class elevation:
def __init__(self, timeout=15, proxyUrl="", port="" ):
def __init__(self, timeout=15, proxyUrl=""):
self.timeout = timeout
self.baseUri = 'http://dhm.agiv.be/api/elevation/v1/DHMVMIXED/request'

if (isinstance(proxyUrl, unicode) or isinstance(proxyUrl, str)) & proxyUrl.startswith("http://"):
netLoc = proxyUrl.strip() + ":" + port
proxy = urllib2.ProxyHandler({'http': netLoc })
if (isinstance(proxyUrl, unicode) or isinstance(proxyUrl, str)) and proxyUrl:
proxy = urllib2.ProxyHandler({'http': proxyUrl, 'https': proxyUrl })
self.opener = urllib2.build_opener(proxy)
else:
self.opener = None
Expand Down Expand Up @@ -506,12 +498,11 @@ def fetchElevaton(self, LineString, srs=31370, samples=50 ):
return elevationJson

class parcel:
def __init__(self, timeout=15, proxyUrl="", port="" ):
def __init__(self, timeout=15, proxyUrl=""):
self.timeout = timeout
self.baseUrl = "http://geo.agiv.be/capakey/api/v0"
if (isinstance( proxyUrl, unicode ) or isinstance( proxyUrl, str )) & proxyUrl.startswith("http://"):
netLoc = proxyUrl.strip() + ":" + port
proxy = urllib2.ProxyHandler({'http': netLoc })
if (isinstance( proxyUrl, unicode ) or isinstance( proxyUrl, str )):
proxy = urllib2.ProxyHandler({'http': proxyUrl, 'https': proxyUrl })
self.opener = urllib2.build_opener(proxy)
else:
self.opener = None
Expand All @@ -531,7 +522,6 @@ def getMunicipalities(self):
else : return []

def getMunicipalitieInfo(self, niscode, srs=31370, geometryType="no" ):

data = {}
if srs in [31370, 4326, 3857]: data["srs"] = srs
if geometryType in ["no", "full", "bbox"]: data["geometry"] = geometryType
Expand Down Expand Up @@ -566,7 +556,6 @@ def getDepartments(self, niscode):
else : return []

def getDepartmentInfo(self, niscode, departmentCode, srs=31370, geometryType="no" ):

data = {}
if srs in [31370, 4326, 3857]: data["srs"] = srs
if geometryType in ["no", "full", "bbox"]: data["geometry"] = geometryType
Expand Down Expand Up @@ -601,7 +590,6 @@ def getSections(self, niscode, departmentCode):
else : return []

def getSectionInfo(self, niscode, departmentCode, sectieCode, srs=31370, geometryType="no" ):

data = {}
if srs in [31370, 4326, 3857]: data["srs"] = srs
if geometryType in ["no", "full", "bbox"]: data["geometry"] = geometryType
Expand Down Expand Up @@ -661,10 +649,9 @@ def __init__(self, message):
def __str__(self):
return repr(self.message)

def internet_on(timeout=15, proxyUrl="", port="" ):
if (isinstance(proxyUrl, unicode) or isinstance(proxyUrl, str)) & proxyUrl.startswith("http://"):
netLoc = proxyUrl.strip() + ":" + port
proxy = urllib2.ProxyHandler({'http': netLoc })
def internet_on(timeout=15, proxyUrl="" ):
if (isinstance(proxyUrl, unicode) or isinstance(proxyUrl, str)) and proxyUrl:
proxy = urllib2.ProxyHandler({'http': proxyUrl, 'https': proxyUrl })
opener = urllib2.build_opener(proxy)
else:
opener = None
Expand Down
10 changes: 4 additions & 6 deletions geopunt4QgisAdresdialog.py
Expand Up @@ -25,12 +25,12 @@
from qgis.gui import QgsMessageBar, QgsVertexMarker
import geopunt, os, json, webbrowser
import geometryhelper as gh
from settings import settings

class geopunt4QgisAdresDialog(QtGui.QDialog):
def __init__(self, iface):
QtGui.QDialog.__init__(self, None)
self.setWindowFlags( self.windowFlags() & ~QtCore.Qt.WindowContextHelpButtonHint )
#self.setWindowFlags( self.windowFlags() | QtCore.Qt.WindowStaysOnTopHint)
self.iface = iface

# initialize locale
Expand Down Expand Up @@ -106,14 +106,12 @@ def loadSettings(self):
self.layerName= layerName
self.adresSearchOnEnter = int( self.s.value("geopunt4qgis/adresSearchOnEnter" , 0))
self.timeout = int( self.s.value("geopunt4qgis/timeout" ,15))
if int( self.s.value("geopunt4qgis/useProxy" , 0)):
self.proxy = self.s.value("geopunt4qgis/proxyHost" ,"")
self.port = self.s.value("geopunt4qgis/proxyPort" ,"")
if settings().proxyUrl:
self.proxy = settings().proxyUrl
else:
self.proxy = ""
self.port = ""
self.startDir = self.s.value("geopunt4qgis/startDir", os.path.dirname(__file__))
self.gp = geopunt.Adres(self.timeout, self.proxy, self.port)
self.gp = geopunt.Adres(self.timeout, self.proxy)

def openHelp(self):
webbrowser.open_new_tab("http://www.geopunt.be/voor-experts/geopunt-plug-ins/functionaliteiten/zoek-een-adres")
Expand Down
13 changes: 6 additions & 7 deletions geopunt4QgisBatchGeoCode.py
Expand Up @@ -19,12 +19,13 @@
* *
***************************************************************************/
"""
import os.path, sys
import os.path
from PyQt4 import QtCore, QtGui
from ui_geopunt4QgisBatchGeoCode import Ui_batchGeocodeDlg
import geopunt, geometryhelper, csv, unicodecsv, webbrowser
from batchGeoHelper import batcGeoHelper
from reverseAdresMapTool import reverseAdresMapTool
from settings import settings

class geopunt4QgisBatcGeoCodeDialog(QtGui.QDialog):
def __init__(self, iface):
Expand Down Expand Up @@ -100,15 +101,13 @@ def loadSettings(self):
if layerName :
self.layerName= layerName
self.timeout = int(self.s.value("geopunt4qgis/timeout" ,15))
if int( self.s.value("geopunt4qgis/useProxy" , 0)):
self.proxy = self.s.value("geopunt4qgis/proxyHost" ,"")
self.port = self.s.value("geopunt4qgis/proxyPort" ,"")
if settings().proxyUrl:
self.proxy = settings().proxyUrl
else:
self.proxy = ""
self.port = ""
self.retrys = 3
self.startDir = self.s.value("geopunt4qgis/startDir", os.path.dirname(__file__))
self.gp = geopunt.Adres(self.timeout, self.proxy, self.port)
self.gp = geopunt.Adres(self.timeout, self.proxy)

#eventHandlers
def openHelp(self):
Expand Down Expand Up @@ -460,7 +459,7 @@ def openInputCsv(self):
self.loadTable()

def internet_on(self):
inet_on = geopunt.internet_on( timeout= self.timeout , proxyUrl= self.proxy , port= self.port )
inet_on = geopunt.internet_on( timeout= self.timeout , proxyUrl= self.proxy )
if True != inet_on:
self.ui.statusMsg.setText(
QtCore.QCoreApplication.translate("batcGeoCodedialog",
Expand Down

0 comments on commit 6f6b725

Please sign in to comment.