Skip to content

Commit

Permalink
Solved many flake8 issues in BAG-extract
Browse files Browse the repository at this point in the history
  • Loading branch information
fsteggink committed Mar 8, 2018
1 parent 46ea163 commit 6e505f3
Show file tree
Hide file tree
Showing 17 changed files with 583 additions and 557 deletions.
98 changes: 49 additions & 49 deletions bag/src/bagattribuut.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
OpenGeoGroep.nl
"""
from log import Log
from etree import etree, tagVolledigeNS, stripschema
from etree import etree, tagVolledigeNS

import sys

Expand All @@ -22,7 +22,6 @@
print("FATAAL: GDAL Python bindings zijn niet beschikbaar, installeer bijv met 'apt-get install python-gdal'")
sys.exit(-1)

from string import maketrans # Required to call maketrans function.

# Geef de waarde van een textnode in XML
def getText(nodelist):
Expand All @@ -31,9 +30,9 @@ def getText(nodelist):
rc = rc + node.text
return rc


# TODO: werking van deze functie controleren en vergelijken met origineel


# Geef de waardes van alle elementen met de gegeven tag binnen de XML (parent).
def getValues(parent, tag):
return [node.text for node in parent.iterfind('./' + tagVolledigeNS(tag, parent.nsmap))]
Expand All @@ -57,7 +56,7 @@ def getValue(parent, tag):
# Bevat - tag
# - naam
# - waarde
#--------------------------------------------------------------------------------------------------------
# --------------------------------------------------------------------------------------------------------
class BAGattribuut:
# Constructor
def __init__(self, lengte, naam, tag):
Expand Down Expand Up @@ -138,16 +137,17 @@ def schrijf(self):
print "- %-27s: %s" % (self._naam, self._waarde)


#--------------------------------------------------------------------------------------------------------
# --------------------------------------------------------------------------------------------------------
# Class BAGstringAttribuut
# Afgeleid van BAGattribuut
# Omschrijving Bevat een string waarde
#--------------------------------------------------------------------------------------------------------
# --------------------------------------------------------------------------------------------------------
class BAGstringAttribuut(BAGattribuut):
# Nodig om allerlei nare characters te verwijderen die bijv COPY
# kunnen beinvloeden
# inputChars = "\\\n~"
# outputChars = "/ ."
# from string import maketrans # Required to call maketrans function.
# translatieTabel = maketrans(inputChars, outputChars)
# Geeft problemen met niet-ASCII range unicode chars!!
# dus voorlopig even handmatig
Expand Down Expand Up @@ -186,13 +186,14 @@ def leesUitXML(self, xml):

#
# except:
# Log.log.warn("Fout in translate: waarde=%s tag=%s id=%s type=%s" % (self._waarde, self._naam, self._parentObj.objectType(), self._parentObj.identificatie()) )
# Log.log.warn("Fout in translate: waarde=%s tag=%s id=%s type=%s" %
# (self._waarde, self._naam, self._parentObj.objectType(), self._parentObj.identificatie()) )

#--------------------------------------------------------------------------------------------------------
# --------------------------------------------------------------------------------------------------------
# Class BAGenumAttribuut
# Afgeleid van BAGattribuut
# Omschrijving Bevat een of meerdere waarden binnen een restrictie
#--------------------------------------------------------------------------------------------------------
# --------------------------------------------------------------------------------------------------------
class BAGenumAttribuut(BAGattribuut):
# Constructor
def __init__(self, lijst, naam, tag):
Expand Down Expand Up @@ -234,11 +235,11 @@ def sqltype(self):
return "NUMERIC(%d)" % (self._lengte)


#--------------------------------------------------------------------------------------------------------
# --------------------------------------------------------------------------------------------------------
# Class BAGintegerAttribuut
# Afgeleid van BAGattribuut
# Omschrijving Bevat een numerieke waarde
#--------------------------------------------------------------------------------------------------------
# --------------------------------------------------------------------------------------------------------
class BAGintegerAttribuut(BAGattribuut):
# Constructor
def __init__(self, naam, tag):
Expand All @@ -257,11 +258,11 @@ def sqltype(self):
return "INTEGER"


#--------------------------------------------------------------------------------------------------------
# --------------------------------------------------------------------------------------------------------
# Class BAGdatumAttribuut
# Afgeleid van BAGattribuut
# Omschrijving Bevat een waarheid attribuut
#--------------------------------------------------------------------------------------------------------
# --------------------------------------------------------------------------------------------------------
class BAGbooleanAttribuut(BAGattribuut):
# Constructor
def __init__(self, naam, tag):
Expand All @@ -286,22 +287,22 @@ def leesUitXML(self, xml):
Log.log.error("Onverwachte boolean waarde: '%s'" % (self._waarde))


#--------------------------------------------------------------------------------------------------------
# --------------------------------------------------------------------------------------------------------
# Class BAGdatetimeAttribuut
# Afgeleid van BAGattribuut
# Omschrijving Bevat een DatumTijd attribuut
# <xs:simpleType name="DatumTijd">
# <xs:annotation>
# <xs:documentation>formaat JJJJMMDDUUMMSSmm</xs:documentation>
# </xs:annotation>
# <xs:restriction base="xs:token">
# <xs:minLength value="8"/>
# <xs:maxLength value="16"/>
# <xs:pattern value="[0-2][0-9][0-9][0-9][0-1][0-9][0-3][0-9][0-2][0-9][0-5][0-9][0-5][0-9][0-9][0-9]"/>
# </xs:restriction>
# </xs:simpleType>
# <xs:annotation>
# <xs:documentation>formaat JJJJMMDDUUMMSSmm</xs:documentation>
# </xs:annotation>
# <xs:restriction base="xs:token">
# <xs:minLength value="8"/>
# <xs:maxLength value="16"/>
# <xs:pattern value="[0-2][0-9][0-9][0-9][0-1][0-9][0-3][0-9][0-2][0-9][0-5][0-9][0-5][0-9][0-9][0-9]"/>
# </xs:restriction>
# </xs:simpleType>
#
#--------------------------------------------------------------------------------------------------------
# --------------------------------------------------------------------------------------------------------
class BAGdatetimeAttribuut(BAGattribuut):
# Constructor
def __init__(self, naam, tag):
Expand Down Expand Up @@ -344,11 +345,11 @@ def leesUitXML(self, xml):
self._waarde = None


#--------------------------------------------------------------------------------------------------------
# --------------------------------------------------------------------------------------------------------
# Class BAGdateAttribuut
# Afgeleid van BAGattribuut
# Omschrijving Bevat een datum (jaar) attribuut
#--------------------------------------------------------------------------------------------------------
# --------------------------------------------------------------------------------------------------------
class BAGdateAttribuut(BAGattribuut):
# Constructor
def __init__(self, naam, tag):
Expand All @@ -372,11 +373,11 @@ def leesUitXML(self, xml):
self._waarde = None


#--------------------------------------------------------------------------------------------------------
# --------------------------------------------------------------------------------------------------------
# Class BAGgeoAttribuut
# Afgeleid van BAGattribuut
# Omschrijving Bevat een geometrie attribuut
#--------------------------------------------------------------------------------------------------------
# --------------------------------------------------------------------------------------------------------
class BAGgeoAttribuut(BAGattribuut):
def __init__(self, dimensie, naam, tag):
self._dimensie = dimensie
Expand Down Expand Up @@ -429,11 +430,11 @@ def soort(self):
return ""


#--------------------------------------------------------------------------------------------------------
# --------------------------------------------------------------------------------------------------------
# Class BAGpoint
# Afgeleid van BAGgeoAttribuut
# Omschrijving Bevat een Puntgeometrie attribuut (geometrie van een verblijfsobject)
#--------------------------------------------------------------------------------------------------------
# --------------------------------------------------------------------------------------------------------
class BAGpoint(BAGgeoAttribuut):
# Attribuut soort
def soort(self):
Expand Down Expand Up @@ -461,17 +462,17 @@ def leesUitXML(self, xml):
gmlStr = etree.tostring(gmlNode)
self._geometrie = ogr.CreateGeometryFromGML(str(gmlStr))
self._geometrie = self._geometrie.Centroid()
except:
except Exception:
Log.log.error("ik kan hier echt geen POINT van maken: %s (en zet dit op 0,0,0)" % str(point.text))
# self._waarde = "POINT(0 0 0)"


#--------------------------------------------------------------------------------------------------------
# --------------------------------------------------------------------------------------------------------
# Class BAGpolygoon
# Afgeleid van BAGgeoAttribuut
# Omschrijving Bevat een Polygoongeometrie attribuut (pand, ligplaats, standplaats of woonplaats)
# De dimensie (2D of 3D) is variabel.
#--------------------------------------------------------------------------------------------------------
# --------------------------------------------------------------------------------------------------------
class BAGpolygoon(BAGgeoAttribuut):
# Attribuut soort
def soort(self):
Expand All @@ -487,11 +488,11 @@ def leesUitXML(self, xml):
self._geometrie = ogr.CreateGeometryFromGML(str(gmlStr))


#--------------------------------------------------------------------------------------------------------
# --------------------------------------------------------------------------------------------------------
# Class BAGmultiPolygoon
# Afgeleid van BAGpolygoon
# Omschrijving Bevat een MultiPolygoongeometrie attribuut (woonplaats)
#--------------------------------------------------------------------------------------------------------
# --------------------------------------------------------------------------------------------------------
class BAGmultiPolygoon(BAGpolygoon):
# Attribuut soort
def soort(self):
Expand Down Expand Up @@ -520,18 +521,18 @@ def leesUitXML(self, xml):
self._geometrie = ogr.CreateGeometryFromGML(str(gmlStr))
if self._geometrie is None:
Log.log.warn("Null MultiSurface in BAGmultiPolygoon: tag=%s parent=%s" % (
self._tag, self._parentObj.identificatie()))
self._tag, self._parentObj.identificatie()))

if self._geometrie is None:
Log.log.warn("Null geometrie in BAGmultiPolygoon: tag=%s identificatie=%s" % (
self._tag, self._parentObj.identificatie()))
self._tag, self._parentObj.identificatie()))


#--------------------------------------------------------------------------------------------------------
# --------------------------------------------------------------------------------------------------------
# Class BAGgeometrieValidatie
# Afgeleid van BAGattribuut
# Omschrijving Bevat de validatie waarde (true,false) van een geometrie attribuut
#--------------------------------------------------------------------------------------------------------
# --------------------------------------------------------------------------------------------------------
class BAGgeometrieValidatie(BAGattribuut):
def __init__(self, naam, naam_geo_attr):
BAGattribuut.__init__(self, -1, naam, None)
Expand Down Expand Up @@ -559,11 +560,11 @@ def soort(self):
return ""


#--------------------------------------------------------------------------------------------------------
# --------------------------------------------------------------------------------------------------------
# Class BAGrelatieAttribuut
# Afgeleid van BAGattribuut
# Omschrijving Bevat een attribuut dat meer dan 1 waarde kan hebben.
#--------------------------------------------------------------------------------------------------------
# --------------------------------------------------------------------------------------------------------
class BAGrelatieAttribuut(BAGattribuut):
# Constructor
def __init__(self, parent, relatieNaam, lengte, naam, tag, extraAttributes):
Expand Down Expand Up @@ -611,7 +612,7 @@ def maakInsertSQL(self, append=None):
# waarden in self._extraAttributes.
sql += self.naam() + ") VALUES (%s, %s, %s, %s, %s"
sql += ", %s" * len(self._extraAttributes) + ", %s)"

inhoud = [self._parent.attribuut('identificatie').waardeSQL(),
self._parent.attribuut('aanduidingRecordInactief').waardeSQL(),
self._parent.attribuut('aanduidingRecordCorrectie').waardeSQL(),
Expand All @@ -630,11 +631,11 @@ def maakInsertSQL(self, append=None):
# Maak insert SQL voor deze relatie
def maakCopySQL(self):
velden = ["identificatie", "aanduidingrecordinactief", "aanduidingrecordcorrectie", "begindatumtijdvakgeldigheid",
"einddatumtijdvakgeldigheid"]
"einddatumtijdvakgeldigheid"]
velden += self._extraAttributes
velden.append(self.naam())
self.velden = tuple(velden)

self.sql = ""
for waarde in self._waarde:
self.sql += self._parent.attribuut('identificatie').waardeSQL() + "~"
Expand All @@ -647,14 +648,14 @@ def maakCopySQL(self):
if not einddatumWaardeSQL or einddatumWaardeSQL is '':
einddatumWaardeSQL = '\\\N'
self.sql += einddatumWaardeSQL + "~"

for attr in self._extraAttributes:
# Ook de extra attributen kunnen leeg zijn
if self._parent.heeftAttribuut(attr):
attrWaarde = self._parent.attribuut(attr).waardeSQL()
else:
attrWaarde = ''

if not attrWaarde or attrWaarde is '':
attrWaarde = '\\\N'
self.sql += attrWaarde + "~"
Expand Down Expand Up @@ -703,11 +704,11 @@ def schrijf(self):
print "- %-27s %s" % ("", waarde)


#--------------------------------------------------------------------------------------------------------
# --------------------------------------------------------------------------------------------------------
# Class BAGenumRelatieAttribuut
# Afgeleid van BAGrelatieAttribuut
# Omschrijving Bevat een relatie attribuut van type enum.
#--------------------------------------------------------------------------------------------------------
# --------------------------------------------------------------------------------------------------------
class BAGenumRelatieAttribuut(BAGrelatieAttribuut):
# Constructor
def __init__(self, parent, relatieNaam, naam, tag, extraAttributes, lijst):
Expand All @@ -724,4 +725,3 @@ def sqltype(self):
def sqlinit(self):
return "DROP TYPE IF EXISTS %s;\nCREATE TYPE %s AS ENUM ('%s');\n" % (
self._naam, self._naam, "', '".join(self._lijst))

11 changes: 5 additions & 6 deletions bag/src/bagconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# Datum: 24 november 2009
#
# Ministerie van Volkshuisvesting, Ruimtelijke Ordening en Milieubeheer
#------------------------------------------------------------------------------
# ------------------------------------------------------------------------------
import sys
import os

Expand Down Expand Up @@ -42,7 +42,7 @@ def __init__(self, args, home_path=None):
self.configdict = ConfigParser()
try:
self.configdict.read(self.config_file)
except:
except Exception:
Log.log.fatal("" + str(self.config_file) + " kan niet worden ingelezen")

try:
Expand All @@ -57,7 +57,7 @@ def __init__(self, args, home_path=None):
if self.configdict.has_option(None, 'port'):
self.port = self.configdict.defaults()['port']

except:
except Exception:
Log.log.fatal("Configuratiebestand " + str(self.config_file) + " is niet volledig")

# Assign Singleton (of heeft Python daar namespaces voor?) (Java achtergrond)
Expand Down Expand Up @@ -88,10 +88,9 @@ def __init__(self, args, home_path=None):
if args.password:
self.password = args.password

except:
except Exception:
Log.log.fatal(" het overrulen van configuratiebestand " + str(self.config_file) + " via commandline loopt spaak")


def save(self):
section = self.configdict.defaults()
section['database'] = self.database
Expand All @@ -102,4 +101,4 @@ def save(self):
section['port'] = self.port

with open(self.config_file, 'w') as configfile: # save
self.configdict.write(configfile)
self.configdict.write(configfile)

0 comments on commit 6e505f3

Please sign in to comment.