[GRASS-SVN] r66011 - grass-addons/grass7/gui/wxpython/wx.metadata/mdlib
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Aug 25 02:39:03 PDT 2015
Author: krejcmat
Date: 2015-08-25 02:39:03 -0700 (Tue, 25 Aug 2015)
New Revision: 66011
Modified:
grass-addons/grass7/gui/wxpython/wx.metadata/mdlib/cswlib.py
grass-addons/grass7/gui/wxpython/wx.metadata/mdlib/cswutil.py
grass-addons/grass7/gui/wxpython/wx.metadata/mdlib/mdeditorfactory.py
grass-addons/grass7/gui/wxpython/wx.metadata/mdlib/mdgrass.py
grass-addons/grass7/gui/wxpython/wx.metadata/mdlib/mdpdffactory.py
grass-addons/grass7/gui/wxpython/wx.metadata/mdlib/mdutil.py
Log:
wx.metadata addons: fix paths for working without addons BASE
Modified: grass-addons/grass7/gui/wxpython/wx.metadata/mdlib/cswlib.py
===================================================================
--- grass-addons/grass7/gui/wxpython/wx.metadata/mdlib/cswlib.py 2015-08-25 08:37:10 UTC (rev 66010)
+++ grass-addons/grass7/gui/wxpython/wx.metadata/mdlib/cswlib.py 2015-08-25 09:39:03 UTC (rev 66011)
@@ -17,7 +17,8 @@
sys.exit('owslib python library is missing. Check requirements on the manual page < https://grasswiki.osgeo.org/wiki/ISO/INSPIRE_Metadata_Support >')
from cswutil import *
-from mdutil import yesNo
+
+from mdutil import yesNo, StaticContext
import tempfile
import json
@@ -47,6 +48,7 @@
from grass.pygrass.modules import Module
from grass.script import parse_key_val
+
class ConstraintsBulder(wx.Panel):
def __init__(self, parent, settings=''):
wx.Panel.__init__(self, parent=parent, id=wx.ID_ANY)
@@ -101,7 +103,7 @@
sizeConst = 55
self.splitterBrowser = SplitterWindow(self, style=wx.SP_3D | wx.SP_LIVE_UPDATE | wx.SP_BORDER)
self.context=StaticContext()
- self.connectionFilePath = os.path.join(self.context.addonsPath, 'connections_resources.xml')
+ self.connectionFilePath = os.path.join(self.context.lib_path, 'connections_resources.xml')
self.pnlLeft = wx.Panel(self.splitterBrowser, id=wx.ID_ANY)
self.pnlRight = wx.Panel(self.splitterBrowser, -1)
@@ -854,7 +856,7 @@
self.connectionLBox = wx.ListBox(self.panelLeft, id=-1, pos=wx.DefaultPosition)
self.timeoutSpin = wx.SpinCtrl(self.panelLeft, min=1, max=100, initial=10 , style=wx.ALIGN_RIGHT | wx.SP_ARROW_KEYS)
self.context = StaticContext()
- self.connectionFilePath = os.path.join(self.context.addonsPath, 'connections_resources.xml')
+ self.connectionFilePath = os.path.join(self.context.lib_path, 'connections_resources.xml')
self.servicePath = 'service_metadata.html'
self.serviceInfoBtt = wx.Button(self.panelLeft, -1, label='Service info')
self.newBtt = wx.Button(self.panelLeft, label='New')
Modified: grass-addons/grass7/gui/wxpython/wx.metadata/mdlib/cswutil.py
===================================================================
--- grass-addons/grass7/gui/wxpython/wx.metadata/mdlib/cswutil.py 2015-08-25 08:37:10 UTC (rev 66010)
+++ grass-addons/grass7/gui/wxpython/wx.metadata/mdlib/cswutil.py 2015-08-25 09:39:03 UTC (rev 66011)
@@ -21,13 +21,6 @@
from pygments.lexers import XmlLexer
from pygments.formatters import HtmlFormatter
-
-class StaticContext(object):
- def __init__(self):
- self.ppath = os.path.dirname(os.path.abspath(__file__))
- self.addonsPath=os.path.join(os.getenv('GRASS_ADDON_BASE'), 'etc','wx.metadata','config')
-
-
def get_connections_from_file( filename):
"""load connections from connection file"""
Modified: grass-addons/grass7/gui/wxpython/wx.metadata/mdlib/mdeditorfactory.py
===================================================================
--- grass-addons/grass7/gui/wxpython/wx.metadata/mdlib/mdeditorfactory.py 2015-08-25 08:37:10 UTC (rev 66010)
+++ grass-addons/grass7/gui/wxpython/wx.metadata/mdlib/mdeditorfactory.py 2015-08-25 09:39:03 UTC (rev 66011)
@@ -114,7 +114,6 @@
if not xmlOutName.lower().endswith('.xml'):
xmlOutName += '.xml'
# if path is None, use lunch. dir
- # TODO change default folder to mapset location
if not outPath:
outPath = os.path.join(self.dirpath, xmlOutName)
else:
@@ -126,9 +125,12 @@
line = mdutil.removeNonAscii(line)
str1 += line
xml.close
- io = open(jinjaPath, 'w')
- io.write(str1)
- io.close()
+ try:
+ 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
# generating xml using jinja templates
head, tail = os.path.split(jinjaPath)
@@ -838,17 +840,20 @@
if not mdutil.isTableExists('metadata_themes'):
sql='create table if not exists metadata_themes (title TEXT, keyword TEXT, date_iso TEXT ,date_type TEXT)'
self.dbExecute(sql)
- p1=os.path.join(sys.path[0],'..')
titles = [['keywordConcepts.txt','GEMET - Concepts, version 2.4'],
['keywordThemes.txt','GEMET - Themes, version 2.4'],
['keywordGroups.txt','GEMET - Groups, version 2.4']]
+
+ context=mdutil.StaticContext()
+ libPath = os.path.join(context.lib_path,'config')
+
for title in titles:
- path = os.path.join(p1, 'config', title[0])
+ path = os.path.join(libPath,title[0])
str=''
with open(path, "r") as inp :
exec(inp.read())
- for item in keywords:#!!! from exec, no mistake
+ for item in keywords:#!!! keywords from exec, no mistake!
str+="('%s','%s','%s','%s'),"%(title[1],item['preferredLabel']['string'],'2010-01-13','publication')
str=str[:-1]
sql="INSERT INTO 'metadata_themes' ('title', 'keyword', 'date_iso' ,'date_type' ) VALUES"+str
@@ -1574,7 +1579,8 @@
self.md = self.mdo.initMD()
# most of objects from OWSLib is initialized in configure file
#dirpath = os.path.dirname(os.path.realpath(__file__))
- path = os.path.join(os.getenv('GRASS_ADDON_BASE'),'etc','wx.metadata','config','init_md.txt')
+ context=mdutil.StaticContext()
+ path = os.path.join(context.lib_path,'config','init_md.txt')
mdInitData = open(path, 'r')
mdExec = mdInitData.read()
Modified: grass-addons/grass7/gui/wxpython/wx.metadata/mdlib/mdgrass.py
===================================================================
--- grass-addons/grass7/gui/wxpython/wx.metadata/mdlib/mdgrass.py 2015-08-25 08:37:10 UTC (rev 66010)
+++ grass-addons/grass7/gui/wxpython/wx.metadata/mdlib/mdgrass.py 2015-08-25 09:39:03 UTC (rev 66011)
@@ -3,7 +3,7 @@
"""
@package mdgrass
@module v.info.iso, r.info.iso, g.gui.metadata
- at brief Base class for import(r.info,v.info) and export(r/v.support)
+ at brief Base class for import(r.info.iso,v.info) and export(r/v.support)
metadata with using OWSLib and jinja template.
Classes:
@@ -47,7 +47,6 @@
from datetime import date, datetime
from osgeo import osr
-#sys.path.insert(1, os.path.join(os.path.dirname(sys.path[0]), 'etc','wx.metadata','mdlib'))
class GrassMD():
'''
@@ -69,7 +68,8 @@
# suffix of output xml file (variables)
self.schema_type = '_basic.xml'
self.profileName='GRASS BASIC'
- self.dirpath = os.getenv('GRASS_ADDON_BASE')
+ context=mdutil.StaticContext()
+ self.dirpath = os.path.join(context.lib_path,'profiles')
# metadata object from OWSLIB ( for define md values)
self.md = mdutil.MD_MetadataMOD(md=None)
self.profilePath = None # path to file with xml templates
@@ -163,7 +163,7 @@
date = datetime.strptime(self.md_grass[key], '%a %b %d %H:%M:%S %Y')
self.md_grass['dateofcreation'] = date.strftime('%Y-%m-%d')
except:
- grass.warning('date of creation: unknown date format')
+ grass.message('date of creation: unknown date format')
self.md_grass['dateofcreation'] = self.md_grass[key]
def parseRast(self):
@@ -229,7 +229,7 @@
int(srs.GetAuthorityCode(None))
return srs.GetAuthorityCode(None)
except:
- grass.warning('Epsg code cannot be identified')
+ grass.message('Attemp of identifiyng EPSG is not successful')
return None
def createTemporalISO(self, profile=None):
@@ -239,7 +239,7 @@
n = '$NULL'
# jinja templates
if profile is None:
- self.profilePath = os.path.join('etc','wx.metadata','profiles', 'temporalProfile.xml')
+ self.profilePath = 'temporalProfile.xml'
else:
self.profilePath = profile
self.schema_type = '_temporal.xml'
@@ -318,7 +318,7 @@
n = '$NULL'
# jinja templates
if profile is None:
- self.profilePath = os.path.join('etc','wx.metadata','profiles', 'basicProfile.xml')
+ self.profilePath = 'basicProfile.xml'
else:
self.profilePath = profile
@@ -387,7 +387,7 @@
try:
self.md.dataquality.lineage = mdutil.replaceXMLReservedChar(self.md_grass['comments']).replace('\n', '\\n')
except:
- grass.warning('Native metadata *flag=comments* not found, dataquality.lineage filled by $NULL')
+ grass.message('Native metadata *flag=comments* not found, dataquality.lineage filled by $NULL')
self.md.dataquality.lineage = n
self.md.identification.denominators.append(n)
@@ -427,7 +427,7 @@
self.createGrassBasicISO()
if profile is None:
- self.profilePath = os.path.join('etc','wx.metadata','profiles', 'inspireProfile.xml')
+ self.profilePath = 'inspireProfile.xml'
else:
self.profilePath = profile
Modified: grass-addons/grass7/gui/wxpython/wx.metadata/mdlib/mdpdffactory.py
===================================================================
--- grass-addons/grass7/gui/wxpython/wx.metadata/mdlib/mdpdffactory.py 2015-08-25 08:37:10 UTC (rev 66010)
+++ grass-addons/grass7/gui/wxpython/wx.metadata/mdlib/mdpdffactory.py 2015-08-25 09:39:03 UTC (rev 66011)
@@ -2,19 +2,25 @@
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 reportlab.platypus import PageBreak
import tempfile, sys, os
+from grass.pygrass.utils import get_lib_path
+from grass.script import core as grass
+
+def load_mdlib(libs):
+ for lib in libs:
+ path = get_lib_path(modname=os.path.join('wx.metadata','mdlib') ,libname=lib)
+ if path is not None and path not in sys.path:
+ sys.path.append(path)
+ elif path is None:
+ grass.fatal("Fatal error: library < %s > not found "%lib)
+load_mdlib(['pdf','mdlib'])
+
import math
from reportlab.platypus import Paragraph, Image, Table
+from reportlab.platypus import PageBreak
from mdpdftheme import *
-from grass.script import core as grass
-sys.path.insert(1, os.path.join(os.path.dirname(sys.path[0]), 'etc', 'pdf'))
-sys.path.insert(1, os.path.join(os.path.dirname(sys.path[0]),'etc','wx.metadata','mdlib'))
-
-
-
class MyTheme(DefaultTheme):
doc = {
'leftMargin': 25,
Modified: grass-addons/grass7/gui/wxpython/wx.metadata/mdlib/mdutil.py
===================================================================
--- grass-addons/grass7/gui/wxpython/wx.metadata/mdlib/mdutil.py 2015-08-25 08:37:10 UTC (rev 66010)
+++ grass-addons/grass7/gui/wxpython/wx.metadata/mdlib/mdutil.py 2015-08-25 09:39:03 UTC (rev 66011)
@@ -35,13 +35,25 @@
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
+import wx
-import wx
class StaticContext(object):
def __init__(self):
self.ppath = os.path.dirname(os.path.abspath(__file__))
- self.addonsPath=os.path.join(os.getenv('GRASS_ADDON_BASE'),'etc' 'wx.metadata')
+ path = os.path.join('wx.metadata','config')
+ 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)
+ path=os.path.join('wx.metadata','profiles')
+ 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)
+
def isTableExists(name):
res = Module('db.tables',flags='p',stdout_=PIPE)
for line in res.outputs.stdout.splitlines():
More information about the grass-commit
mailing list