[GRASS-SVN] r61407 - sandbox/krejcmat/src
svn_grass at osgeo.org
svn_grass at osgeo.org
Fri Jul 25 13:48:37 PDT 2014
Author: krejcmat
Date: 2014-07-25 13:48:37 -0700 (Fri, 25 Jul 2014)
New Revision: 61407
Modified:
sandbox/krejcmat/src/editor3.py
sandbox/krejcmat/src/g.gui.metadata.py
sandbox/krejcmat/src/jinjainfo.py
sandbox/krejcmat/src/mdgrass.py
sandbox/krejcmat/src/r.info.iso.py
Log:
g.gui.metadata alpha
Modified: sandbox/krejcmat/src/editor3.py
===================================================================
--- sandbox/krejcmat/src/editor3.py 2014-07-25 20:18:24 UTC (rev 61406)
+++ sandbox/krejcmat/src/editor3.py 2014-07-25 20:48:37 UTC (rev 61407)
@@ -17,6 +17,9 @@
import re
import os
import string
+import logging
+from core.gcmd import RunCommand, GError, GMessage
+import sys
#=========================================================================
@@ -30,22 +33,31 @@
# self.readXML()
def initMD(self, path=None):
+ #print path
if path is None:
self.md = MD_Metadata(md=None)
+
return self.md
else:
- tree = ET.parse(path)
- root = tree.getroot()
- self.md = MD_Metadata(root)
- return self.md
-
+
+ try:
+ tree = ET.parse(path)
+ root = tree.getroot()
+ self.md = MD_Metadata(root)
+ return self.md
+ except Exception, e:
+ ##print e
+
+ GError('Error loading xml:\n'+str(e))
+
+
def saveToXML(self, md, jinjaPath, outPath=None, xmlOutName=None):
# if output file name is None, use map name and add postfix
self.dirpath = os.path.dirname(os.path.realpath(__file__))
self.md = md
- jinjaPath
+
if xmlOutName is None:
- xmlOutName = 'testExportMD' # TODO change to name of map
+ xmlOutName = 'RANDExportMD' # TODO change to name of map
if not xmlOutName.lower().endswith('.xml'):
xmlOutName += '.xml'
# if path is None, use lunch. dir
@@ -56,6 +68,7 @@
outPath = os.path.join(outPath, xmlOutName)
# generate xml using jinja tempaltes
+ #print jinjaPath
head, tail = os.path.split(jinjaPath)
env = Environment(loader=FileSystemLoader(head))
env.globals.update(zip=zip)
@@ -65,14 +78,16 @@
# write xml to flat file
try:
+ #print '*'*100
+ #print 'saveToXML'
xml_file = open(outPath, "w")
xml_file.write(iso_xml)
xml_file.close()
- print 'metadata exported: \n%s' % (str(outPath))
+ #print 'metadata exported: \n%s' % (str(outPath))
- except IOError as e:
- print "I/O error({0}): {1}".format(e.errno, e.strerror)
- grass.fatal('error: cannot write xml file')
+ except Exception, e:
+ GError('Error loading xml:\n'+str(e))
+ sys.exit()
return outPath
#=========================================================================
@@ -190,13 +205,13 @@
# mdItem1.setValue('')
itemList.append(mdItem1)
i.addMdItem(mdItem1)
- # print i.mdItem
+ # #print i.mdItem
self.mdBox.addItems(itemList, False, True)
else:
self.mdItem = MdItem(parent, mdItems, False, True)
if mdItems.inbox is not None:
- print 'here------------1'
+ #print 'here------------1'
mdItems.addMdItem(self.mdItem, mdItemOld)
else:
mdItems.addMdItem(self.mdItem)
@@ -269,13 +284,6 @@
def __init__(self,parent,item,multiplicity=None,rmMulti=False,isFirstNum=-1):
wx.BoxSizer.__init__(self, wx.VERTICAL)
self.mdDescription = item
- #======================================================================
- # print self.mdDescription
- # print self.mdDescription.tag
- # print self.mdDescription.name
- # print self.mdDescription.mdItem
- # print '-----'
- #======================================================================
if multiplicity is None:
self.multiple = item.multiplicity
@@ -321,13 +329,23 @@
def createInfo(self):
string = ''
+ if self.mdDescription.ref is not None:
+ string += self.mdDescription.ref + '\n\n'
if self.mdDescription.name is not None:
- string += 'name: ' + self.mdDescription.name + '\n'
+ string += 'NAME: \n' + self.mdDescription.name + '\n\n'
if self.mdDescription.desc is not None:
- string += 'description: ' + self.mdDescription.desc + '\n'
+ string += 'DESCRIPTION: \n' + self.mdDescription.desc + '\n\n'
if self.mdDescription.example is not None:
- string += 'example: ' + self.mdDescription.example + '\n'
-
+ string += 'EXAMPLE: \n' + self.mdDescription.example + '\n\n'
+ if self.mdDescription.type is not None:
+ string += 'DATA TYPE: \n' + self.mdDescription.type + '\n\n'
+ string += '- -'*30 + '\n'
+ if self.mdDescription.statements is not None:
+ string += 'statements: \n' + self.mdDescription.statements + '\n'
+ if self.mdDescription.statements1 is not None:
+ string += self.mdDescription.statements1 + '\n'
+
+ string += '\ntag: \n' + self.mdDescription.tag
self.infoTip = string
def removeItem(self, evt):
@@ -360,7 +378,18 @@
self.valueCtrl.GetId())
def setValue(self, value):
- self.valueCtrl.SetValue(value)
+ ##print "value ",value
+
+ if value is None:
+ self.valueCtrl.SetBackgroundColour((245,204,230))
+ self.valueCtrl.SetValue('')
+ elif value=='$NULL':
+ self.valueCtrl.SetBackgroundColour((255,255,82))
+ self.valueCtrl.SetValue('')
+ else:
+ value=value.replace('"','')
+ value=value.replace("'",'')
+ self.valueCtrl.SetValue(value)
def getValue(self):
return self.valueCtrl.GetValue()
@@ -423,23 +452,26 @@
return self.sizerIndex
def addItem(self, item):
-
+ ##print "****---*",type(item)
if isinstance(item, list):
for i in item:
- self.sizerIndexDict[i.GetId()] = self._getIndex()
+ ##print "1****---*",type(i)
+ if isinstance(i, list):
+ for ii in i:
+ self.sizerIndexDict[ii.getCtrlID()] = self._getIndex()
+ self.mainSizer.Add(ii, proportion=0, flag=wx.EXPAND)
+ else:
+ self.sizerIndexDict[i.getCtrlID()] = self._getIndex()
+ self.mainSizer.Add(i, proportion=0, flag=wx.EXPAND)
+ else:
- # self.items.append(i)
- self.mainSizer.Add(i, proportion=0, flag=wx.EXPAND)
- else:
- # self.items.append(item)
- # print item.getCtrlID()
self.sizerIndexDict[item.getCtrlID()] = self._getIndex()
self.mainSizer.Add(item, proportion=0, flag=wx.EXPAND)
def addDuplicatedItem(self, item, id):
self.items.append(item)
posIndex = self.sizerIndexDict[id]
- # print posIndex
+ # #print posIndex
self.mainSizer.Insert(posIndex, item, proportion=0, flag=wx.EXPAND)
self.SetSizerAndFit(self.mainSizer)
@@ -455,36 +487,38 @@
item.Destroy()
self.SetSizerAndFit(self.mainSizer)
- def getPositionInSizer(self):
- """ Returns the current position of this control in its containing
- sizer. This is useful for when a control needs to be re-created in
- place.
- If the containing sizer is a box sizer, the integer position will
- be returned. If it is a grid sizer, a row,col tuple will be returned.
- If the object is not contained in a sizer, None will be returned.
- """
- sz = self.GetContainingSizer()
- if not sz:
- return None
- if isinstance(sz, wx.BoxSizer):
- chil = sz.GetChildren()
- for pos in range(len(chil)):
- # Yeah, normally we'd just iterate over the children, but
- # we want the position, so...
- szitem = chil[pos]
- if szitem.IsWindow():
- if szitem.GetWindow() == self:
- return pos
- # If we reached here, something's wrong!
- dabo.errorLog.write(_("Containing sizer did not match item %s")
- % self.Name)
- return None
- elif isinstance(sz, wx.GridBagSizer):
- # Return a row,col tuple
- row, col = sz.GetItemPosition(self)
- eturn(row, col)
- else:
- return None
+ #===========================================================================
+ # def getPositionInSizer(self):
+ # """ Returns the current position of this control in its containing
+ # sizer. This is useful for when a control needs to be re-created in
+ # place.
+ # If the containing sizer is a box sizer, the integer position will
+ # be returned. If it is a grid sizer, a row,col tuple will be returned.
+ # If the object is not contained in a sizer, None will be returned.
+ # """
+ # sz = self.GetContainingSizer()
+ # if not sz:
+ # return None
+ # if isinstance(sz, wx.BoxSizer):
+ # chil = sz.GetChildren()
+ # for pos in range(len(chil)):
+ # # Yeah, normally we'd just iterate over the children, but
+ # # we want the position, so...
+ # szitem = chil[pos]
+ # if szitem.IsWindow():
+ # if szitem.GetWindow() == self:
+ # return pos
+ # # If we reached here, something's wrong!
+ # dabo.errorLog.write(_("Containing sizer did not match item %s")
+ # % self.Name)
+ # return None
+ # elif isinstance(sz, wx.GridBagSizer):
+ # # Return a row,col tuple
+ # row, col = sz.GetItemPosition(self)
+ # eturn(row, col)
+ # else:
+ # return None
+ #===========================================================================
#=========================================================================
# MAIN FRAME
#=========================================================================
@@ -514,7 +548,7 @@
#----------------------------------------------------------- GUI GENERATOR START
def executeStr(self, stri, linfo):
- print stri
+ #print stri
exec stri
def plusC(self, num=None):
@@ -562,19 +596,41 @@
if 'zip(' in lstruct[c]:
sta = lstruct[c]
lstruct[c] = sta.replace('md.', 'self.md.')
-
+
+ def chckIfStetementsFORisValid(sta):
+ self.isValidS=False
+ staTMP=sta
+ if not '\t'in staTMP:
+ tab='\t'
+ tab1=''
+ else:
+ tab='\t\t'
+ tab1='\t'
+
+ staTMP=staTMP+":\n"+tab+'self.isValidS=True'
+ self.executeStr(staTMP, False)
+ ##print 'is valid===',self.isValidS
+ if self.isValidS:
+ return sta
+ else:
+ return tab1+'for n in range(1)'
+
+
def inBlock(): # function in def initCreatorMD(self): !!!
'''
@note:
'''
+ ##print 'c--' , self.c
IFStatements = False
statements = lstruct[self.c - 1]
if 'if' in statements.split():
IFStatements = True
-
+
+ looptmp=chckIfStetementsFORisValid(statements.replace(' md.', ' self.md.'))
str2 = 'numOfSameBox=0\n'
- str2 += statements.replace(' md.', ' self.md.')
- looptmp = statements.replace(' md.', ' self.md.')
+ str2 += looptmp
+
+
str2 += ':\n'
str2 += '\t' + 'self.ItemList=list()\n' # initialize list
str2 += '\t' + 'numOfSameBox+=1\n'
@@ -585,27 +641,34 @@
str2 += '\t' + \
'box=MdBox(self.nbPage,linfo[' + str(self.c) + '].inbox)\n' # add box
str1 = str2
-
+ itemCounter=1
while '\t' in lstruct[self.c] and self.stop is False:
+ itemCounter+=1
if 'for' not in str(lstruct[self.c]).split()\
- and 'if' not in str(lstruct[self.c]).split():
+ and 'if' not in str(lstruct[self.c]).split():
+
value = str(self.mdOWSTagStrList[self.c])
str1 += '\t' + \
'self.mdDescription[' + str(self.c) + '].addStatements("' + looptmp + '")\n'
- str1 += '\t' + 'self.cTmp=' + str(self.c) + '\n'
+
if box:
str1 += '\t' + \
'it=MdItem(parent=box,item=linfo[' + str(self.c) + '],isFirstNum=numOfSameBox)\n'
else:
str1 += '\t' + \
'it=MdItem(parent=self.nbPage,item=linfo[' + str(self.c) + '],isFirstNum=numOfSameBox)\n'
-
- if IFStatements:
- str1 += '\t' + 'it.setValue(self.' + str(value) + ')\n'
- else:
- str1 += '\t' + 'it.setValue(' + str(value) + ')\n'
-
+ if self.isValidS: #if metatdata are loaded to owslib
+ if IFStatements:
+
+ str1 += '\t' + 'it.setValue(self.' + str(value) + ')\n'
+ else:
+ str1 += '\t' + 'it.setValue(' + str(value) + ')\n'
+ else:
+ if IFStatements:
+ str1 += '\t' + 'it.setValue("$NULL")\n'
+ else:
+ str1 += '\t' + 'it.setValue("$NULL")\n'
str1 += '\t' + \
'self.mdDescription[' + str(self.c) + '].addMdItem(it)\n'
str1 += '\t' + 'self.ItemList.append(it)\n'
@@ -622,11 +685,13 @@
str2 += '\t' + 'numOfSameItem=0\n'
looptmp1 = statements.replace(' md.', ' self.md.')
+ #looptmp1=chckIfStetementsFORisValid(looptmp1)
str2 += looptmp1 + ':\n'
self.plusC()
str1 += str2
+ itemCounter+=1
while '\t\t' in lstruct[self.c] and self.stop is False:
-
+ itemCounter+=1
value = str(self.mdOWSTagStrList[self.c])
# save information about loops
str1 += '\t\t' + 'numOfSameItem+=1\n'
@@ -634,8 +699,6 @@
'self.mdDescription[' + str(self.c) + "].addStatements('" + looptmp + "')\n"
str1 += '\t\t' + \
'self.mdDescription[' + str(self.c) + "].addStatements1('" + looptmp1 + "')\n"
- str1 += '\t\t' + 'self.cTmp=' + \
- str(self.c) + '\n' # save wx id
if box:
str1 += '\t\t' + \
@@ -643,8 +706,10 @@
else:
str1 += '\t\t' + \
'it=MdItem(self.nbPage,linfo[' + str(self.c) + '],isFirstNum=numOfSameItem)\n'
-
- str1 += '\t\t' + 'it.setValue(' + str(value) + ')\n'
+ if self.isValidS:
+ str1 += '\t\t' + 'it.setValue(' + str(value) + ')\n'
+ else:
+ str1 += '\t\t' + 'it.setValue("$NULL")\n'
str1 += '\t\t' + 'self.ItemList.append(it)\n'
if keyword:
@@ -658,9 +723,8 @@
tab = '\t\t'
self.plusC()
- self.c -= 1
- print '-' * 80
- print linfo[self.c].inboxmulti
+ ##print '-' * 80
+ ##print linfo[self.c].inboxmulti
if box:
str1 += tab + \
'box.addItems(items=self.ItemList,multi=linfo[self.c].inboxmulti,isFirstNum=numOfSameBox)\n'
@@ -668,9 +732,12 @@
else:
str1 += tab + 'self.nbPage.addItem(self.ItemList)\n'
- str1 += tab + 'self.plusC()\n'
+ #str1 += tab + 'self.plusC()\n'
self.executeStr(str1, linfo)
-
+ ##print 'item counter-',itemCounter
+ #self.minusC(itemCounter)
+
+ #print 'c--po plus' , self.c
#--------------------------------------------------------------------- INIT VARS
self.notebook = wx.Notebook(self)
markgroup = [] # notebok panel marker
@@ -682,6 +749,7 @@
self.stop = False
self.max = len(linfo)
prepareStatements()
+ self.notebokDict={}
# --------------------------------------------- #START of the looop of genereator
while self.stop is False: # self.stop is managed by def plusC(self):
group = linfo[self.c].group
@@ -690,26 +758,43 @@
markgroup.append(group) # mark group
self.nbPage = MdNotebookPage(self.notebook)
self.notebook.AddPage(self.nbPage, linfo[self.c].group)
-
+ self.notebokDict[linfo[self.c].group]=self.nbPage
+ else:
+ self.nbPage=self.notebokDict[linfo[self.c].group]
+
+
+
# if starting the statements
if '\t' in lstruct[self.c]and self.stop is False:
+ #print '-'*50
inBlock()
-
+ #print '-'*50
# if just singe item without statements
elif 'for' not in str(lstruct[self.c]).split() and 'if' not in str(lstruct[self.c]).split():
+ #print '-'*50
- self.cTmp = self.c
it = MdItem(self.nbPage, linfo[self.c])
+ ##print 'hodnota--', linfo[self.c].tag
value = 'self.' + \
str(self.mdOWSTagStrList[self.c]).replace('\n', '')
+ ##print value
+
it.setValue(eval(value))
self.mdDescription[self.c].addMdItem(it)
self.nbPage.addItem(it)
self.plusC()
+ #print '-'*50
else:
self.plusC()
+
+
+
+
self.md = MD_Metadata()
+
+
+
#----------------------------------------------------------- GUI GENERATOR END
#------------------------------------------------------------------------ LAYOUT
@@ -723,20 +808,20 @@
self.Show()
#=========================================================================
- # def printmd(self):
+ # def #printmd(self):
# for item in self.mdDescription:
- # print item.tag
- # print item.name
- # print item.mdItem
- # print '-----'
+ # #print item.tag
+ # #print item.name
+ # #print item.mdItem
+ # #print '-----'
#=========================================================================
def executeStr1(self, stri, item):
- print stri
+ #print stri
exec stri
def exportToXml(self, jinjaPath, outPath, xmlOutName):
- print '=' * 50
+ #print '=' * 50
self.createNewMD()
self.mdo.saveToXML(self.md, jinjaPath, outPath, xmlOutName)
@@ -804,7 +889,7 @@
'''
str1 = ''
for wxCtrl in mdDes[self.c].mdItem:
- print "item"
+ #print "item"
if wxCtrl.getValue() is not None:
str1 += 'self.' + \
mdDes[self.c].tag + '="' + str(wxCtrl.getValue()) + '"\n'
@@ -837,20 +922,18 @@
# how many MdItem() is in object
leng = len(mdDes[self.c].mdItem)
# (2.1) IF NECESSARY TO INITIALIZE OWSLIB OBJECT
+
if mdDes[cTmp].object and 'if' not in mdDes[cTmp].tag.split():
- print 'init'
+ #print 'init owslib'
# self.val=CI_ResponsibleParty()
objStr = 'self.val=' + mdDes[cTmp].object + '\n'
-
+ ##print 'c--po',self.c
for n in range(leng):
numOfItems = 0
str1 += objStr
- # print self.c, 'pred'
+ # #print self.c, 'pred'
while mdDes[self.c].statements == stat and self.stop is False:
- # print 'c',self.c
- # if len(mdDes[self.c].mdItem)>leng:
- #moreLoop = len(mdDes[self.c].mdItem) - leng
- # mark
+
metadata = re.split(r'[.]', mdDes[self.c].tag)
metadata[0] = 'self.val.'
str1 += ''.join(metadata) + "='"\
@@ -862,16 +945,21 @@
self.executeStr1(str1, False)
str1 = ''
self.minusC(numOfItems)
- # print self.c, 'po'
- self.plusC(leng)
-
+
+ ##print numOfItems
+ #===============================================================
+ # if leng==1:
+ # leng=2
+ #===============================================================
+ self.plusC(numOfItems)
+ ##print 'c--po',self.c
# (2.2)
elif 'for' in mdDes[cTmp].tag.split() and mdDes[cTmp].object is None and ' zip(' in mdDes[cTmp].tag:
- print 'no init and py ZIP'
+ #print 'no init and py ZIP'
leng = len(mdDes[self.c].mdItem)
tag1 = self.jinj._findBetween(tag1, 'zip(', ')').split(',')
- # print tag1
+ # #print tag1
for n in range(leng):
numOfItems = 0
@@ -883,12 +971,13 @@
self.executeStr1(str1, False)
str1 = ''
self.minusC(numOfItems)
- # print numOfItems
- self.plusC(leng)
+ # #print numOfItems
+ self.plusC(numOfItems)
elif 'for' in mdDes[cTmp].tag.split() and mdDes[cTmp].object is None:
- print 'no init'
+ #print 'no init'
leng = len(mdDes[self.c].mdItem)
+ numOfItems = 0
for n in range(leng):
numOfItems = 0
while mdDes[self.c].statements == stat and self.stop is False:
@@ -899,10 +988,10 @@
self.executeStr1(str1, False)
str1 = ''
self.minusC(numOfItems)
- self.plusC(leng)
+ self.plusC(numOfItems)
# (1)
elif 'if' in mdDes[cTmp].tag.split():
- print 'no init IF'
+ #print 'no init IF'
objStr = mdDes[cTmp].tag.replace(' md.', ' self.md.') + ':\n'
for n in range(leng):
@@ -919,7 +1008,7 @@
self.minusC(numOfItems)
self.executeStr1(str1, False)
str1 = ''
- self.plusC(leng)
+ self.plusC(numOfItems)
def in2Statements():
'''possible combinations of statements
@@ -942,9 +1031,7 @@
cTmp1 = self.c + 1
tag = str(mdDes[cTmp].tag).split()
tag1 = str(mdDes[cTmp1].tag).split()
- print '-'
- print tag
- print tag1
+
stat = mdDes[self.c + 2].statements
append = 'self.' + str(tag1[-1]) + '.append(self.val)\n'
@@ -952,12 +1039,12 @@
# (1)
# if 'if' in jinja=skip and do single loop
if 'if' in tag and 'for' in tag1:
- print 'iffor'
+ #print 'iffor'
leng = len(mdDes[self.c + 2].mdItem)
- print mdDes[self.c + 2].tag
+ ##print mdDes[self.c + 2].tag
# (1.1)
if mdDes[cTmp1].object:
- print "if and for with init object"
+ #print "if and for with init object"
condition = mdDes[cTmp].tag.replace(
' md.',
' self.md.') + ':\n'
@@ -983,12 +1070,13 @@
self.executeStr1(str1, False)
str1 = ''
self.minusC(numOfItems)
- self.plusC(leng)
+ self.plusC(numOfItems)
# (1.2)
else:
- print "if and for "
+ #print "if and for "
self.plusC()
self.plusC()
+ numOfItems = 0
size = len(mdDes[self.c].mdItem)
for n in range(size):
numOfItems = 0
@@ -1002,10 +1090,10 @@
self.executeStr1(str1, False)
self.minusC(numOfItems)
- self.plusC(size) # #TODO TEST -1
+ self.plusC(numOfItems) # #TODO TEST -1
# (2) only keywords (dict)
elif 'for' in tag and 'for' in tag1: #
- print 'for-for statement'
+ #print 'for-for statement'
self.plusC() # skip staementes 2x
self.plusC()
@@ -1019,29 +1107,24 @@
kw = {}
kw['keywords'] = []
- print mdDes[self.c].mdItem[n]
- print '---'
+ ##print mdDes[self.c].mdItem[n]
+ ##print '---'
for k in range(len(mdDes[self.c].mdItem[n])):
kw['keywords'].append(
- '"' +
- mdDes[
- self.c].mdItem[n][k].getValue() +
- '"')
- print mdDes[self.c].mdItem[n][k].getValue()
+ mdDes[
+ self.c].mdItem[n][k].getValue() )
+ ##print mdDes[self.c].mdItem[n][k].getValue()
kw['type'] = None
kw['thesaurus'] = {}
- kw['thesaurus']['title'] = '"' + \
- mdDes[self.c + 1].mdItem[n].getValue() + '"'
- # print mdDes[self.c+1].mdItem[n].getValue()
- kw['thesaurus']['date'] = '"' + \
- mdDes[self.c + 2].mdItem[n].getValue() + '"'
- # print mdDes[self.c+2].mdItem[n].getValue()
- kw['thesaurus']['datetype'] = '"' + \
- mdDes[self.c + 3].mdItem[n].getValue() + '"'
- # print mdDes[self.c+3].mdItem[n].getValue()
+ kw['thesaurus']['title'] = mdDes[self.c + 1].mdItem[n].getValue()
+ # #print mdDes[self.c+1].mdItem[n].getValue()
+ kw['thesaurus']['date'] = mdDes[self.c + 2].mdItem[n].getValue()
+ # #print mdDes[self.c+2].mdItem[n].getValue()
+ kw['thesaurus']['datetype'] = mdDes[self.c + 3].mdItem[n].getValue()
+ # #print mdDes[self.c+3].mdItem[n].getValue()
self.md.identification.keywords.append(kw)
- # print '---'
+ # #print '---'
self.plusC()
self.plusC()
@@ -1051,7 +1134,7 @@
self.mdo = MdFileWork()
# TODO define this in flat file
self.md = self.mdo.initMD()
- # print self.md
+ # #print self.md
self.md.identification = MD_DataIdentification()
self.md.dataquality = DQ_DataQuality()
self.md.distribution = MD_Distribution()
@@ -1073,53 +1156,61 @@
if mdDes[self.c].statements is None\
and 'if' not in mdDes[self.c].tag.split()\
and 'for' not in mdDes[self.c].tag.split():
- print '0x statements'
- print mdDes[self.c].tag
- print mdDes[self.c].statements
- print mdDes[self.c].mdItem
+ #print '0x statements'
+ #print mdDes[self.c].tag
+ #print mdDes[self.c].statements
+ #print mdDes[self.c].mdItem
+
noneStatements()
chckEnd()
+ #print '+' * 80
+ #print 'next'
+ #print mdDes[self.c].tag
+ #print mdDes[self.c].statements
+ #print mdDes[self.c].statements1
+ #print mdDes[self.c].mdItem
+ #print '+-' * 80
# if 2x statements
elif chckIf2xStatements():
- print '-+' * 80
- print '2x statements'
- print mdDes[self.c].tag
- print mdDes[self.c].statements
- print mdDes[self.c].statements1
- print mdDes[self.c].mdItem
- print '+' * 80
+ #print '-+' * 80
+ #print '2x statements'
+ #print mdDes[self.c].tag
+ #print mdDes[self.c].statements
+ #print mdDes[self.c].statements1
+ #print mdDes[self.c].mdItem
+ #print '+' * 80
in2Statements()
chckEnd()
- print '+' * 80
- print '2x statements'
- print mdDes[self.c].tag
- print mdDes[self.c].statements
- print mdDes[self.c].statements1
- print mdDes[self.c].mdItem
- print '+-' * 80
+ #print '+' * 80
+ #print 'next'
+ #print mdDes[self.c].tag
+ #print mdDes[self.c].statements
+ #print mdDes[self.c].statements1
+ #print mdDes[self.c].mdItem
+ #print '+-' * 80
# break
elif chckIf1Statements: # if 1x statements
- print '-+' * 80
- print '1x statements'
- print mdDes[self.c].tag
- print mdDes[self.c].statements
- print mdDes[self.c].statements1
- print mdDes[self.c].mdItem
- print '+' * 80
+ #print '-+' * 80
+ #print '1x statements'
+ #print mdDes[self.c].tag
+ #print mdDes[self.c].statements
+ #print mdDes[self.c].statements1
+ #print mdDes[self.c].mdItem
+ #print '+' * 80
inStatements()
chckEnd()
- print '+' * 80
- print '1x statements'
- print mdDes[self.c].tag
- print mdDes[self.c].statements
- print mdDes[self.c].statements1
- print mdDes[self.c].mdItem
- print '+-' * 80
- # print mdDes[self.c].statements
+ #print '+' * 80
+ #print 'next'
+ #print mdDes[self.c].tag
+ #print mdDes[self.c].statements
+ #print mdDes[self.c].statements1
+ #print mdDes[self.c].mdItem
+ #print '+-' * 80
+ # #print mdDes[self.c].statements
# self.plusC()
- print '==' * 50
+ #print '==' * 50
#----------------------------------------------------------------------
Modified: sandbox/krejcmat/src/g.gui.metadata.py
===================================================================
--- sandbox/krejcmat/src/g.gui.metadata.py 2014-07-25 20:18:24 UTC (rev 61406)
+++ sandbox/krejcmat/src/g.gui.metadata.py 2014-07-25 20:48:37 UTC (rev 61407)
@@ -14,7 +14,7 @@
for details.
"""
-# from grass.pygrass.gis import Mapset
+
from lxml import etree as et
from wx.lib.splitter import MultiSplitterWindow
import wx
@@ -26,68 +26,72 @@
import glob
import os
-########################################################################
+import sys
+#===============================================================================
+# gisbase = os.environ['GISBASE'] = "/home/matt/Documents/grass_trunk/dist.x86_64-unknown-linux-gnu/"
+# gisdbase = os.path.join("/home", "grass_data")
+# location = "nc_basic_spm_grass7"
+# mapset = "user1"
+#
+# sys.path.append(os.path.join(os.environ["GISBASE"], "etc", "python"))
+# sys.path.append(os.path.join(os.environ["GISBASE"], "gui", "wxpython"))
+#===============================================================================
-class MapTree(wx.Panel):
+import grass.script as grass
+import grass.script.setup as gsetup
+from lmgr import datacatalog
+from core.gcmd import RunCommand, GError, GMessage
+import mdgrass
- def __init__(self, parent):
- wx.Panel.__init__(self, parent=parent, id=wx.ID_ANY)
+#===============================================================================
+# gsetup.init(gisbase,
+# gisdbase, location, mapset)
+#
+# from grass.pygrass.gis import Mapset
+#===============================================================================
- self.panel1 = wx.Panel(self, -1)
- self.tree = wx.TreeCtrl(
- self.panel1, 1, wx.DefaultPosition, (-1, -1), wx.TR_HIDE_ROOT | wx.TR_HAS_BUTTONS)
- self.initMaps()
- self.tree.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnSelChanged, id=1)
- self._layout()
+########################################################################
+class MapTree(datacatalog.LocationMapTree):
+
+ def __init__(self, parent):
+ """Test Tree constructor."""
+ super(MapTree, self).__init__(parent)
+ self.InitTreeItems()
+ self.map=None
+ self.mapType=None
+
+ def InitTreeItems(self):
+ """Add locations, mapsets and layers to the tree."""
+ gisenv = grass.gisenv()
+ location = gisenv['LOCATION_NAME']
+ self.mapset = gisenv['MAPSET']
+ self._initTreeItems(locations=[location],
+ mapsets=[self.mapset])
+ self.ExpandAll()
+ self.Bind(wx.EVT_TREE_SEL_CHANGED,self.onChanged)
+
+ def onChanged(self,evt=None):
+ if self.GetChildrenCount(evt.Item)==0:
+ self.map = self.GetItemText(evt.Item)+ '@'+self.mapset
+ self.mapType=self.GetItemParent(evt.Item)
+ self.mapType=self.GetItemText(self.mapType)
+ if self.mapType =='vect':
+ self.mapType='vector'
+ elif self.mapType == 'rast':
+ self.mapType='cell'
+ else:
+ GMessage('Please select map.')
- def _layout(self):
- hbox = wx.BoxSizer(wx.HORIZONTAL)
- vbox = wx.BoxSizer(wx.VERTICAL)
- vbox.Add(self.tree, 1, wx.EXPAND)
- hbox.Add(self.panel1, 1, wx.EXPAND)
- self.panel1.SetSizer(vbox)
- self.SetSizer(hbox)
- self.Centre()
+ def _popupMenuLayer(self):
+ """Create popup menu for layers"""
+ pass
- def OnSelChanged(self, event):
- item = event.GetItem()
- self.display.SetLabel(self.tree.GetItemText(item))
+ def _popupMenuMapset(self):
+ """Create popup menu for mapsets"""
+ pass
- def initMaps(self):
- #-------------------------------------- root = self.tree.AddRoot('Maps')
- #--------------------------- rast = self.tree.AppendItem(root, 'raster')
- #--------------------------- vect = self.tree.AppendItem(root, 'vector')
- #----------------------------- rast3d = self.tree.AppendItem(root, 'r3')
- #----------------------------------------------------------------------
- #----------------------------------------------------- mapset = Mapset()
- #---------------------------------------- rast_maps=mapset.glist('rast')
- #------------------------------------------------ for rmap in rast_maps:
- #---------------------------------- self.tree.AppendItem(rast, rmap)
- #----------------------------------------------------------------------
- #---------------------------------------- vect_maps=mapset.glist('vect')
- #------------------------------------------------ for vmap in vect_maps:
- #---------------------------------- self.tree.AppendItem(vect, vmap)
-
- self.tree = wx.TreeCtrl(
- self.panel1,
- wx.TR_HIDE_ROOT | wx.TR_HAS_BUTTONS)
- root = self.tree.AddRoot('maps')
- os = self.tree.AppendItem(root, 'raster')
- self.tree.AppendItem(os, 'DTM_01')
- self.tree.AppendItem(os, 'random')
- self.tree.AppendItem(os, 'jezera')
-
- os1 = self.tree.AppendItem(root, 'vector')
- self.tree.AppendItem(os1, 'silnice')
- self.tree.AppendItem(os1, 'reky')
- self.tree.AppendItem(os1, 'lesy')
-
- self.tree.Bind(wx.EVT_TREE_SEL_CHANGED, self.OnSelChanged, id=1)
- self.display = wx.StaticText(self, style=wx.ALIGN_CENTRE)
-
-
class Html(wx.Panel):
def __init__(self, parent):
@@ -109,7 +113,7 @@
parent=parent,
id=wx.ID_ANY,
style=wx.TR_HAS_BUTTONS)
- # self.SetMinSize(500,500)
+
self.parent = parent
self.fpath = xmlPath
self.xml = et.parse(self.fpath)
@@ -152,7 +156,7 @@
# def OnEdit(self, evt):
# elm = self.GetPyData(evt.Item)
#
- # print evt.Label
+ # #print evt.Label
# if elm is not None:
# elm.text = evt.Label
# self.xml.write(self.fpath, encoding="UTF-8", xml_declaration=True)
@@ -170,54 +174,40 @@
else:
self.CollapseAllChildren(evt.Item)
- #------------------------------------------------------- def printLog(self):
- #------------------------------------------------------------ print self
- #-------------------------------------------------------- if self.error:
- #------------------------------------------ print(self.error.column)
- #------------------------------------------ print(self.error.domain)
- #------------------------------------- print(self.error.domain_name)
-#------------------------------------------------------------------------------
- #---------------------------------------- print(self.error.filename)
- #------------------------------------------- print(self.error.level)
- #-------------------------------------- print(self.error.level_name)
- #-------------------------------------------- print(self.error.line)
-#------------------------------------------------------------------------------
- #----------------------------------------- print(self.error.message)
- #-------------------------------------------- print(self.error.type)
- #--------------------------------------- print(self.error.type_name)
- #-------------------------------------------- print(self.error.line)
-#------------------------------------------------------------------------------
- #------------------------------------------------------- def validate(self):
- #------------------------------------------- self.xsd.validate(self.xml)
- #----------------------------------------- self.log = self.xsd.error_log
- #-------------------------------------- self.error = self.log.last_error
- #------------------------------------------------------- self.printLog()
-
-
class Toolbar(wx.Panel):
def __init__(self, parent):
- wx.Panel.__init__(self, parent)
+ wx.Panel.__init__(self, parent,id=wx.ID_ANY)
self.jinjaFile = None
-
+ self.xmlPath=None
self.toolbar = wx.ToolBar(self, 1, wx.DefaultPosition, (-1, -1),)
self.toolbar.AddSeparator()
-
+#----------------------------------------------------------------- OPEN TEMPLATE
bitmapLoad = wx.Image(
os.path.join(os.environ['GISBASE'], 'gui', 'icons', 'grass', 'open.png'),
wx.BITMAP_TYPE_PNG).ConvertToBitmap()
self.bttLoad = BitmapBtnTxt(
self.toolbar, -1, bitmapLoad, "template", size=(100, -1))
self.toolbar.AddControl(control=self.bttLoad)
-
+ self.bttLoad.Disable()
self.toolbar.AddSeparator()
-
+#---------------------------------------------------------------------- OPEN XML
+ bitmapLoadXml =wx.Image(
+ os.path.join(os.environ['GISBASE'], 'gui', 'icons', 'grass', 'open.png'),
+ wx.BITMAP_TYPE_PNG).ConvertToBitmap()
+ self.bttLoadXml = BitmapBtnTxt(
+ self.toolbar, -1, bitmapLoad, "XML", size=(100, -1))
+ self.toolbar.AddControl(control=self.bttLoadXml)
+ self.bttLoadXml.Disable()
+ #self.toolbar.AddSeparator()
+
+#-------------------------------------------------------------------------- SAVE
bitmapSave = wx.Image(
os.path.join(os.environ['GISBASE'], 'gui', 'icons', 'grass', 'save.png'),
wx.BITMAP_TYPE_PNG).ConvertToBitmap()
self.bttsave = BitmapBtnTxt(
- self.toolbar, -1, bitmapSave, "export", size=(100, -1))
+ self.toolbar, -1, bitmapSave, "XML", size=(100, -1))
self.bttsave.Disable()
self.toolbar.AddControl(control=self.bttsave)
@@ -228,7 +218,31 @@
self.bttLoad.Bind(wx.EVT_BUTTON, self.OnOpenTemplate)
self.bttsave.Bind(wx.EVT_BUTTON, self.onSaveXML)
-
+ self.bttLoadXml.Bind(wx.EVT_BUTTON, self.onLoadXml)
+
+ def forteseting(self,evt=None):
+ self.xmlPath = '/home/matt/Dropbox/gsoc/gsoc2014-krejci/src/metadata/series.xml'
+ self.jinjaFile ='/home/matt/Dropbox/gsoc/gsoc2014-krejci/src/templates/grassInspireTemplateFinal.xml'
+
+ self.onChangeXml()
+ self.onChangeTemplate()
+
+ def onLoadXml(self,evt=None):
+ dlg = wx.FileDialog(
+ self,
+ "Choose a xml metadata file",
+ os.getcwd(),
+ "",
+ "*.xml",
+ wx.OPEN)
+ if dlg.ShowModal() == wx.ID_OK:
+ self.xmlPath = dlg.GetPath()
+ self.onChangeXml()
+ dlg.Destroy()
+
+ else:
+ dlg.Destroy()
+
def onSaveXML(self, evt=None):
dlg = wx.FileDialog(
self,
@@ -237,14 +251,20 @@
"",
"*.xml",
wx.SAVE)
- # if dlg.ShowModal() == wx.ID_OK:
- self.GetParent().jinjaPath
- self.GetParent().editor.exportToXml(
- self.jinjaFile,
- outPath=None,
- xmlOutName=None)
-
- def onChangeTemplate(self, evt):
+ if dlg.ShowModal() == wx.ID_OK:
+ if self.jinjaFile is None:
+ self.jinjaFile=self.GetParent().jinjaPath
+
+ self.GetParent().editor.exportToXml(
+ self.jinjaFile,
+ outPath=dlg.GetDirectory(),
+ xmlOutName=dlg.GetFilename())
+
+ def onChangeXml(self,evt=None):
+ self.GetParent().xmlPath = self.xmlPath
+ self.GetParent().refreshConfig()
+
+ def onChangeTemplate(self, evt=None):
self.GetParent().jinjaPath = self.jinjaFile
self.GetParent().refreshConfig()
@@ -342,7 +362,7 @@
self.GetParent().GetParent().editor.createNewMD()
md = self.GetParent().GetParent().editor.md
- print md
+ ##print md
self.validator.validate_inspire(md)
def _layout(self, path):
@@ -372,60 +392,173 @@
# infoText=wx.StaticText(self, id=wx.ID_ANY, label='Select ISO template with using toolbar(upper) and map in catalog browser(left)')
# self.mainSizer.Add(infoText, proportion=1, flag=wx.EXPAND)
#=========================================================================
+class MdEditTypePanel(wx.Panel):
+
+ def __init__(self, parent):
+ wx.Panel.__init__(self, parent,id=wx.ID_ANY)
+
+ self.mapGrassEdit=True
+ self.rbGrass = wx.RadioButton(self, id=wx.ID_ANY, label='Metadata map editor', style=wx.RB_GROUP)
+ self.rbExternal = wx.RadioButton(self, id=wx.ID_ANY, label='Metadata external editor')
+ self.comboBoxProfile=wx.ComboBox(self,choices=['INSPIRE','GRASS BASIC','Load Custom'])
+ self.comboBoxProfile.SetStringSelection('GRASS BASIC')
+ self.buttEdit=wx.Button(self,id=wx.ID_ANY,label='Edit')
+
+
+ self.buttEdit.Bind(wx.EVT_BUTTON,self.onClickEdit)
+ self.Bind(wx.EVT_RADIOBUTTON, self.onSetRadioType, id=self.rbGrass.GetId())
+ self.Bind(wx.EVT_RADIOBUTTON, self.onSetRadioType, id=self.rbExternal.GetId())
+ #self.SetVal(True)
+ self._layout()
+
+ def SetVal(self, event):
+ state1 = str()
+ state2 = str(self.rb2.GetValue())
+
+ self.statusbar.SetStatusText(state1,0)
+ self.statusbar.SetStatusText(state2,1)
+
+ def onSetRadioType(self,evt=None):
+ self.mapGrassEdit=self.rbGrass.GetValue()
+ if self.mapGrassEdit==False:
+ self.comboBoxProfile.Hide()
+ self.buttEdit.Hide()
+ else:
+ self.comboBoxProfile.Show()
+ self.buttEdit.Show()
+ self.GetParent().GetParent().GetParent().editingType(self.mapGrassEdit)
+
+ #print parent
+
+ def onClickEdit(self,evt=None):
+ self.templeteChoice=self.comboBoxProfile.GetValue()
+ self.GetParent().GetParent().GetParent().editMapMetadata(self.templeteChoice)
+ self.buttEdit.Disable()
+ self.rbGrass.Disable()
+ self.rbExternal.Disable()
+ self.comboBoxProfile.Disable()
+
+ def _layout(self):
+ self.mainsizer = wx.BoxSizer(wx.VERTICAL)
+ self.SetSizer(self.mainsizer)
+ self.mainsizer.Add(self.rbGrass)
+ self.mainsizer.Add(self.rbExternal)
+ self.mainsizer.Add(self.comboBoxProfile)
+ self.mainsizer.Add(self.buttEdit)
+
+
class MainFrame(wx.Frame):
def __init__(self, jinjaPath=None, xmlPath=None, pos=None):
"""Constructor"""
wx.Frame.__init__(self, None, title="Metadata Editor",
- size=(1000, 1200), pos=pos)
+ size=(600, 800), pos=pos)
# self.template
self.jinjaPath = jinjaPath
self.xmlPath = xmlPath
self.init()
-
+ #=======================================================================
+ # if templeteChoice is not None:
+ # #print '***'*50
+ # #print 'haskjak'
+ # self.jinjaPath=None
+ # self.editMapMetadata(templeteChoice)
+ #=======================================================================
+
def refreshConfig(self):
- self.xmlPath = 'INStest.xml'
- print self.jinjaPath, '\n', self.xmlPath
-
+ #print '***'*50
+ #print self.jinjaPath
+ #print self.xmlPath
+
+ #self.xmlPath=os.path.basename(self.xmlPath)
+ #print '***'*50
if self.jinjaPath and self.xmlPath:
- self.editor = mainEditor(
- self.splitter,
- self.jinjaPath,
- self.xmlPath)
+ self.editor = mainEditor(self.splitter,self.jinjaPath,self.xmlPath)
+
self.splitter.AppendWindow(self.editor)
- self.splitter.AppendWindow(
- NotebookRight(
- self.splitter,
- self.xmlPath))
-
+ self.splitter.AppendWindow(NotebookRight(self.splitter,self.xmlPath))
+ self.toolbar.bttsave.Enable()
self.Show()
+
+
+ def editMapMetadata(self,templeteChoice):
+
+ if self.jinjaPath is None:
+ self.mapTreePanelLeft.Hide()
+ map=self.mapTreePanelLeft.map
+ maptype=self.mapTreePanelLeft.mapType
+
+ if map is not None:
+ mdCreator=mdgrass.GrassMD(map,maptype)
+
+ if templeteChoice=='INSPIRE':
+ mdCreator.createGrassInspireISO()
+ self.jinjaPath=mdCreator.templatePathAbs
+ self.xmlPath = mdCreator.saveXML()
+ self.refreshConfig()
+
+ elif templeteChoice=='GRASS BASIC':
+ mdCreator.createGrassBasicISO()
+ self.jinjaPath=mdCreator.templatePathAbs
+ self.xmlPath = mdCreator.saveXML()
+ self.refreshConfig()
+
+ elif templeteChoice=='Load Custom':
+ dlg = wx.FileDialog(
+ self,
+ "Choose a file",
+ os.getcwd(),
+ "",
+ "*.xml",
+ wx.OPEN)
+ if dlg.ShowModal() == wx.ID_OK:
+ mdCreator.createGrassInspireISO()
+ self.jinjaPath = dlg.GetPath()
+ self.xmlPath = mdCreator.saveXML()
+ self.refreshConfig()
+ else:
+ x, y = self.GetSize()
+ MainFrame(self.jinjaPath, None, (x, y))
+ self.Close(True)
+ self.DestroyChildren()
+
+ def editingType(self,editStatus):
+
+ if editStatus:
+ self.mapTreePanelLeft.Show()
+ self.toolbar.bttLoad.Disable()
+ self.toolbar.bttLoadXml.Disable()
+
+ else:
+ self.mapTreePanelLeft.Hide()
+ self.toolbar.bttLoad.Enable()
+ self.toolbar.bttLoadXml.Enable()
+
def init(self):
self.toolbar = Toolbar(self)
self.splitter = MultiSplitterWindow(
self,
style=wx.SP_3D | wx.SP_LIVE_UPDATE)
+
+ self.leftPanel=wx.Panel(self.splitter,id=wx.ID_ANY)
+ self.typePanelLeft=MdEditTypePanel(self.leftPanel)
+ self.mapTreePanelLeft=MapTree(self.leftPanel)
+
+ self.splitter.AppendWindow(self.leftPanel)
- self.splitter.AppendWindow(MapTree(self.splitter))
-
if self.jinjaPath and self.xmlPath:
self.editor = mainEditor(
self.splitter,
self.jinjaPath,
self.xmlPath)
+
self.splitter.AppendWindow(self.editor)
- self.splitter.AppendWindow(
- NotebookRight(
- self.splitter,
- self.xmlPath))
- # else:
- # tmpPan=tempPanel(self.splitter)
- # self.splitter.AppendWindow(tmpPan)
- # self.splitter.AppendWindow(NotebookRight(self.splitter,None))
+ self.splitter.AppendWindow(NotebookRight(self.splitter,self.xmlPath))
self._layout()
self.Show()
@@ -434,6 +567,11 @@
self.mainSizer = wx.BoxSizer(wx.VERTICAL)
self.SetSizer(self.mainSizer)
+ self.leftPanelSizer=wx.BoxSizer(wx.VERTICAL)
+ self.leftPanel.SetSizer(self.leftPanelSizer)
+ self.leftPanelSizer.Add(self.typePanelLeft, proportion=0.2, flag=wx.EXPAND)
+ self.leftPanelSizer.Add(self.mapTreePanelLeft, proportion=1, flag=wx.EXPAND)
+
self.mainSizer.Add(self.toolbar)
self.mainSizer.Add(
wx.StaticLine(self, -1, style=wx.LI_HORIZONTAL, size=(10000, 5)))
@@ -468,7 +606,7 @@
result["num_of_errors"] = "0"
errors = 0
- if self.md.identification is None:
+ if self.md.identification is (None or ''):
result["errors"].append(
"gself.md:CI_ResponsibleParty: Organization missing")
result["errors"].append(
@@ -507,7 +645,7 @@
result["errors"].append("gself.md:otherConstraints is missing")
errors += 20
else:
- if self.md.identification.contact is None or len(
+ if self.md.identification.contact is (None or '') or len(
self.md.identification.contact) < 1:
result["errors"].append(
"gself.md:CI_ResponsibleParty: Organization missing")
@@ -517,48 +655,52 @@
"gself.md:CI_ResponsibleParty: Role missing")
errors += 3
else:
- if self.md.identification.contact[0].organization is None:
+ if self.md.identification.contact[0].organization is (None or '') :
result["errors"].append(
"gself.md:CI_ResponsibleParty: Organization missing")
errors += 1
- if self.md.identification.contact[0].email is None:
+ if self.md.identification.contact[0].email is (None or ''):
result["errors"].append(
"gself.md:CI_ResponsibleParty: E-mail missing")
errors += 1
- if self.md.identification.contact[0].role is None:
+ if self.md.identification.contact[0].role is (None or ''):
result["errors"].append(
"gself.md:CI_ResponsibleParty: Role missing")
errors += 1
- if self.md.identification.title is None:
+ if self.md.identification.title is (None or ''):
result["errors"].append(
"gself.md:self.md_DataIdentification: Title is missing")
errors += 1
- if self.md.identification.abstract is None:
+ if self.md.identification.abstract is (None or ''):
result["errors"].append(
"gself.md:self.md_DataIdentification: Abstract is missing")
errors += 1
- if self.md.identification.identtype is None:
+ if self.md.identification.identtype is (None or ''):
result["errors"].append(
"gself.md:self.md_ScopeCode: Resource Type is missing")
errors += 1
- if self.md.identification.resourcelanguage is None or len(
- self.md.identification.resourcelanguage) < 1:
+ if self.md.identification.resourcelanguage is (None or '') or len(
+ self.md.identification.resourcelanguage) < 1 or\
+ self.md.identification.resourcelanguage[0]=='':
result["errors"].append(
"gself.md:language: Resource Language is missing")
errors += 1
- if self.md.identification.uricode is None or len(
- self.md.identification.uricode) < 1:
+ if self.md.identification.uricode is (None or '') or len(
+ self.md.identification.uricode) < 1 or\
+ self.md.identification.uricode[0]=='':
result["errors"].append(
"gself.md:RS_Identifier: Unique Resource Identifier is missing")
errors += 1
- if self.md.identification.topiccategory is None or len(
- self.md.identification.topiccategory) < 1:
+ if self.md.identification.topiccategory is (None or '') or len(
+ self.md.identification.topiccategory) < 1 or\
+ self.md.identification.topiccategory[0]=='':
result["errors"].append(
"gself.md:topicCategory: TopicCategory is missing")
errors += 1
- if self.md.identification.keywords is None or len(
- self.md.identification.keywords) < 1:
+ if self.md.identification.keywords is (None or '') or len(
+ self.md.identification.keywords) < 1 or\
+ self.md.identification.keywords[0]=='':
result["errors"].append(
"gself.md:self.md_Keywords: Keywords are missing")
result["errors"].append(
@@ -569,12 +711,12 @@
"gself.md:thesaurusName: Thesaurus Date Type is missing")
errors += 4
else:
- if self.md.identification.keywords[0]['keywords'] is None or len(
- self.md.identification.keywords[0]['keywords']) < 1:
+ if self.md.identification.keywords[0]['keywords'] is (None or '') or len(
+ self.md.identification.keywords[0]['keywords']) < 1 :
result["errors"].append(
"gself.md:self.md_Keywords: Keywords are missing")
errors += 1
- if self.md.identification.keywords[0]['thesaurus'] is None:
+ if self.md.identification.keywords[0]['thesaurus'] is (None or ''):
result["errors"].append(
"gself.md:thesaurusName: Thesaurus Title is missing")
result["errors"].append(
@@ -584,77 +726,82 @@
errors += 3
else:
if self.md.identification.keywords[
- 0]['thesaurus']['title'] is None:
+ 0]['thesaurus']['title'] is (None or ''):
result["errors"].append(
"gself.md:thesaurusName: Thesaurus Title is missing")
errors += 1
if self.md.identification.keywords[
- 0]['thesaurus']['date'] is None:
+ 0]['thesaurus']['date'] is (None or ''):
result["errors"].append(
"gself.md:thesaurusName: Thesaurus Date is missing")
errors += 1
if self.md.identification.keywords[0][
- 'thesaurus']['datetype'] is None:
+ 'thesaurus']['datetype'] is (None or ''):
result["errors"].append(
"gself.md:thesaurusName: Thesaurus Date Type is missing")
errors += 1
- if self.md.identification.extent is None:
+ if self.md.identification.extent is (None or '') :
result["errors"].append(
"gself.md:EX_Extent: extent element is missing")
errors += 1
else:
- if self.md.identification.extent.boundingBox is None:
+ if self.md.identification.extent.boundingBox is (None or ''):
result["errors"].append(
"gself.md:EX_GeographicBoundingBox: bbox is missing")
errors += 1
else:
- if self.md.identification.extent.boundingBox.minx is None:
+ if self.md.identification.extent.boundingBox.minx is (None or ''):
result["errors"].append(
"gself.md:westBoundLongitude: minx is missing")
errors += 1
- if self.md.identification.extent.boundingBox.maxx is None:
+ if self.md.identification.extent.boundingBox.maxx is (None or ''):
result["errors"].append(
"gself.md:eastBoundLongitude: maxx is missing")
errors += 1
- if self.md.identification.extent.boundingBox.miny is None:
+ if self.md.identification.extent.boundingBox.miny is (None or ''):
result["errors"].append(
"gself.md:southBoundLatitude: miny is missing")
errors += 1
- if self.md.identification.extent.boundingBox.maxy is None:
+ if self.md.identification.extent.boundingBox.maxy is (None or ''):
result["errors"].append(
"gself.md:northBoundLatitude: maxy is missing")
errors += 1
+
if len(
self.md.identification.date) < 1 and (
- self.md.identification.temporalextent_start is None or self.md.identification.temporalextent_end is None):
+ self.md.identification.temporalextent_start is (None or '') or self.md.identification.temporalextent_end is (None or '')):
result["errors"].append(
"Both gself.md:EX_TemporalExtent and gself.md:CI_Date are missing")
errors += 1
- if len(self.md.identification.uselimitation) < 1:
+
+ if len(self.md.identification.uselimitation) < 1 or\
+ self.md.identification.uselimitation[0]=='':
result["errors"].append(
"gself.md:useLimitation is missing")
errors += 1
- if len(self.md.identification.accessconstraints) < 1:
+ if len(self.md.identification.accessconstraints) < 1 or\
+ self.md.identification.accessconstraints[0]=='':
result["errors"].append(
"gself.md:accessConstraints is missing")
errors += 1
- if len(self.md.identification.otherconstraints) < 1:
+ if len(self.md.identification.otherconstraints) < 1 or\
+ self.md.identification.otherconstraints[0]=='':
result["errors"].append(
"gself.md:otherConstraints is missing")
errors += 1
- if self.md.languagecode is None:
+ if self.md.languagecode is (None or ''):
result["errors"].append(
"gself.md:LanguageCode: Language code missing")
errors += 1
- if self.md.datestamp is None:
+ if self.md.datestamp is (None or ''):
result["errors"].append("gself.md:dateStamp: Date is missing")
errors += 1
- if self.md.identifier is None:
+ if self.md.identifier is (None or ''):
result["errors"].append(
"gself.md:identifier: Identifier is missing")
errors += 1
- if self.md.dataquality is None:
+ if self.md.dataquality is (None or ''):
result["errors"].append("gself.md:LI_Lineage is missing")
result["errors"].append(
"gself.md:DQ_ConformanceResult: date is missing")
@@ -665,37 +812,40 @@
"gself.md:DQ_ConformanceResult: title is missing")
errors += 4
else:
- if self.md.dataquality.lineage is None:
+ if self.md.dataquality.lineage is (None or ''):
result["errors"].append("gself.md:LI_Lineage is missing")
errors += 1
- if len(self.md.dataquality.conformancedate) < 1:
+ if len(self.md.dataquality.conformancedate) < 1 or \
+ self.md.dataquality.conformancedate[0]=='':
result["errors"].append(
"gself.md:DQ_ConformanceResult: date is missing")
errors += 1
- if len(self.md.dataquality.conformancedatetype) < 1:
+ if len(self.md.dataquality.conformancedatetype) < 1 or\
+ self.md.dataquality.conformancedatetype[0]=='' :
result["errors"].append(
"gself.md:DQ_ConformanceResult: date type is missing")
errors += 1
# if len(self.md.dataquality.conformancedegree) < 1:
# result["errors"].append("gself.md:DQ_ConformanceResult: degree is missing")
# errors += 1
- if len(self.md.dataquality.conformancetitle) < 1:
+ if len(self.md.dataquality.conformancetitle) < 1 or\
+ self.md.dataquality.conformancetitle[0]=='':
result["errors"].append(
"gself.md:DQ_ConformanceResult: title is missing")
errors += 1
- if self.md.contact is None:
+ if self.md.contact is (None or ''):
result["errors"].append(
"gself.md:contact: Organization name is missing")
result["errors"].append("gself.md:contact: e-mail is missing")
errors += 2
else:
- if self.md.contact[0].organization is None:
+ if self.md.contact[0].organization is (None or ''):
result["errors"].append(
"gself.md:contact: Organization name is missing")
errors += 1
- if self.md.contact[0].email is None:
+ if self.md.contact[0].email is (None or ''):
result["errors"].append(
"gself.md:contact: e-mail is missing")
errors += 1
@@ -703,9 +853,9 @@
if errors > 0:
result["status"] = "failed"
result["num_of_errors"] = str(errors)
- print result
-
- str1 = 'Status of validation: ' + result["status"] + '\n'
+ #print result
+ str1 = 'INSPIRE VALIDATOR'
+ str1 += 'Status of validation: ' + result["status"] + '\n'
str1 += 'Numbers of errors: ' + result["num_of_errors"] + '\n'
if result["status"] != 'succeded':
Modified: sandbox/krejcmat/src/jinjainfo.py
===================================================================
--- sandbox/krejcmat/src/jinjainfo.py 2014-07-25 20:18:24 UTC (rev 61406)
+++ sandbox/krejcmat/src/jinjainfo.py 2014-07-25 20:48:37 UTC (rev 61407)
@@ -22,9 +22,9 @@
class MdDescription():
- def __init__(self, tag=None, object=None, name=None, desc=None,
+ def __init__(self, tag=None, object=None, name='', desc=None,
example=None, type=None, multi=0, inboxmulti=None, group=None,
- inbox=None, multiline=None, validator=None, num=None):
+ inbox=None, multiline=None, validator=None, num=None, ref=None):
# ++info from jinja start
self.tag = tag
self.object = object
@@ -35,6 +35,7 @@
self.multiplicity = multi # multiplicity of MD item
self.group = group
self.inbox = inbox
+ self.ref=ref
# multiplicity in subrotoup (in static box)
self.inboxmulti = inboxmulti
self.multiline = multiline # type of ctrl text
@@ -52,25 +53,20 @@
# if new mditem is from box- need to hold information
# about it.(list on same index in self.mdItem)
- print self.mdItem, ' list'
+ #print self.mdItem, ' list'
if oldMdItem is not None:
for n, item in enumerate(self.mdItem):
- print 'here------------2'
+ #print 'here------------2'
for i in item:
if i == oldMdItem:
self.mdItem[n].append(newMdItem)
else:
self.mdItem.append(newMdItem)
- print self.tag
- print self.name
- print self.mdItem
- print '=' * 50
- print ' list', self.mdItem
def removeMdItem(self, item):
- print self.mdItem
+ #print self.mdItem
try:
for k, oldListItem in enumerate(self.mdItem):
for i in oldListItem:
@@ -78,7 +74,7 @@
self.mdItem[k].remove(item)
except:
self.mdItem.remove(item)
- print self.mdItem
+ #print self.mdItem
def addStatements(self, stat):
if self.statements is None:
@@ -110,7 +106,7 @@
box = {}
for md in self.mdDescription:
skey = 'md.' + str(akey)
- # print skey
+ ##print skey
key = eval(skey)
if key is not None:
if key not in box:
@@ -153,7 +149,8 @@
self.mdOWSTag.append(object)
except IOError as e:
- print "I/O error({0}): {1}".format(e.errno, e.strerror)
+ pass
+ #print "I/O error({0}): {1}".format(e.errno, e.strerror)
def _readJinjaInfo(self):
# template = 'data/grassBasicISOTemplate01.xml'
@@ -166,17 +163,17 @@
# if found start of comments
if str(line).find("{#") != -1:
- # print 'num' + str(counter)
+ ##print 'num' + str(counter)
values = self._findBetween(line, "{#", "#}")
values += ',num=' + str(counter)
- # print values
+ ##print values
exe_str = "self.mdDescription.append(MdDescription(%s))" % values
-
+ #print exe_str
eval(exe_str)
counter += 1
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)
+
def _findBetween(self, s, first, last):
try:
start = s.index(first) + len(first)
Modified: sandbox/krejcmat/src/mdgrass.py
===================================================================
--- sandbox/krejcmat/src/mdgrass.py 2014-07-25 20:18:24 UTC (rev 61406)
+++ sandbox/krejcmat/src/mdgrass.py 2014-07-25 20:48:37 UTC (rev 61407)
@@ -55,7 +55,7 @@
# metadata object from OWSLIB ( for define md values)
self.md = MD_Metadata(md=None)
self.template = None # path to file with xml templates
-
+
if self.type == "cell":
self.parseRast()
elif self.type == "vector":
@@ -72,8 +72,9 @@
def readXML(self, xml_file):
'''create instance of metadata(owslib) from xml file'''
+ print xml_file
self.md = MD_Metadata(etree.parse(xml_file))
-
+
def parseRast3D(self):
pass
@@ -141,23 +142,30 @@
# create abstract
if self.md_grass['description'] != '""':
- self.md_abstract = self.md_grass['description'] + '\n'
+ self.md_abstract = self.md_grass['description'] + '\\n'
if self.md_grass['source1'] != '""':
- self.md_abstract += self.md_grass['source1'] + '\n'
+ self.md_abstract += self.md_grass['source1'] + '\\n'
if self.md_grass['source2'] != '""':
- self.md_abstract += self.md_grass['source2'] + '\n'
+ self.md_abstract += self.md_grass['source2'] + '\\n'
self.md_abstract += 'Total cells: ' + self.md_grass['cells']
self.md_abstract += 'A range of values: min: ' + \
self.md_grass['min'] + ' max: ' + self.md_grass['max']
-
- def createGrassBasicISO(self):
+ self.md_abstract.translate(None, """&<>"'""")
+
+ def createGrassBasicISO(self,template=None):
'''Create basic/essential profile based on ISO
- unknown values are filling by n = '$NULL'
'''
-
+ try:
+ self.md_grass['comments']=self.md_grass['comments'].replace('\n','\\n')
+ except:
+ pass
n = '$NULL'
# jinja templates
- self.template = 'data/grassBasicISOTemplate.xml'
+ if template is None:
+ self.template = 'templates/grassGRASSTemplateFinal.xml'
+ else:
+ self.template= template
# OWSLib md object
self.md.identification = MD_DataIdentification()
@@ -240,8 +248,8 @@
val.organization = self.md_grass['creator']
val.role = 'owner'
self.md.identification.contact.append(val)
-
- def createGrassInspireISO(self):
+ self.templatePathAbs=os.path.join(self.dirpath,self.template)
+ def createGrassInspireISO(self,template=None):
'''Create valid INSPIRE profile and fill it as much as possible by GRASS metadata. Missing values is $NULL
-create basic md profile and add INSPIRE mandatory attributes
'''
@@ -250,7 +258,11 @@
# create basic profile
self.createGrassBasicISO()
- self.template = 'data/grassInspireTemplate.xml'
+
+ if template is None:
+ self.template = 'templates/grassInspireTemplateFinal.xml'
+ else:
+ self.template = template
n = '$NULL'
self.md.datestamp = n
@@ -295,7 +307,7 @@
# Temporal/Temporal Extent
self.md.identification.temporalextent_start = n
self.md.identification.temporalextent_end = n
-
+ self.templatePathAbs=os.path.join(self.dirpath,self.template)
def saveXML(self, path=None, xml_out_name=None):
''' Save custom record to ISO XML file'''
@@ -326,10 +338,11 @@
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 file')
+ #sys.exit()
return path
-
+
def validate_inspire(self):
'''function for validation INSPIRE XML file'''
Modified: sandbox/krejcmat/src/r.info.iso.py
===================================================================
--- sandbox/krejcmat/src/r.info.iso.py 2014-07-25 20:18:24 UTC (rev 61406)
+++ sandbox/krejcmat/src/r.info.iso.py 2014-07-25 20:48:37 UTC (rev 61407)
@@ -54,7 +54,7 @@
mdout = None
else:
mdout = options['mdout']
-
+ print options['map']
md = GrassMD(options['map'], 'cell')
if options['profil'] == 'inspire':
md.createGrassInspireISO()
More information about the grass-commit
mailing list