[GRASS-SVN] r53494 - in grass/branches/releasebranch_6_4: gui/wxpython/core gui/wxpython/lmgr gui/wxpython/modules lib/init
svn_grass at osgeo.org
svn_grass at osgeo.org
Fri Oct 19 04:29:25 PDT 2012
Author: martinl
Date: 2012-10-19 04:29:24 -0700 (Fri, 19 Oct 2012)
New Revision: 53494
Modified:
grass/branches/releasebranch_6_4/gui/wxpython/core/globalvar.py
grass/branches/releasebranch_6_4/gui/wxpython/core/utils.py
grass/branches/releasebranch_6_4/gui/wxpython/lmgr/frame.py
grass/branches/releasebranch_6_4/gui/wxpython/modules/extensions.py
grass/branches/releasebranch_6_4/lib/init/init.bat
grass/branches/releasebranch_6_4/lib/init/init.sh
Log:
eliminate gis env ADDON_PATH, see #1696
Modified: grass/branches/releasebranch_6_4/gui/wxpython/core/globalvar.py
===================================================================
--- grass/branches/releasebranch_6_4/gui/wxpython/core/globalvar.py 2012-10-19 11:18:33 UTC (rev 53493)
+++ grass/branches/releasebranch_6_4/gui/wxpython/core/globalvar.py 2012-10-19 11:29:24 UTC (rev 53494)
@@ -25,6 +25,8 @@
ETCIMGDIR = os.path.join(ETCDIR, "gui", "images")
ETCSYMBOLDIR = os.path.join(ETCDIR, "gui", "images", "symbols")
+from core.debug import Debug
+
sys.path.append(os.path.join(ETCDIR, "python"))
import grass.script as grass
@@ -145,24 +147,47 @@
if script[-len(pattern):] != pattern: # ignore wrappers
cmd.append(script)
+ return set(cmd), scripts
+
+def UpdateGRASSAddOnCommands():
+ """!Update list of available GRASS AddOns commands to use when
+ parsing string from the command line
+ """
+ global grassCmd, grassScripts
+
# scan addons (path)
- if os.getenv('GRASS_ADDON_PATH'):
- for path in os.getenv('GRASS_ADDON_PATH').split(os.pathsep):
- if not os.path.exists(path) or not os.path.isdir(path):
+ if not os.getenv('GRASS_ADDON_PATH'):
+ return
+
+ nCmd = 0
+ for path in os.getenv('GRASS_ADDON_PATH').split(os.pathsep):
+ if not os.path.exists(path) or not os.path.isdir(path):
+ continue
+ for fname in os.listdir(path):
+ if fname in ['docs', 'modules.xml']:
continue
- for fname in os.listdir(path):
- if scripts: # win32
- name, ext = os.path.splitext(fname)
- cmd.append(name)
- if ext in scripts.keys():
- scripts[ext].append(name)
- else:
- cmd.append(fname)
-
- return set(cmd), scripts
+ if grassScripts: # win32
+ name, ext = os.path.splitext(fname)
+ if ext not in ['.exe', '.bat']:
+ continue
+ if name not in grassCmd:
+ grassCmd.add(name)
+ nCmd += 1
+ if ext == '.bat' and \
+ ext in grassScripts.keys() and \
+ name not in grassScripts[ext]:
+ grassScripts[ext].append(name)
+ else:
+ if fname not in grassCmd:
+ grassCmd.add(fname)
+ nCmd += 1
+
+ Debug.msg(1, "Number of new AddOn commands: %d", nCmd)
"""@brief Collected GRASS-relared binaries/scripts"""
grassCmd, grassScripts = GetGRASSCommands()
+Debug.msg(1, "Number of GRASS commands: %d", len(grassCmd))
+UpdateGRASSAddOnCommands()
"""@Toolbar icon size"""
toolbarSize = (24, 24)
Modified: grass/branches/releasebranch_6_4/gui/wxpython/core/utils.py
===================================================================
--- grass/branches/releasebranch_6_4/gui/wxpython/core/utils.py 2012-10-19 11:18:33 UTC (rev 53493)
+++ grass/branches/releasebranch_6_4/gui/wxpython/core/utils.py 2012-10-19 11:29:24 UTC (rev 53494)
@@ -777,6 +777,80 @@
# 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:
+ gVersion = grass.version()['version'].split('.', 1)[0]
+ envFile = os.path.join(os.getenv('APPDATA'), 'GRASS%s' % gVersion, '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/releasebranch_6_4/gui/wxpython/lmgr/frame.py
===================================================================
--- grass/branches/releasebranch_6_4/gui/wxpython/lmgr/frame.py 2012-10-19 11:18:33 UTC (rev 53493)
+++ grass/branches/releasebranch_6_4/gui/wxpython/lmgr/frame.py 2012-10-19 11:29:24 UTC (rev 53494)
@@ -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
@@ -648,8 +649,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/releasebranch_6_4/gui/wxpython/modules/extensions.py
===================================================================
--- grass/branches/releasebranch_6_4/gui/wxpython/modules/extensions.py 2012-10-19 11:18:33 UTC (rev 53493)
+++ grass/branches/releasebranch_6_4/gui/wxpython/modules/extensions.py 2012-10-19 11:29:24 UTC (rev 53494)
@@ -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
@@ -220,15 +221,14 @@
log.RunCmd(self._getCmd(), onDone = self.OnDone)
def OnDone(self, cmd, returncode):
- item = self.tree.GetSelected()
- if not item or not item.IsOk() or \
- returncode != 0 or \
- not os.getenv('GRASS_ADDON_PATH'):
- return
-
- name = self.tree.GetItemText(item)
- globalvar.grassCmd.add(name)
-
+ if returncode == 0:
+ if not os.getenv('GRASS_ADDON_PATH'):
+ SetAddOnPath()
+
+ globalvar.UpdateGRASSAddOnCommands()
+ log = self.parent.GetLogWindow()
+ log.GetPrompt().SetFilter(None)
+
def OnItemSelected(self, event):
"""!Item selected"""
item = event.GetItem()
Modified: grass/branches/releasebranch_6_4/lib/init/init.bat
===================================================================
--- grass/branches/releasebranch_6_4/lib/init/init.bat 2012-10-19 11:18:33 UTC (rev 53493)
+++ grass/branches/releasebranch_6_4/lib/init/init.bat 2012-10-19 11:29:24 UTC (rev 53494)
@@ -25,6 +25,10 @@
set SAVEPATH=%PATH%
rem DON'T include scripts directory in PATH - .bat files in bin directory
rem are used to run scripts on Windows
+
+if exist "%APPDATA%\GRASS6\env.bat" (
+ call %APPDATA%\GRASS6\env.bat
+)
if "%GRASS_ADDON_PATH%"=="" set GRASS_ADDON_PATH=%APPDATA%\GRASS6\addons
PATH=%GISBASE%\bin;%GISBASE%\lib;%GRASS_ADDON_PATH%;%PATH%
Modified: grass/branches/releasebranch_6_4/lib/init/init.sh
===================================================================
--- grass/branches/releasebranch_6_4/lib/init/init.sh 2012-10-19 11:18:33 UTC (rev 53493)
+++ grass/branches/releasebranch_6_4/lib/init/init.sh 2012-10-19 11:29:24 UTC (rev 53494)
@@ -742,15 +742,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