From ab7dca686579e92cba895c9f4b790f930231fced Mon Sep 17 00:00:00 2001 From: Tomas Zigo Date: Fri, 26 Jun 2020 21:17:12 +0200 Subject: [PATCH] wx.metadata/mdlib, t.info.iso, v.info.iso: fix flake8-strict errors --- .../gui/wxpython/wx.metadata/mdlib/mdutil.py | 461 ++++++++++++------ .../wx.metadata/t.info.iso/t.info.iso.py | 22 +- .../wx.metadata/v.info.iso/v.info.iso.py | 21 +- 3 files changed, 351 insertions(+), 153 deletions(-) diff --git a/grass7/gui/wxpython/wx.metadata/mdlib/mdutil.py b/grass7/gui/wxpython/wx.metadata/mdlib/mdutil.py index 1ba60b1261..868c1a4913 100644 --- a/grass7/gui/wxpython/wx.metadata/mdlib/mdutil.py +++ b/grass7/gui/wxpython/wx.metadata/mdlib/mdutil.py @@ -1,5 +1,6 @@ #!/usr/bin/env python -# -*- coding: utf-8 +# -*- coding: utf-8 -*- + """ @package mdgrass @module v.info.iso, r.info.iso, g.gui.metadata @@ -20,21 +21,29 @@ @author Matej Krejci (GSoC 2014) """ + import os +import string import sys +from subprocess import PIPE try: - 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 owslib.iso import ( + MD_DataIdentification, MD_Metadata, namespaces, + SV_ServiceIdentification, + ) +except ImportError: + sys.exit('owslib library is missing. Check requirements on the ' + 'manual page < https://grasswiki.osgeo.org/wiki/ISO/INSPIRE ' + 'Metadata_Support >') -from owslib import util -import string -from grass.script import core as grass from grass.pygrass.modules import Module -from subprocess import PIPE from grass.pygrass.utils import get_lib_path +from grass.script import core as grass + + +from owslib import util + import wx @@ -42,24 +51,42 @@ class StaticContext(object): def __init__(self): self.ppath = os.path.dirname(os.path.abspath(__file__)) - self.confDirPath = os.path.join(os.getenv('GRASS_ADDON_BASE'), 'etc', 'wx.metadata', 'config') + self.confDirPath = os.path.join( + os.getenv('GRASS_ADDON_BASE'), + 'etc', 'wx.metadata', 'config', + ) path = os.path.join('wx.metadata', 'config') - self.connResources = get_lib_path(modname=path, libname='connections_resources.xml') + self.connResources = get_lib_path( + modname=path, libname='connections_resources.xml', + ) if self.connResources is None: - grass.fatal("Fatal error: library < %s > not found" % path) + grass.fatal( + "Fatal error: library < {} > not found".format( + path), + ) else: - self.connResources = os.path.join(self.connResources, 'connections_resources.xml') + self.connResources = os.path.join( + self.connResources, 'connections_resources.xml', + ) - self.configureLibPath = get_lib_path(modname=path, libname='init_md.txt') + self.configureLibPath = get_lib_path( + modname=path, libname='init_md.txt', + ) if self.configureLibPath is None: - grass.fatal("Fatal error: library < %s > not found" % path) + grass.fatal( + "Fatal error: library < {} > not found".format(path), + ) path = os.path.join('wx.metadata', 'profiles') - self.profilesLibPath = get_lib_path(modname=path, libname='basicProfile.xml') + self.profilesLibPath = get_lib_path( + modname=path, libname='basicProfile.xml', + ) if self.profilesLibPath is None: grass.fatal("Fatal error: library < %s > not found" % path) - self.lib_path = os.path.normpath(self.configureLibPath + os.sep + os.pardir) + self.lib_path = os.path.normpath( + os.path.join(self.configureLibPath, os.pardir), + ) def isTableExists(name): @@ -78,7 +105,10 @@ def removeNonAscii(s): def yesNo(parent, question, caption='Yes or no?'): - dlg = wx.MessageDialog(parent, question, caption, wx.YES_NO | wx.ICON_QUESTION) + dlg = wx.MessageDialog( + parent, question, caption, + wx.YES_NO | wx.ICON_QUESTION, + ) result = dlg.ShowModal() == wx.ID_YES dlg.Destroy() return result @@ -89,7 +119,7 @@ def findBetween(s, first, last): start = s.index(first) + len(first) end = s.index(last, start) return s[start:end] - except: + except ValueError: return "" @@ -106,11 +136,15 @@ def replaceXMLReservedChar(inp): def pathToMapset(): gisenvDict = grass.gisenv() - return os.path.join(gisenvDict['GISDBASE'], gisenvDict['LOCATION_NAME'], gisenvDict['MAPSET']) + return os.path.join( + gisenvDict['GISDBASE'], + gisenvDict['LOCATION_NAME'], + gisenvDict['MAPSET'], + ) def grassProfileValidator(md): - '''function for validation of GRASS BASIC XML-OWSLib file-object''' + '''Validation of GRASS BASIC XML-OWSLib file-object''' result = {} result["status"] = "succeded" @@ -119,71 +153,97 @@ def grassProfileValidator(md): errors = 0 if md.identification is None: - result["errors"].append("gmd:CI_ResponsibleParty: Organization name is missing") + result["errors"].append( + "gmd:CI_ResponsibleParty: Organization name is missing") result["errors"].append("gmd:CI_ResponsibleParty: E-mail is missing") result["errors"].append("gmd:CI_ResponsibleParty: Role is missing") result["errors"].append("gmd:md_DataIdentification: Title is missing") - result["errors"].append("gmd:md_DataIdentification: Abstract is missing") + result["errors"].append( + "gmd:md_DataIdentification: Abstract is missing") result["errors"].append("gmd:md_ScopeCode: Resource type is missing") - result["errors"].append("gmd:RS_Identifier: Unique Resource Identifier is missing") + result["errors"].append( + "gmd:RS_Identifier: Unique Resource Identifier is missing") result["errors"].append("gmd:EX_Extent: Extent element is missing") - result["errors"].append("gmd:EX_GeographicBoundingBox: Bounding box is missing") - result["errors"].append("Both gmd:EX_TemporalExtent and gmd:CI_Date are missing") + result["errors"].append( + "gmd:EX_GeographicBoundingBox: Bounding box is missing") + result["errors"].append( + "Both gmd:EX_TemporalExtent and gmd:CI_Date are missing") result["errors"].append("gmd:useLimitation is missing") errors += 20 else: - if len(md.identification.contact) < 1 or md.identification.contact is None: - result["errors"].append("gmd:CI_ResponsibleParty: Organization name is missing") - result["errors"].append("gmd:CI_ResponsibleParty: E-mail is missing") - result["errors"].append("gmd:CI_ResponsibleParty: Role is missing") + if len(md.identification.contact) < 1 or \ + md.identification.contact is None: + result["errors"].append( + "gmd:CI_ResponsibleParty: Organization name is missing") + result["errors"].append( + "gmd:CI_ResponsibleParty: E-mail is missing") + result["errors"].append( + "gmd:CI_ResponsibleParty: Role is missing") errors += 3 else: if md.identification.contact[0].organization is (None or ''): - result["errors"].append("gmd:CI_ResponsibleParty: Organization name is missing") + result["errors"].append( + "gmd:CI_ResponsibleParty: Organization name is missing") errors += 1 if md.identification.contact[0].email is (None or ''): - result["errors"].append("gmd:CI_ResponsibleParty: E-mail is missing") + result["errors"].append( + "gmd:CI_ResponsibleParty: E-mail is missing") errors += 1 if md.identification.contact[0].role is (None or ''): - result["errors"].append("gmd:CI_ResponsibleParty: Role is missing") + result["errors"].append( + "gmd:CI_ResponsibleParty: Role is missing") errors += 1 if md.identification.title is (None or ''): - result["errors"].append("gmd:md_DataIdentification: Title is missing") + result["errors"].append( + "gmd:md_DataIdentification: Title is missing") errors += 1 if md.identification.abstract is (None or ''): - result["errors"].append("gmd:md_DataIdentification: Abstract is missing") + result["errors"].append( + "gmd:md_DataIdentification: Abstract is missing") errors += 1 - if md.identification.identtype is '': - result["errors"].append("gmd:md_ScopeCode: Resource type is missing") + if md.identification.identtype == '': + result["errors"].append( + "gmd:md_ScopeCode: Resource type is missing") errors += 1 if md.identification.extent is None: - result["errors"].append("gmd:EX_Extent: Extent element is missing") + result["errors"].append( + "gmd:EX_Extent: Extent element is missing") errors += 4 else: if md.identification.extent.boundingBox is None: - result["errors"].append("gmd:EX_GeographicBoundingBox: Bounding box is missing") + result["errors"].append( + "gmd:EX_GeographicBoundingBox: Bounding box is missing") errors += 4 else: if md.identification.extent.boundingBox.minx is (None or ''): - result["errors"].append("gmd:westBoundLongitude: minx is missing") + result["errors"].append( + "gmd:westBoundLongitude: minx is missing") errors += 1 if md.identification.extent.boundingBox.maxx is (None or ''): - result["errors"].append("gmd:eastBoundLongitude: maxx is missing") + result["errors"].append( + "gmd:eastBoundLongitude: maxx is missing") errors += 1 if md.identification.extent.boundingBox.miny is (None or ''): - result["errors"].append("gmd:southBoundLatitude: miny is missing") + result["errors"].append( + "gmd:southBoundLatitude: miny is missing") errors += 1 if md.identification.extent.boundingBox.maxy is (None or ''): - result["errors"].append("gmd:northBoundLatitude: maxy is missing") + result["errors"].append( + "gmd:northBoundLatitude: maxy is missing") errors += 1 - if len(md.identification.date) < 1 or (md.identification.temporalextent_start is ( - None or '') or md.identification.temporalextent_end is (None or '')): - result["errors"].append("Both gmd:EX_TemporalExtent and gmd:CI_Date are missing") + if (len(md.identification.date) < 1 or + ( + md.identification.temporalextent_start is (None or '') or + md.identification.temporalextent_end is (None or '') + )): + + result["errors"].append( + "Both gmd:EX_TemporalExtent and gmd:CI_Date are missing") errors += 1 if md.datestamp is (None or ''): @@ -201,7 +261,8 @@ def grassProfileValidator(md): errors += 3 else: if md.contact[0].organization is (None or ''): - result["errors"].append("gmd:contact: Organization name is missing") + result["errors"].append( + "gmd:contact: Organization name is missing") errors += 1 if md.contact[0].email is (None or ''): @@ -219,7 +280,7 @@ def grassProfileValidator(md): def isnpireValidator(md): - '''function for validation INSPIRE XML-OWSLib file-object''' + '''Validation INSPIRE XML-OWSLib file-object''' result = {} result["status"] = "succeded" @@ -228,108 +289,152 @@ def isnpireValidator(md): errors = 0 if md.identification is None: - result["errors"].append("gmd:CI_ResponsibleParty: Organization name is missing") + result["errors"].append( + "gmd:CI_ResponsibleParty: Organization name is missing") result["errors"].append("gmd:CI_ResponsibleParty: E-mail is missing") result["errors"].append("gmd:CI_ResponsibleParty: Role is missing") result["errors"].append("gmd:md_DataIdentification: Title is missing") - result["errors"].append("gmd:md_DataIdentification: Abstract is missing") + result["errors"].append( + "gmd:md_DataIdentification: Abstract is missing") result["errors"].append("gmd:md_ScopeCode: Resource type is missing") result["errors"].append("gmd:language: Resource language is missing") - result["errors"].append("gmd:RS_Identifier: Unique Resource Identifier is missing") + result["errors"].append( + "gmd:RS_Identifier: Unique Resource Identifier is missing") result["errors"].append("gmd:topicCategory: TopicCategory is missing") result["errors"].append("gmd:md_Keywords: Keywords are missing") - result["errors"].append("gmd:thesaurusName: Thesaurus title is missing") + result["errors"].append( + "gmd:thesaurusName: Thesaurus title is missing") result["errors"].append("gmd:thesaurusName: Thesaurus date is missing") - result["errors"].append("gmd:thesaurusName: Thesaurus date type is missing") + result["errors"].append( + "gmd:thesaurusName: Thesaurus date type is missing") result["errors"].append("gmd:EX_Extent: Extent element is missing") - result["errors"].append("gmd:EX_GeographicBoundingBox: Bounding box is missing") - result["errors"].append("Both gmd:EX_TemporalExtent and gmd:CI_Date are missing") + result["errors"].append( + "gmd:EX_GeographicBoundingBox: Bounding box is missing") + result["errors"].append( + "Both gmd:EX_TemporalExtent and gmd:CI_Date are missing") result["errors"].append("gmd:useLimitation is missing") result["errors"].append("gmd:accessConstraints is missing") result["errors"].append("gmd:otherConstraints is missing") errors += 20 else: - if md.identification.contact is None or len(md.identification.contact) < 1: - result["errors"].append("gmd:CI_ResponsibleParty: Organization name is missing") - result["errors"].append("gmd:CI_ResponsibleParty: E-mail is missing") + if md.identification.contact is None or \ + len(md.identification.contact) < 1: + + result["errors"].append( + "gmd:CI_ResponsibleParty: Organization name is missing") + result["errors"].append( + "gmd:CI_ResponsibleParty: E-mail is missing") result["errors"].append("gmd:CI_ResponsibleParty: Role is missing") errors += 3 - else: + else: if md.identification.contact[0].organization is (None or ''): - result["errors"].append("gmd:CI_ResponsibleParty: Organization name is missing") + result["errors"].append( + "gmd:CI_ResponsibleParty: Organization name is missing") errors += 1 if md.identification.contact[0].email is (None or ''): - result["errors"].append("gmd:CI_ResponsibleParty: E-mail is missing") + result["errors"].append( + "gmd:CI_ResponsibleParty: E-mail is missing") errors += 1 if md.identification.contact[0].role is (None or ''): - result["errors"].append("gmd:CI_ResponsibleParty: Role is missing") + result["errors"].append( + "gmd:CI_ResponsibleParty: Role is missing") errors += 1 if md.identification.title is (None or ''): - result["errors"].append("gmd:md_DataIdentification: Title is missing") + result["errors"].append( + "gmd:md_DataIdentification: Title is missing") errors += 1 if md.identification.abstract is (None or ''): - result["errors"].append("gmd:md_DataIdentification: Abstract is missing") + result["errors"].append( + "gmd:md_DataIdentification: Abstract is missing") errors += 1 if md.identification.identtype is (None or ''): - result["errors"].append("gmd:md_ScopeCode: Resource type is missing") + result["errors"].append( + "gmd:md_ScopeCode: Resource type is missing") errors += 1 if md.identification.resourcelanguage is None: errors += 1 - result["errors"].append("gmd:language: Resource language is missing") + result["errors"].append( + "gmd:language: Resource language is missing") else: - if len(md.identification.resourcelanguage) < 1 or md.identification.resourcelanguage[0] == '': - result["errors"].append("gmd:language: Resource language is missing") + if len(md.identification.resourcelanguage) < 1 or \ + md.identification.resourcelanguage[0] == '': + result["errors"].append( + "gmd:language: Resource language is missing") errors += 1 if md.identification.uricode is None: - result["errors"].append("gmd:RS_Identifier: Unique Resource Identifier is missing") + result["errors"].append( + "gmd:RS_Identifier: Unique Resource Identifier is missing") errors += 1 else: - if len(md.identification.uricode) < 1 or md.identification.uricode[0] == '': - result["errors"].append("gmd:RS_Identifier: Unique Resource Identifier is missing") + if len(md.identification.uricode) < 1 or \ + md.identification.uricode[0] == '': + result["errors"].append( + "gmd:RS_Identifier: Unique Resource Identifier is missing") errors += 1 if md.identification.topiccategory is None: - result["errors"].append("gmd:topicCategory: TopicCategory is missing") + result["errors"].append( + "gmd:topicCategory: TopicCategory is missing") errors += 1 else: - if len(md.identification.topiccategory) < 1 or md.identification.topiccategory[0] == '': - result["errors"].append("gmd:topicCategory: TopicCategory is missing") + if len(md.identification.topiccategory) < 1 or \ + md.identification.topiccategory[0] == '': + result["errors"].append( + "gmd:topicCategory: TopicCategory is missing") errors += 1 - if md.identification.keywords is None or len(md.identification.keywords) < 1: + if md.identification.keywords is None or \ + len(md.identification.keywords) < 1: + result["errors"].append("gmd:MD_Keywords: Keywords are missing") - result["errors"].append("gmd:thesaurusName: Thesaurus title is missing") - result["errors"].append("gmd:thesaurusName: Thesaurus date is missing") - result["errors"].append("gmd:thesaurusName: Thesaurus date type is missing") + result["errors"].append( + "gmd:thesaurusName: Thesaurus title is missing") + result["errors"].append( + "gmd:thesaurusName: Thesaurus date is missing") + result["errors"].append( + "gmd:thesaurusName: Thesaurus date type is missing") errors += 4 + else: - if md.identification.keywords[0]['keywords'] is None or len(md.identification.keywords[0]['keywords']) < 1 \ - or str(md.identification.keywords[0]['keywords']) == "[u'']": - result["errors"].append("gmd:MD_Keywords: Keywords are missing") + if ( + md.identification.keywords[0]['keywords'] is None or + len(md.identification.keywords[0]['keywords']) < 1 or + str(md.identification.keywords[0]['keywords']) == "[u'']" + ): + + result["errors"].append( + "gmd:MD_Keywords: Keywords are missing") errors += 1 if md.identification.keywords[0]['thesaurus'] is None: - result["errors"].append("gmd:thesaurusName: Thesaurus title is missing") - result["errors"].append("gmd:thesaurusName: Thesaurus date is missing") - result["errors"].append("gmd:thesaurusName: Thesaurus date type is missing") + result["errors"].append( + "gmd:thesaurusName: Thesaurus title is missing") + result["errors"].append( + "gmd:thesaurusName: Thesaurus date is missing") + result["errors"].append( + "gmd:thesaurusName: Thesaurus date type is missing") errors += 3 else: - if md.identification.keywords[0]['thesaurus']['title'] is None \ - or len(md.identification.keywords[0]['thesaurus']['title']) < 1: - result["errors"].append("gmd:thesaurusName: Thesaurus title is missing") + title = md.identification.keywords[0]['thesaurus']['title'] + if (title is None or len(title) < 1): + result["errors"].append( + "gmd:thesaurusName: Thesaurus title is missing") errors += 1 - if md.identification.keywords[0]['thesaurus']['date'] is None \ - or len(md.identification.keywords[0]['thesaurus']['date']) < 1: - result["errors"].append("gmd:thesaurusName: Thesaurus date is missing") + date = md.identification.keywords[0]['thesaurus']['date'] + if date is None or len(date) < 1: + result["errors"].append( + "gmd:thesaurusName: Thesaurus date is missing") errors += 1 - if md.identification.keywords[0]['thesaurus']['datetype'] is None \ - or len(md.identification.keywords[0]['thesaurus']['datetype']) < 1: - result["errors"].append("gmd:thesaurusName: Thesaurus date type is missing") + datetype = (md.identification.keywords[0]['thesaurus'] + ['datetype']) + if datetype is None or len(datetype) < 1: + result["errors"].append( + "gmd:thesaurusName: Thesaurus date type is missing") errors += 1 if md.identification.extent is None: @@ -342,30 +447,43 @@ def isnpireValidator(md): errors += 1 else: if md.identification.extent.boundingBox.minx is (None or ''): - result["errors"].append("gmd:westBoundLongitude: minx is missing") + result["errors"].append( + "gmd:westBoundLongitude: minx is missing") errors += 1 if md.identification.extent.boundingBox.maxx is (None or ''): - result["errors"].append("gmd:eastBoundLongitude: maxx is missing") + result["errors"].append( + "gmd:eastBoundLongitude: maxx is missing") errors += 1 if md.identification.extent.boundingBox.miny is (None or ''): - result["errors"].append("gmd:southBoundLatitude: miny is missing") + result["errors"].append( + "gmd:southBoundLatitude: miny is missing") errors += 1 if md.identification.extent.boundingBox.maxy is (None or ''): - result["errors"].append("gmd:northBoundLatitude: maxy is missing") + result["errors"].append( + "gmd:northBoundLatitude: maxy is missing") errors += 1 - if len(md.identification.date) < 1 or (md.identification.temporalextent_start is ( - None or '') or md.identification.temporalextent_end is (None or '')): - result["errors"].append("Both gmd:EX_TemporalExtent and gmd:CI_Date are missing") + if ( + len(md.identification.date) < 1 or + ( + md.identification.temporalextent_start is (None or '') or + md.identification.temporalextent_end is (None or '') + ) + ): + result["errors"].append( + "Both gmd:EX_TemporalExtent and gmd:CI_Date are missing") errors += 1 - if len(md.identification.uselimitation) < 1 or md.identification.uselimitation[0] == '': + if len(md.identification.uselimitation) < 1 or \ + md.identification.uselimitation[0] == '': result["errors"].append("gmd:useLimitation is missing") errors += 1 - if len(md.identification.accessconstraints) < 1 or md.identification.accessconstraints[0] == '': + if len(md.identification.accessconstraints) < 1 or \ + md.identification.accessconstraints[0] == '': result["errors"].append("gmd:accessConstraints is missing") errors += 1 - if len(md.identification.otherconstraints) < 1 or md.identification.otherconstraints[0] == '': + if len(md.identification.otherconstraints) < 1 or \ + md.identification.otherconstraints[0] == '': result["errors"].append("gmd:otherConstraints is missing") errors += 1 @@ -381,8 +499,10 @@ def isnpireValidator(md): if md.dataquality is (None or ''): result["errors"].append("gmd:LI_Lineage is missing") result["errors"].append("gmd:DQ_ConformanceResult: Date is missing") - result["errors"].append("gmd:DQ_ConformanceResult: Date type is missing") - # result["errors"].append("gmd:DQ_ConformanceResult: Degree is missing") + result["errors"].append( + "gmd:DQ_ConformanceResult: Date type is missing") + # result["errors"].append( + # "gmd:DQ_ConformanceResult: Degree is missing") result["errors"].append("gmd:DQ_ConformanceResult: Title is missing") errors += 4 else: @@ -390,17 +510,24 @@ def isnpireValidator(md): if md.dataquality.lineage is (None or ''): result["errors"].append("gmd:LI_Lineage is missing") errors += 1 - if len(md.dataquality.conformancedate) < 1 or md.dataquality.conformancedate[0] == '': - result["errors"].append("gmd:DQ_ConformanceResult: Date is missing") + if len(md.dataquality.conformancedate) < 1 or \ + md.dataquality.conformancedate[0] == '': + result["errors"].append( + "gmd:DQ_ConformanceResult: Date is missing") errors += 1 - if len(md.dataquality.conformancedatetype) < 1 or md.dataquality.conformancedatetype[0] == '': - result["errors"].append("gmd:DQ_ConformanceResult: Date type is missing") + if len(md.dataquality.conformancedatetype) < 1 or \ + md.dataquality.conformancedatetype[0] == '': + result["errors"].append( + "gmd:DQ_ConformanceResult: Date type is missing") errors += 1 # if len(md.dataquality.conformancedegree) < 1: - # result["errors"].append("gmd:DQ_ConformanceResult: Degree is missing") + # result["errors"].append( + # "gmd:DQ_ConformanceResult: Degree is missing") # errors += 1 - if len(md.dataquality.conformancetitle) < 1 or md.dataquality.conformancetitle[0] == '': - result["errors"].append("gmd:DQ_ConformanceResult: Title is missing") + if len(md.dataquality.conformancetitle) < 1 or \ + md.dataquality.conformancetitle[0] == '': + result["errors"].append( + "gmd:DQ_ConformanceResult: Title is missing") errors += 1 if md.contact is None or len(md.contact) < 1: @@ -411,7 +538,8 @@ def isnpireValidator(md): else: if md.contact[0].organization is (None or ''): - result["errors"].append("gmd:contact: Organization name is missing") + result["errors"].append( + "gmd:contact: Organization name is missing") errors += 1 if md.contact[0].email is (None or ''): @@ -443,30 +571,63 @@ def __init__(self, md=None, identtype=None): val1 = None val3 = None val4 = None - extents = md.findall(util.nspath_eval('gmd:extent', namespaces)) - extents.extend(md.findall(util.nspath_eval('srv:extent', namespaces))) + extents = md.findall( + util.nspath_eval('gmd:extent', namespaces), + ) + extents.extend( + md.findall( + util.nspath_eval('srv:extent', namespaces), + ), + ) for extent in extents: if val2 is None: - val2 = extent.find(util.nspath_eval( - 'gmd:EX_Extent/gmd:temporalElement/gmd:EX_TemporalExtent/gmd:extent/gml:TM_PeriodDuration/gml:duration', - namespaces)) # TODO + duration = ('gmd:EX_Extent/gmd:temporalElement/' + 'gmd:EX_TemporalExtent/gmd:extent/' + 'gml:TM_PeriodDuration/gml:duration') + val2 = extent.find( + util.nspath_eval( + duration, + namespaces, + ), + ) # TODO self.temporalType = util.testXMLValue(val2) if val1 is None: - val1 = extent.find(util.nspath_eval( - 'gmd:EX_Extent/gmd:temporalElement/gmd:EX_TemporalExtent/gmd:extent/gml:timeLength/gml:timeInterval/gml:unit/gml:TimeUnitType', - namespaces)) + time_unit_type = ('gmd:EX_Extent/gmd:temporalElement/' + 'gmd:EX_TemporalExtent/gmd:extent/' + 'gml:timeLength/gml:timeInterval/' + 'gml:unit/gml:TimeUnitType') + val1 = extent.find( + util.nspath_eval( + time_unit_type, + namespaces, + ), + ) self.timeUnit = util.testXMLValue(val1) if val3 is None: - val3 = extent.find(util.nspath_eval( - 'gmd:EX_Extent/gmd:temporalElement/gmd:EX_TemporalExtent/gmd:extent/gml:timeLength/gml:timeInterval/gml:radix/gco:positiveInteger', - namespaces)) + positive_int = ('gmd:EX_Extent/gmd:temporalElement/' + 'gmd:EX_TemporalExtent/gmd:extent/' + 'gml:timeLength/gml:timeInterval/' + 'gml:radix/gco:positiveInteger') + val3 = extent.find( + util.nspath_eval( + positive_int, + namespaces, + ), + ) self.radixT = util.testXMLValue(val3) if val4 is None: - val4 = extent.find(util.nspath_eval( - 'gmd:EX_Extent/gmd:temporalElement/gmd:EX_TemporalExtent/gmd:extent/gml:timeLength/gml:timeInterval/gml:factor/gco:Integer', - namespaces)) + integer = ('gmd:EX_Extent/gmd:temporalElement/' + 'gmd:EX_TemporalExtent/gmd:extent/' + 'gml:timeLength/gml:timeInterval/' + 'gml:factor/gco:Integer') + val4 = extent.find( + util.nspath_eval( + integer, + namespaces, + ), + ) self.factor = util.testXMLValue(val4) @@ -476,28 +637,56 @@ class MD_MetadataMOD(MD_Metadata): def __init__(self, md=None): MD_Metadata.__init__(self, md) if md is not None: - val = md.find(util.nspath_eval('gmd:identificationInfo/gmd:MD_DataIdentification', namespaces)) - val2 = md.find(util.nspath_eval('gmd:identificationInfo/srv:SV_ServiceIdentification', namespaces)) + val = md.find( + util.nspath_eval( + 'gmd:identificationInfo/gmd:MD_DataIdentification', + namespaces, + ), + ) + val2 = md.find( + util.nspath_eval( + 'gmd:identificationInfo/srv:SV_ServiceIdentification', + namespaces, + ), + ) if val is not None: self.identification = MD_DataIdentification_MOD(val, 'dataset') self.serviceidentification = None elif val2 is not None: - self.identification = MD_DataIdentification_MOD(val2, 'service') + self.identification = MD_DataIdentification_MOD( + val2, 'service', + ) self.serviceidentification = SV_ServiceIdentification(val2) else: self.identification = None self.serviceidentification = None self.identificationinfo = [] - for idinfo in md.findall(util.nspath_eval('gmd:identificationInfo', namespaces)): + for idinfo in md.findall( + util.nspath_eval( + 'gmd:identificationInfo', + namespaces, + ), + ): val = list(idinfo)[0] tagval = util.xmltag_split(val.tag) if tagval == 'MD_DataIdentification': - self.identificationinfo.append(MD_DataIdentification_MOD(val, 'dataset')) + self.identificationinfo.append( + MD_DataIdentification_MOD(val, 'dataset'), + ) elif tagval == 'MD_ServiceIdentification': - self.identificationinfo.append(MD_DataIdentification_MOD(val, 'service')) + self.identificationinfo.append( + MD_DataIdentification_MOD(val, 'service'), + ) elif tagval == 'SV_ServiceIdentification': - self.identificationinfo.append(SV_ServiceIdentification(val)) - - val = md.find(util.nspath_eval('gmd:distributionInfo/gmd:MD_Distribution', namespaces)) + self.identificationinfo.append( + SV_ServiceIdentification(val), + ) + + val = md.find( + util.nspath_eval( + 'gmd:distributionInfo/gmd:MD_Distribution', + namespaces, + ), + ) diff --git a/grass7/gui/wxpython/wx.metadata/t.info.iso/t.info.iso.py b/grass7/gui/wxpython/wx.metadata/t.info.iso/t.info.iso.py index 7dc601cd2a..a0ea1e42e8 100644 --- a/grass7/gui/wxpython/wx.metadata/t.info.iso/t.info.iso.py +++ b/grass7/gui/wxpython/wx.metadata/t.info.iso/t.info.iso.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -# -*- coding: utf-8 +# -*- coding: utf-8 -*- """ @module r.info.iso @brief Module for creating metadata based on ISO for raster maps @@ -10,6 +10,7 @@ @author Matej Krejci (GSoC 2015) """ + #%module #% description: Lists information about space time datasets and maps. #% keyword: temporal @@ -42,7 +43,7 @@ def main(): - # load metadata library + # Load metadata library from mdlib.mdgrass import GrassMD if not options['output']: @@ -54,7 +55,6 @@ def main(): name = options["input"] type_ = options["type"] - # Make sure the temporal database exists tgis.init() @@ -63,18 +63,22 @@ def main(): if name.find("@") >= 0: id_ = name else: - id_ = name + "@" + grass.gisenv()["MAPSET"] + id_ = "{}@{}".format(name, grass.gisenv()["MAPSET"]) dataset = tgis.dataset_factory(type_, id_) - if dataset.is_in_db(dbif) == False: - grass.fatal(_("Dataset <%s> not found in temporal database") % (id_)) + if not dataset.is_in_db(dbif): + grass.fatal( + _("Dataset <%s> not found in temporal database") % (id_), + ) md = GrassMD(id_, type=type_) md.createTemporalISO() - md.saveXML(path=destination, - xml_out_name=name, - overwrite=os.getenv('GRASS_OVERWRITE', False)) + md.saveXML( + path=destination, + xml_out_name=name, + overwrite=os.getenv('GRASS_OVERWRITE', False), + ) 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 cdbad1a0e1..00032a18a8 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 @@ -1,5 +1,5 @@ #!/usr/bin/env python -# -*- coding: utf-8 +# -*- coding: utf-8 -*- """ @module v.info.iso @brief Module for creating metadata based on ISO for vector maps @@ -41,8 +41,9 @@ set_path(modulename='wx.metadata', dirname='mdlib', path='..') + def main(): - # load metadata library + # Load metadata library from mdlib.mdgrass import GrassMD if not options['output']: @@ -54,9 +55,11 @@ def main(): md = GrassMD(options['map'], 'vector') if options['profile'] == 'inspire': md.createGrassInspireISO() - xml_file = md.saveXML(path=destination, - xml_out_name=name, - overwrite=os.getenv('GRASS_OVERWRITE', False)) + xml_file = md.saveXML( + path=destination, + xml_out_name=name, + overwrite=os.getenv('GRASS_OVERWRITE', False), + ) if xml_file is not False: md.readXML(xml_file) @@ -64,9 +67,11 @@ def main(): else: md.createGrassBasicISO() - xml_file = md.saveXML(path=destination, - xml_out_name=name, - overwrite=os.getenv('GRASS_OVERWRITE', False)) + xml_file = md.saveXML( + path=destination, + xml_out_name=name, + overwrite=os.getenv('GRASS_OVERWRITE', False), + ) if xml_file is not False: md.readXML(xml_file)