[GRASS-SVN] r53481 - in grass/branches/develbranch_6: gui/wxpython/core gui/wxpython/lmgr gui/wxpython/modules lib/init
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Oct 18 17:18:07 PDT 2012
Author: martinl
Date: 2012-10-18 17:18:07 -0700 (Thu, 18 Oct 2012)
New Revision: 53481
Modified:
grass/branches/develbranch_6/gui/wxpython/core/utils.py
grass/branches/develbranch_6/gui/wxpython/lmgr/frame.py
grass/branches/develbranch_6/gui/wxpython/modules/extensions.py
grass/branches/develbranch_6/lib/init/init.sh
Log:
wxGUI: eliminate gis env ADDON_PATH, see #1696
Modified: grass/branches/develbranch_6/gui/wxpython/core/utils.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/core/utils.py 2012-10-18 19:33:23 UTC (rev 53480)
+++ grass/branches/develbranch_6/gui/wxpython/core/utils.py 2012-10-19 00:18:07 UTC (rev 53481)
@@ -777,6 +777,79 @@
# keep location of settings files rc and wx in sync with
# lib/init/init.sh and init.bat
if sys.platform == 'win32':
- return os.path.join(os.getenv('APPDATA'), 'grass%d' % version)
+ return os.path.join(os.getenv('APPDATA'), 'GRASS%d' % version)
return os.path.join(os.getenv('HOME'), '.grass%d' % version)
+
+def StoreEnvVariable(key, value, envFile = None):
+ """!Store environmental variable
+
+ @param key env key
+ @param value env value
+ @param envFile path to the environmental file (None for default location)
+ """
+ windows = sys.platform == 'win32'
+ if not envFile:
+ if not windows:
+ envFile = os.path.join(os.getenv('HOME'), '.grass.bashrc')
+ else:
+ envFile = os.path.join(os.getenv('APPDATA'), 'GRASS%d' % version, 'env.bat')
+
+ # read env file
+ environ = dict()
+ if os.path.exists(envFile):
+ try:
+ fd = open(envFile)
+ except IOError, e:
+ sys.stderr.write(_("Unable to open file '%s'") % envFile)
+ return
+ for line in fd.readlines():
+ try:
+ key, value = line.split(' ', 1).strip().split('=', 1)
+ except:
+ sys.stderr.write(_("%s: unable to parse '%s'") % (envFile, line))
+ continue
+ if key in environ:
+ sys.stderr.write(_("Duplicated key: %s") % key)
+ environ[key] = value
+
+ fd.close()
+
+ # update environmental variables
+ environ[key] = value
+
+ # write update env file
+ try:
+ fd = open(envFile, 'w')
+ except IOError, e:
+ sys.stderr.write(_("Unable to create file '%s'") % envFile)
+ return
+ if windows:
+ expCmd = 'set'
+ else:
+ expCmd = 'export'
+
+ for key, value in environ.iteritems():
+ fd.write('%s %s=%s\n' % (expCmd, key, value))
+
+ fd.close()
+
+def SetAddOnPath(addonPath = None):
+ """!Set default AddOn path
+
+ @addonPath path to addons (None for default)
+ """
+ gVersion = grass.version()['version'].split('.', 1)[0]
+ # update env file
+ if not addonPath:
+ if sys.platform != 'win32':
+ addonPath = os.path.join(os.path.join(os.getenv('HOME'),
+ '.grass%s' % gVersion,
+ 'addons'))
+ else:
+ addonPath = os.path.join(os.path.join(os.getenv('APPDATA'),
+ 'GRASS%s' % gVersion,
+ 'addons'))
+
+ StoreEnvVariable('GRASS_ADDON_PATH', addonPath)
+ os.environ['GRASS_ADDON_PATH'] = addonPath
Modified: grass/branches/develbranch_6/gui/wxpython/lmgr/frame.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/lmgr/frame.py 2012-10-18 19:33:23 UTC (rev 53480)
+++ grass/branches/develbranch_6/gui/wxpython/lmgr/frame.py 2012-10-19 00:18:07 UTC (rev 53481)
@@ -41,6 +41,7 @@
from core.gcmd import RunCommand, GError, GMessage
from core.settings import UserSettings
+from core.utils import SetAddOnPath
from gui_core.preferences import MapsetAccess, PreferencesDialog, EVT_SETTINGS_CHANGED
from lmgr.layertree import LayerTree, LMIcons
from lmgr.menudata import ManagerData
@@ -681,8 +682,7 @@
caption = _("Update Addons path?"),
style = wx.YES_NO | wx.YES_DEFAULT | wx.ICON_QUESTION)
if dlg.ShowModal() == wx.ID_YES:
- os.environ['GRASS_ADDON_PATH'] = os.pathsep.join(addonPath)
- RunCommand('g.gisenv', set = 'ADDON_PATH=%s' % os.environ['GRASS_ADDON_PATH'])
+ SetAddOnPath(os.pathsep.join(addonPath))
self.goutput.WriteCmdLog(_("Launching script '%s'...") % filename)
self.goutput.RunCmd([filename], switchPage = True)
Modified: grass/branches/develbranch_6/gui/wxpython/modules/extensions.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/modules/extensions.py 2012-10-18 19:33:23 UTC (rev 53480)
+++ grass/branches/develbranch_6/gui/wxpython/modules/extensions.py 2012-10-19 00:18:07 UTC (rev 53481)
@@ -33,6 +33,7 @@
from core import globalvar
from core.gcmd import GError, RunCommand
+from core.utils import SetAddOnPath
from gui_core.forms import GUI
from gui_core.widgets import ItemTree
from gui_core.ghelp import SearchModuleWindow
@@ -221,6 +222,9 @@
def OnDone(self, cmd, returncode):
if returncode == 0:
+ if not os.getenv('GRASS_ADDON_PATH'):
+ SetAddOnPath()
+
globalvar.UpdateGRASSAddOnCommands()
log = self.parent.GetLogWindow()
log.GetPrompt().SetFilter(None)
Modified: grass/branches/develbranch_6/lib/init/init.sh
===================================================================
--- grass/branches/develbranch_6/lib/init/init.sh 2012-10-18 19:33:23 UTC (rev 53480)
+++ grass/branches/develbranch_6/lib/init/init.sh 2012-10-19 00:18:07 UTC (rev 53481)
@@ -736,15 +736,6 @@
exit 1
fi
-# check gisenv's ADDON_PATH
-ADDON_PATH=`g.gisenv ADDON_PATH`
-if [ -n "$ADDON_PATH" ] ; then
- GRASS_ADDON_PATH="$GRASS_ADDON_PATH:$ADDON_PATH"
- export GRASS_ADDON_PATH
- PATH="$GISBASE/bin:$GISBASE/scripts:$GRASS_ADDON_PATH:$PATH"
- export PATH
-fi
-
LOCATION="${GISDBASE?}/${LOCATION_NAME?}/${MAPSET?}"
# Check for concurrent use
More information about the grass-commit
mailing list