From 0f47f82f2d32b868bfcf29961c7adc73dd99c877 Mon Sep 17 00:00:00 2001 From: Markus Neteler Date: Fri, 19 Jun 2020 10:11:43 +0200 Subject: [PATCH] wx.metadata: update to Python 3 (#210) --- grass7/gui/wxpython/wx.metadata/README.md | 13 +++++ .../wxpython/wx.metadata/config/init_md.txt | 4 +- .../wx.metadata/db.csw.admin/db.csw.admin.py | 16 +++---- .../db.csw.harvest/db.csw.harvest.py | 6 +-- .../wx.metadata/db.csw.run/db.csw.run.py | 6 +-- grass7/gui/wxpython/wx.metadata/dependency.py | 8 ++-- .../g.gui.metadata/g.gui.metadata.py | 27 ++++++----- .../gui/wxpython/wx.metadata/mdlib/cswlib.py | 48 +++++++++---------- .../gui/wxpython/wx.metadata/mdlib/cswutil.py | 4 +- .../wx.metadata/mdlib/mdeditorfactory.py | 20 ++++---- .../gui/wxpython/wx.metadata/mdlib/mdgrass.py | 20 ++++---- .../wx.metadata/mdlib/mdjinjaparser.py | 2 +- .../wx.metadata/mdlib/mdpdffactory.py | 10 ++-- .../wxpython/wx.metadata/mdlib/mdpdftheme.py | 8 ++-- .../gui/wxpython/wx.metadata/mdlib/mdutil.py | 2 +- .../wx.metadata/r.info.iso/r.info.iso.py | 4 +- .../wx.metadata/v.info.iso/v.info.iso.py | 4 +- 17 files changed, 108 insertions(+), 94 deletions(-) create mode 100644 grass7/gui/wxpython/wx.metadata/README.md diff --git a/grass7/gui/wxpython/wx.metadata/README.md b/grass7/gui/wxpython/wx.metadata/README.md new file mode 100644 index 0000000000..f1cf76b695 --- /dev/null +++ b/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 +``` diff --git a/grass7/gui/wxpython/wx.metadata/config/init_md.txt b/grass7/gui/wxpython/wx.metadata/config/init_md.txt index f16e6b674b..34f1149647 100644 --- a/grass7/gui/wxpython/wx.metadata/config/init_md.txt +++ b/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) \ No newline at end of file +self.md.referencesystem=MD_ReferenceSystem(None) diff --git a/grass7/gui/wxpython/wx.metadata/db.csw.admin/db.csw.admin.py b/grass7/gui/wxpython/wx.metadata/db.csw.admin/db.csw.admin.py index c06d123997..ce982e530a 100755 --- a/grass7/gui/wxpython/wx.metadata/db.csw.admin/db.csw.admin.py +++ b/grass7/gui/wxpython/wx.metadata/db.csw.admin/db.csw.admin.py @@ -116,7 +116,7 @@ import sys import os -import ConfigParser +import configparser import getopt from grass.script import core as grass @@ -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: @@ -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 is a required argument' + print('ERROR: -f 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') @@ -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, diff --git a/grass7/gui/wxpython/wx.metadata/db.csw.harvest/db.csw.harvest.py b/grass7/gui/wxpython/wx.metadata/db.csw.harvest/db.csw.harvest.py index 1d047a6f53..e1a9bee931 100755 --- a/grass7/gui/wxpython/wx.metadata/db.csw.harvest/db.csw.harvest.py +++ b/grass7/gui/wxpython/wx.metadata/db.csw.harvest/db.csw.harvest.py @@ -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) diff --git a/grass7/gui/wxpython/wx.metadata/db.csw.run/db.csw.run.py b/grass7/gui/wxpython/wx.metadata/db.csw.run/db.csw.run.py index b2cbd46962..5a04ae1ab2 100755 --- a/grass7/gui/wxpython/wx.metadata/db.csw.run/db.csw.run.py +++ b/grass7/gui/wxpython/wx.metadata/db.csw.run/db.csw.run.py @@ -75,7 +75,7 @@ #% answer: 8000 #%end -from StringIO import StringIO +from io import StringIO import os import sys import contextlib @@ -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] @@ -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() diff --git a/grass7/gui/wxpython/wx.metadata/dependency.py b/grass7/gui/wxpython/wx.metadata/dependency.py index a850ea9fb4..512f0f3068 100644 --- a/grass7/gui/wxpython/wx.metadata/dependency.py +++ b/grass7/gui/wxpython/wx.metadata/dependency.py @@ -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 @@ -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: @@ -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 >') diff --git a/grass7/gui/wxpython/wx.metadata/g.gui.metadata/g.gui.metadata.py b/grass7/gui/wxpython/wx.metadata/g.gui.metadata/g.gui.metadata.py index ef5381d8f4..268a3f2f97 100755 --- a/grass7/gui/wxpython/wx.metadata/g.gui.metadata/g.gui.metadata.py +++ b/grass7/gui/wxpython/wx.metadata/g.gui.metadata/g.gui.metadata.py @@ -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 @@ -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: @@ -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: @@ -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: @@ -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() @@ -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() @@ -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)) @@ -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) diff --git a/grass7/gui/wxpython/wx.metadata/mdlib/cswlib.py b/grass7/gui/wxpython/wx.metadata/mdlib/cswlib.py index 36f532e1d5..f434f5ce18 100644 --- a/grass7/gui/wxpython/wx.metadata/mdlib/cswlib.py +++ b/grass7/gui/wxpython/wx.metadata/mdlib/cswlib.py @@ -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 @@ -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) @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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): @@ -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) diff --git a/grass7/gui/wxpython/wx.metadata/mdlib/cswutil.py b/grass7/gui/wxpython/wx.metadata/mdlib/cswutil.py index 40e2c04cdf..edb7a97965 100644 --- a/grass7/gui/wxpython/wx.metadata/mdlib/cswutil.py +++ b/grass7/gui/wxpython/wx.metadata/mdlib/cswutil.py @@ -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) diff --git a/grass7/gui/wxpython/wx.metadata/mdlib/mdeditorfactory.py b/grass7/gui/wxpython/wx.metadata/mdlib/mdeditorfactory.py index 12eaef2b74..79b7247714 100644 --- a/grass7/gui/wxpython/wx.metadata/mdlib/mdeditorfactory.py +++ b/grass7/gui/wxpython/wx.metadata/mdlib/mdeditorfactory.py @@ -35,7 +35,7 @@ from owslib.iso import * except: sys.exit('owslib library is missing. Check requirements on the manual page < https://grasswiki.osgeo.org/wiki/ISO/INSPIRE_Metadata_Support >') -from mdjinjaparser import JinjaTemplateParser +from .mdjinjaparser import JinjaTemplateParser try: from jinja2 import Environment, FileSystemLoader except: @@ -46,7 +46,7 @@ from gui_core.widgets import IntegerValidator, NTCValidator, SimpleValidator,\ TimeISOValidator, EmailValidator # ,EmptyValidator -import mdutil +from . import mdutil from core.gcmd import RunCommand from subprocess import PIPE from grass.pygrass.modules import Module @@ -89,7 +89,7 @@ def initMD(self, path=None): return self.md - except Exception, e: + except Exception as e: GError('Error loading xml:\n' + str(e)) def saveToXML(self, md, owsTagList, jinjaPath, outPath=None, xmlOutName=None, msg=True, rmTeplate=False): @@ -129,8 +129,8 @@ def saveToXML(self, md, owsTagList, jinjaPath, outPath=None, xmlOutName=None, ms io = open(jinjaPath, 'w') io.write(str1) io.close() - except Exception,err: - print "WARNING: Cannot check and remove non ascii characters from template err:< %s >"%err + except Exception as err: + print("WARNING: Cannot check and remove non ascii characters from template err:< %s >"%err) # generating xml using jinja templates head, tail = os.path.split(jinjaPath) @@ -156,7 +156,7 @@ def saveToXML(self, md, owsTagList, jinjaPath, outPath=None, xmlOutName=None, ms return outPath - except Exception, e: + except Exception as e: GError('Error writing xml:\n' + str(e)) #========================================================================= @@ -889,7 +889,7 @@ def fillKeywordsList(self): return self.titles[titleTmp]=self.keysDict - for key in self.titles.keys(): + for key in list(self.titles.keys()): self.comboKeys.Append(key) def onSetVocabulary(self,evt): @@ -952,7 +952,7 @@ def executeStr(self, stri, mdDescrObj): for easy understanding to product of self.generateGUI()- print stri ''' #print stri - exec stri + exec(stri) def plusC(self, num=None): '''iterator for handling jinja teplate items in self.generateGUI and self.createNewMD @@ -1209,7 +1209,7 @@ def defineTemplate(self): ''' try: template = open(self.profilePath, 'r') - except Exception, e: + except Exception as e: GError('Error loading template:\n' + str(e)) owsTagList = list() @@ -1308,7 +1308,7 @@ def executeStr1(self, stri, item): for easier understanding to product of self.createNewMD()- print stri ''' #print stri - exec stri + exec(stri) def getKeywordsFromRepositoryWidget(self,md): if self.keywords is not None: diff --git a/grass7/gui/wxpython/wx.metadata/mdlib/mdgrass.py b/grass7/gui/wxpython/wx.metadata/mdlib/mdgrass.py index 568107336a..fd53ed9aba 100644 --- a/grass7/gui/wxpython/wx.metadata/mdlib/mdgrass.py +++ b/grass7/gui/wxpython/wx.metadata/mdlib/mdgrass.py @@ -31,9 +31,9 @@ set_path(modulename='wx.metadata', dirname='mdlib') from lxml import etree -import StringIO +import io import uuid -import mdutil # metadata lib +from . import mdutil # metadata lib from grass.pygrass.modules import Module from grass.script import parse_key_val @@ -103,7 +103,7 @@ def parseTemporal(self): type=self.type, stdout_=PIPE) md_h_grass = tinfoHist.outputs.stdout - buf = StringIO.StringIO(md_h_grass) + buf = io.StringIO(md_h_grass) line = buf.readline().splitlines() while line: @@ -136,7 +136,7 @@ def parseVect(self): stdout_=PIPE) md_h_grass = rinfo_h.outputs.stdout - buf = StringIO.StringIO(md_h_grass) + buf = io.StringIO(md_h_grass) line = buf.readline().splitlines() while str(line) != '[]': if str(line[0]).strip() != "": @@ -217,7 +217,7 @@ def getEPSG(self): def wkt2standards(self,prj_txt): try: from osgeo import osr - except Exception , e: + except Exception as e: grass.message('GDAL python library is not installed: %s \n identifying of EPSG is disabled'%e) return None @@ -503,7 +503,7 @@ def saveXML(self, path=None, xml_out_name=None, wxparent=None, overwrite=False): if not path: path = os.path.join(mdutil.pathToMapset(), 'metadata') if not os.path.exists(path): - print os.makedirs(path) + print(os.makedirs(path)) path = os.path.join(path, xml_out_name) # generate xml using jinja profiles @@ -523,7 +523,7 @@ def saveXML(self, path=None, xml_out_name=None, wxparent=None, overwrite=False): Module('g.message', message='metadata exported: \n\ %s' % (str(path))) except IOError as e: - print "I/O error({0}): {1}".format(e.errno, e.strerror) + print("I/O error({0}): {1}".format(e.errno, e.strerror)) grass.fatal('ERROR: cannot write xml to file') return path else: @@ -534,7 +534,7 @@ def saveXML(self, path=None, xml_out_name=None, wxparent=None, overwrite=False): Module('g.message', message='metadata exported: \n\ %s' % (str(path))) except IOError as e: - print "I/O error({0}): {1}".format(e.errno, e.strerror) + print("I/O error({0}): {1}".format(e.errno, e.strerror)) grass.fatal('ERROR: cannot write xml to file') # sys.exit() return path @@ -549,7 +549,7 @@ def saveXML(self, path=None, xml_out_name=None, wxparent=None, overwrite=False): Module('g.message', message='Metadata file has been overwritten') return path except IOError as e: - print "I/O error({0}): {1}".format(e.errno, e.strerror) + print("I/O error({0}): {1}".format(e.errno, e.strerror)) grass.fatal('error: cannot write xml to file') else: Module('g.message', message='For overwriting use flag -overwrite') @@ -563,7 +563,7 @@ def saveXML(self, path=None, xml_out_name=None, wxparent=None, overwrite=False): return path except IOError as e: - print "I/O error({0}): {1}".format(e.errno, e.strerror) + print("I/O error({0}): {1}".format(e.errno, e.strerror)) grass.fatal('error: cannot write xml to file') def validate_inspire(self): diff --git a/grass7/gui/wxpython/wx.metadata/mdlib/mdjinjaparser.py b/grass7/gui/wxpython/wx.metadata/mdlib/mdjinjaparser.py index 424936db2e..641e5a3668 100644 --- a/grass7/gui/wxpython/wx.metadata/mdlib/mdjinjaparser.py +++ b/grass7/gui/wxpython/wx.metadata/mdlib/mdjinjaparser.py @@ -16,7 +16,7 @@ @author Matej Krejci (GSoC 2014) """ from core.gcmd import GError -from mdutil import findBetween +from .mdutil import findBetween class MdDescription(): diff --git a/grass7/gui/wxpython/wx.metadata/mdlib/mdpdffactory.py b/grass7/gui/wxpython/wx.metadata/mdlib/mdpdffactory.py index cd0437a6e0..5836e4bcec 100755 --- a/grass7/gui/wxpython/wx.metadata/mdlib/mdpdffactory.py +++ b/grass7/gui/wxpython/wx.metadata/mdlib/mdpdffactory.py @@ -12,7 +12,7 @@ import math from reportlab.platypus import Paragraph, Image, Table from reportlab.platypus import PageBreak -from mdpdftheme import * +from .mdpdftheme import * class MyTheme(DefaultTheme): @@ -468,7 +468,7 @@ def __init__(self, coords, size=[200, 200]): self.pixel_range = [] self.pixels = 256 self.size = size - zoom_levels = range(0, 18) + zoom_levels = list(range(0, 18)) for z in zoom_levels: origin = self.pixels / 2 self.pixels_per_lon_degree.append(self.pixels / 360) @@ -602,7 +602,7 @@ def CalculateBoundsZoomLevel(self, bounds, view_size): zmin = 0 bottom_left = bounds[0] top_right = bounds[1] - backwards_range = range(zmin, zmax) + backwards_range = list(range(zmin, zmax)) backwards_range.reverse() for z in backwards_range: bottom_left_pixel = self.FromLatLngToPixel(bottom_left, z) @@ -634,8 +634,8 @@ def CalcBoundsFromPoints(self, lats, lngs): """ lats = [float(x) for x in lats] lngs = [float(x) for x in lngs] - flats = map(float, lats) - flngs = map(float, lngs) + flats = list(map(float, lats)) + flngs = list(map(float, lngs)) west = min(flngs) east = max(flngs) north = max(flats) diff --git a/grass7/gui/wxpython/wx.metadata/mdlib/mdpdftheme.py b/grass7/gui/wxpython/wx.metadata/mdlib/mdpdftheme.py index 49bc948db1..0e74ed61c3 100644 --- a/grass7/gui/wxpython/wx.metadata/mdlib/mdpdftheme.py +++ b/grass7/gui/wxpython/wx.metadata/mdlib/mdpdftheme.py @@ -3,8 +3,8 @@ from reportlab.lib import colors from reportlab.rl_config import canvas_basefontname as _baseFontName from reportlab.lib.enums import TA_LEFT, TA_CENTER -import cStringIO -import urllib +import io +import urllib.request, urllib.parse, urllib.error from reportlab.platypus.doctemplate import SimpleDocTemplate from reportlab.platypus.flowables import Image from reportlab.platypus import Paragraph, Spacer, KeepTogether @@ -250,7 +250,7 @@ class DefaultTheme(object): @classmethod def doc_template_args(cls): - return dict([(k, v) for k, v in cls.doc.items() if v is not None]) + return dict([(k, v) for k, v in list(cls.doc.items()) if v is not None]) @classmethod def header_for_level(cls, level): @@ -324,7 +324,7 @@ def add_image(self, src, width, height, align=CENTER): self.add(img) def render(self): - buffer = cStringIO.StringIO() + buffer = io.StringIO() doc_template_args = self.theme.doc_template_args() doc = SimpleDocTemplate(buffer, title=self.title, author=self.author, **doc_template_args) diff --git a/grass7/gui/wxpython/wx.metadata/mdlib/mdutil.py b/grass7/gui/wxpython/wx.metadata/mdlib/mdutil.py index d5f41d518f..c77e7326d8 100644 --- a/grass7/gui/wxpython/wx.metadata/mdlib/mdutil.py +++ b/grass7/gui/wxpython/wx.metadata/mdlib/mdutil.py @@ -73,7 +73,7 @@ def isTableExists(name): def removeNonAscii(s): '''Removed non ASCII chars ''' - s = filter(lambda x: x in string.printable, s) + s = [x for x in s if x in string.printable] return s diff --git a/grass7/gui/wxpython/wx.metadata/r.info.iso/r.info.iso.py b/grass7/gui/wxpython/wx.metadata/r.info.iso/r.info.iso.py index 40acc50ae7..f3b0e9306f 100755 --- a/grass7/gui/wxpython/wx.metadata/r.info.iso/r.info.iso.py +++ b/grass7/gui/wxpython/wx.metadata/r.info.iso/r.info.iso.py @@ -61,7 +61,7 @@ def main(): if xml_file is not False: md.readXML(xml_file) - print md.validate_inspire() + print(md.validate_inspire()) else: md.createGrassBasicISO() @@ -71,7 +71,7 @@ def main(): if xml_file is not False: md.readXML(xml_file) - print md.validate_basic() + print(md.validate_basic()) if __name__ == "__main__": diff --git a/grass7/gui/wxpython/wx.metadata/v.info.iso/v.info.iso.py b/grass7/gui/wxpython/wx.metadata/v.info.iso/v.info.iso.py index bf9a5f07e0..f1abb18f87 100755 --- a/grass7/gui/wxpython/wx.metadata/v.info.iso/v.info.iso.py +++ b/grass7/gui/wxpython/wx.metadata/v.info.iso/v.info.iso.py @@ -60,7 +60,7 @@ def main(): if xml_file is not False: md.readXML(xml_file) - print md.validate_inspire() + print(md.validate_inspire()) else: md.createGrassBasicISO() @@ -70,7 +70,7 @@ def main(): if xml_file is not False: md.readXML(xml_file) - print md.validate_basic() + print(md.validate_basic()) if __name__ == "__main__":