Skip to content

Commit

Permalink
wx.metadata: update to Python 3 (#210)
Browse files Browse the repository at this point in the history
  • Loading branch information
neteler committed Jun 19, 2020
1 parent 96d39e0 commit 0f47f82
Show file tree
Hide file tree
Showing 17 changed files with 108 additions and 94 deletions.
13 changes: 13 additions & 0 deletions grass7/gui/wxpython/wx.metadata/README.md
@@ -0,0 +1,13 @@
## Dependencies

### Requirements:

https://grasswiki.osgeo.org/wiki/ISO/INSPIRE_Metadata_Support#Requirements_and_installation

### Test Dependencies

Test dependencies with

```
python3 dependency.py
```
4 changes: 2 additions & 2 deletions grass7/gui/wxpython/wx.metadata/config/init_md.txt
@@ -1,6 +1,6 @@
self.md.identification = mdutil.MD_DataIdentification_MOD()
self.md.identification = mdutil.MD_DataIdentification()
self.md.dataquality = DQ_DataQuality()
self.md.distribution = MD_Distribution()
self.md.identification.extent = EX_Extent()
self.md.identification.extent.boundingBox = EX_GeographicBoundingBox()
self.md.referencesystem=MD_ReferenceSystem(None)
self.md.referencesystem=MD_ReferenceSystem(None)
16 changes: 8 additions & 8 deletions grass7/gui/wxpython/wx.metadata/db.csw.admin/db.csw.admin.py
Expand Up @@ -116,7 +116,7 @@

import sys
import os
import ConfigParser
import configparser
import getopt

from grass.script import core as grass
Expand Down Expand Up @@ -241,7 +241,7 @@ def run(self, argv):
if len(argv) == 0:
grass.error('Nothing to do. Set args')
return
print argv
print(argv)
try:
OPTS, ARGS = getopt.getopt(argv, 'c:f:ho:p:ru:x:s:t:y')
except getopt.GetoptError as err:
Expand Down Expand Up @@ -269,10 +269,10 @@ def run(self, argv):
self.FORCE_CONFIRM = True

if self.CFG is None and self.COMMAND not in ['post_xml']:
print 'ERROR: -f <cfg> is a required argument'
print('ERROR: -f <cfg> is a required argument')

if self.COMMAND not in ['post_xml']:
SCP = ConfigParser.SafeConfigParser()
SCP = configparser.SafeConfigParser()
SCP.readfp(open(self.CFG))

self.DATABASE = SCP.get('repository', 'database')
Expand All @@ -281,16 +281,16 @@ def run(self, argv):
self.METADATA = dict(SCP.items('metadata:main'))
try:
self.TABLE = SCP.get('repository', 'table')
except ConfigParser.NoOptionError:
except configparser.NoOptionError:
self.TABLE = 'records'

if self.COMMAND == 'setup_db':
try:
admin.setup_db(self.DATABASE, self.TABLE, self.HOME)
except Exception as err:
print err
print 'ERROR: DB creation error. Database tables already exist'
print 'Delete tables or database to reinitialize'
print(err)
print('ERROR: DB creation error. Database tables already exist')
print('Delete tables or database to reinitialize')

elif self.COMMAND == 'load_records':
admin.load_records(self.CONTEXT, self.DATABASE, self.TABLE, self.XML_DIRPATH, self.RECURSIVE,
Expand Down
Expand Up @@ -106,11 +106,11 @@ def _get_csw(catalog_url, timeout=10):
try:
catalog = CatalogueServiceWeb(catalog_url, timeout=timeout)
return catalog
except ExceptionReport, err:
except ExceptionReport as err:
msg = 'Error connecting to service: %s' % err
except ValueError, err:
except ValueError as err:
msg = 'Value Error: %s' % err
except Exception, err:
except Exception as err:
msg = 'Unknown Error: %s' % err
grass.error('CSW Connection error: %s' % msg)

Expand Down
6 changes: 3 additions & 3 deletions grass7/gui/wxpython/wx.metadata/db.csw.run/db.csw.run.py
Expand Up @@ -75,7 +75,7 @@
#% answer: 8000
#%end

from StringIO import StringIO
from io import StringIO
import os
import sys
import contextlib
Expand Down Expand Up @@ -147,7 +147,7 @@ def application(env, start_response):
headers['Content-Length'] = str(len(contents))
headers['Content-Type'] = csw.contenttype

start_response(status, headers.items())
start_response(status, list(headers.items()))

return [contents]

Expand All @@ -165,7 +165,7 @@ def main():
try:
httpd = make_server('', port, application)
grass.message("Serving on port %d..." % port)
except Exception, e:
except Exception as e:
grass.error(str(e))
sys.stdout.flush()
sys.exit()
Expand Down
8 changes: 4 additions & 4 deletions grass7/gui/wxpython/wx.metadata/dependency.py
Expand Up @@ -3,7 +3,7 @@
import owslib
owslib=True
except:
print'owslib library is missing. Check requirements on the manual page < https://grasswiki.osgeo.org/wiki/ISO/INSPIRE_Metadata_Support >'
print('owslib library is missing. Check requirements on the manual page < https://grasswiki.osgeo.org/wiki/ISO/INSPIRE_Metadata_Support >')

if owslib:
import owslib
Expand All @@ -13,14 +13,14 @@

MD_Metadata()
except:
print ('Installed version of owslib library is < %s >.'%owsvs)
print('Installed version of owslib library is < %s >.'%owsvs)
print('owslib >=0.9 is required. Check requirements on the manual page < https://grasswiki.osgeo.org/wiki/ISO/INSPIRE_Metadata_Support >')


try:
import jinja2
except:
print'jinja2 library is missing. Check requirements on the manual page < https://grasswiki.osgeo.org/wiki/ISO/INSPIRE_Metadata_Support >'
print('jinja2 library is missing. Check requirements on the manual page < https://grasswiki.osgeo.org/wiki/ISO/INSPIRE_Metadata_Support >')
pycsw=False

try:
Expand All @@ -40,7 +40,7 @@
try:
from pycsw.core import admin
except:
print ('Installed version of pycsw library is < %s >.'%cswvs)
print('Installed version of pycsw library is < %s >.'%cswvs)
print('pycsw >=2.0 is required. Check requirements on the manual page < https://grasswiki.osgeo.org/wiki/ISO/INSPIRE_Metadata_Support >')


Expand Down
27 changes: 14 additions & 13 deletions grass7/gui/wxpython/wx.metadata/g.gui.metadata/g.gui.metadata.py
Expand Up @@ -31,6 +31,7 @@
import grass.temporal as tgis

from grass.script.setup import set_gui_path
from functools import reduce
set_gui_path()

from core.gcmd import RunCommand, GError, GMessage
Expand Down Expand Up @@ -820,8 +821,8 @@ def editMapMetadata(self, multipleEditing=False):
if self.numOfMap == 1 and multipleEditing is False and self.profileChoice != 'Load custom':
if self.profileChoice == 'INSPIRE':
if self.chckProfileSelection('spatial'):
self.mdCreator = mdgrass.GrassMD(self.ListOfMapTypeDict[-1][self.ListOfMapTypeDict[-1].keys()[0]],
self.ListOfMapTypeDict[-1].keys()[0])
self.mdCreator = mdgrass.GrassMD(self.ListOfMapTypeDict[-1][list(self.ListOfMapTypeDict[-1].keys())[0]],
list(self.ListOfMapTypeDict[-1].keys())[0])
self.mdCreator.createGrassInspireISO()
self.jinjaPath = self.mdCreator.profilePathAbs
else:
Expand All @@ -830,8 +831,8 @@ def editMapMetadata(self, multipleEditing=False):

elif self.profileChoice == 'GRASS BASIC':
if self.chckProfileSelection('spatial'):
self.mdCreator = mdgrass.GrassMD(self.ListOfMapTypeDict[-1][self.ListOfMapTypeDict[-1].keys()[0]],
self.ListOfMapTypeDict[-1].keys()[0])
self.mdCreator = mdgrass.GrassMD(self.ListOfMapTypeDict[-1][list(self.ListOfMapTypeDict[-1].keys())[0]],
list(self.ListOfMapTypeDict[-1].keys())[0])
self.mdCreator.createGrassBasicISO()
self.jinjaPath = self.mdCreator.profilePathAbs
else:
Expand All @@ -840,8 +841,8 @@ def editMapMetadata(self, multipleEditing=False):

elif self.profileChoice == 'TEMPORAL':
if self.chckProfileSelection('temporal'):
self.mdCreator = mdgrass.GrassMD(self.ListOfMapTypeDict[-1][self.ListOfMapTypeDict[-1].keys()[0]],
self.ListOfMapTypeDict[-1].keys()[0])
self.mdCreator = mdgrass.GrassMD(self.ListOfMapTypeDict[-1][list(self.ListOfMapTypeDict[-1].keys())[0]],
list(self.ListOfMapTypeDict[-1].keys())[0])
self.mdCreator.createTemporalISO()
self.jinjaPath = self.mdCreator.profilePathAbs
else:
Expand All @@ -856,8 +857,8 @@ def editMapMetadata(self, multipleEditing=False):
if multipleEditing is False:
dlg = wx.FileDialog(self, "Select profile", os.getcwd(), "", "*.xml", wx.OPEN)
if dlg.ShowModal() == wx.ID_OK:
self.mdCreator = mdgrass.GrassMD(self.ListOfMapTypeDict[-1][self.ListOfMapTypeDict[-1].keys()[0]],
self.ListOfMapTypeDict[-1].keys()[0])
self.mdCreator = mdgrass.GrassMD(self.ListOfMapTypeDict[-1][list(self.ListOfMapTypeDict[-1].keys())[0]],
list(self.ListOfMapTypeDict[-1].keys())[0])

if self.chckProfileSelection('temporal'): #if map is temporal, use temporal md pareser
self.mdCreator.createTemporalISO()
Expand All @@ -880,8 +881,8 @@ def editMapMetadata(self, multipleEditing=False):
else: # do nothing
return False
else:
self.mdCreator = mdgrass.GrassMD(self.ListOfMapTypeDict[-1][self.ListOfMapTypeDict[-1].keys()[0]],
self.ListOfMapTypeDict[-1].keys()[0])
self.mdCreator = mdgrass.GrassMD(self.ListOfMapTypeDict[-1][list(self.ListOfMapTypeDict[-1].keys())[0]],
list(self.ListOfMapTypeDict[-1].keys())[0])
self.mdCreator.createGrassInspireISO()
self.xmlPath = self.mdCreator.saveXML(self.mdDestination, self.nameTMPteplate, self)
self.initMultipleEditor()
Expand Down Expand Up @@ -1130,8 +1131,8 @@ def initTemporalTree(self, location, mapset):
tDict = tgis.tlist_grouped('stds', group_type=True, dbif=self.dbif)
# nested list with '(map, mapset, etype)' items
allDatasets = [[[(map, mapset, etype) for map in maps]
for etype, maps in etypesDict.iteritems()]
for mapset, etypesDict in tDict.iteritems()]
for etype, maps in list(etypesDict.items())]
for mapset, etypesDict in list(tDict.items())]
if allDatasets:
allDatasets = reduce(lambda x, y: x + y, reduce(lambda x, y: x + y,
allDatasets))
Expand Down Expand Up @@ -1164,7 +1165,7 @@ def initTemporalTree(self, location, mapset):
if vartype is not None:
self.AppendItem(vartype, ml[0])

except Exception, e:
except Exception as e:
GError('Initialize of temporal tree catalogue error: < %s >'%e)

self.Bind(wx.EVT_TREE_SEL_CHANGED, self.onChanged)
Expand Down
48 changes: 24 additions & 24 deletions grass7/gui/wxpython/wx.metadata/mdlib/cswlib.py
Expand Up @@ -18,8 +18,8 @@
sys.exit(
'owslib python library is missing. Check requirements on the manual page < https://grasswiki.osgeo.org/wiki/ISO/INSPIRE_Metadata_Support >')
import tempfile
from cswutil import *
from mdutil import yesNo, StaticContext
from .cswutil import *
from .mdutil import yesNo, StaticContext
import json
import wx
from wx import SplitterWindow
Expand Down Expand Up @@ -300,15 +300,15 @@ def OnRecord(self, evt):
maxrecords=1,
startposition=startfr,
outputschema='http://www.isotc211.org/2005/gmd')
except ExceptionReport, err:
except ExceptionReport as err:
GWarning('Error getting response: %s' % err)
return
except KeyError, err:
except KeyError as err:
GWarning('Record parsing error, unable to locate record identifier')
return

if self.catalog:
md = cat.records.values()[0]
md = list(cat.records.values())[0]
path = 'record_metadata_gmd.html'
metadata = render_template('en', self.context, md, path)

Expand All @@ -319,10 +319,10 @@ def OnRecord(self, evt):
cat = CatalogueServiceWeb(self.catalog_url, timeout=self.timeout)
try:
cat.getrecordbyid([self.catalog.records[identifier].identifier])
except ExceptionReport, err:
except ExceptionReport as err:
GWarning('Error getting response: %s' % err)
return
except KeyError, err:
except KeyError as err:
GWarning('Record parsing error, unable to locate record identifier')
return

Expand All @@ -337,7 +337,7 @@ def OnRecord(self, evt):

try:
record = self.catalog.records[identifier]
except KeyError, err:
except KeyError as err:
GWarning('@!Record parsing error, unable to locate record identifier')
return

Expand Down Expand Up @@ -385,9 +385,9 @@ def findServices(self, record, item):
if link_type is not None:
link_type = link_type.upper()

wmswmst_link_types = map(str.upper, WMSWMST_LINK_TYPES)
wfs_link_types = map(str.upper, WFS_LINK_TYPES)
wcs_link_types = map(str.upper, WCS_LINK_TYPES)
wmswmst_link_types = list(map(str.upper, WMSWMST_LINK_TYPES))
wfs_link_types = list(map(str.upper, WFS_LINK_TYPES))
wcs_link_types = list(map(str.upper, WCS_LINK_TYPES))

# if the link type exists, and it is one of the acceptable
# interactive link types, then set
Expand Down Expand Up @@ -470,10 +470,10 @@ def OnNavigate(self, evt):
self.catalog.getrecords2(constraints=self.constraints,
maxrecords=self.maxrecords,
startposition=self.startfrom, esn='full')
except ExceptionReport, err:
except ExceptionReport as err:
GWarning('Search error: %s' % err)
return
except Exception, err:
except Exception as err:
GWarning('Connection error: %s' % err)
return

Expand Down Expand Up @@ -519,11 +519,11 @@ def _get_csw(self):
self.catalog = CatalogueServiceWeb(self.catalog_url,
timeout=self.timeout)
return True
except ExceptionReport, err:
except ExceptionReport as err:
msg = 'Error connecting to service: %s' % err
except ValueError, err:
except ValueError as err:
msg = 'Value Error: %s' % err
except Exception, err:
except Exception as err:
msg = 'Unknown Error: %s' % err
GMessage('CSW Connection error: %s' % msg)
return False
Expand Down Expand Up @@ -664,10 +664,10 @@ def OnSearch(self, evt):
self.catalog.getrecords2(constraints=self.constraints,
maxrecords=self.maxrecords, esn='full')
self.outpoutschema = 'dc'
except ExceptionReport, err:
except ExceptionReport as err:
GError('Search error: %s' % err)
return
except Exception, err:
except Exception as err:
GError('Connection error: %s' % err)
return

Expand All @@ -683,10 +683,10 @@ def OnSearch(self, evt):
"Endopoint of service is not setup properly. Server returns ISO metadata(http://www.isotc211.org/2005/gmd) instead of CSW records(http://schemas.opengis.net/csw/2.0.2/record.xsd). CSW browser may work incorrectly.")
self.warns = False

except ExceptionReport, err:
except ExceptionReport as err:
GError('Search error: %s' % err)
return
except Exception, err:
except Exception as err:
GError('Connection error: %s' % err)
return
###work around for GMD records- END
Expand Down Expand Up @@ -1070,7 +1070,7 @@ def publishCSW(self, path):

try:
self.catalog.transaction(ttype='insert', typename='gmd:MD_Metadata', record=open(path).read())
except Exception, e:
except Exception as e:
GWarning('Transaction error: <%s>' % e)

def onHtmlLinkClicked(self, event):
Expand Down Expand Up @@ -1119,11 +1119,11 @@ def _get_csw(self):
self.catalog = CatalogueServiceWeb(self.catalog_url,
timeout=self.timeoutSpin.GetValue())
return True
except ExceptionReport, err:
except ExceptionReport as err:
msg = 'Error connecting to service: %s' % err
except ValueError, err:
except ValueError as err:
msg = 'Value Error: %s' % err
except Exception, err:
except Exception as err:
msg = 'Unknown Error: %s' % err

GMessage('CSW Connection error: %s' % msg)
Expand Down
4 changes: 2 additions & 2 deletions grass7/gui/wxpython/wx.metadata/mdlib/cswutil.py
Expand Up @@ -30,10 +30,10 @@ def get_connections_from_file( filename):
if doc.tag != 'qgsCSWConnections':
error = 1
msg = 'Invalid CSW connections XML.'
except etree.ParseError, err:
except etree.ParseError as err:
error = 1
msg = ('Cannot parse XML file: %s' % err)
except IOError, err:
except IOError as err:
error = 1
msg = ('Cannot open file: %s' % err)

Expand Down

0 comments on commit 0f47f82

Please sign in to comment.