[GRASS-SVN] r38399 - grass/trunk/scripts/g.extension
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Jul 13 13:01:17 EDT 2009
Author: martinl
Date: 2009-07-13 13:01:16 -0400 (Mon, 13 Jul 2009)
New Revision: 38399
Modified:
grass/trunk/scripts/g.extension/g.extension.py
Log:
prefix -> ~/.grass/addons
Modified: grass/trunk/scripts/g.extension/g.extension.py
===================================================================
--- grass/trunk/scripts/g.extension/g.extension.py 2009-07-13 15:52:34 UTC (rev 38398)
+++ grass/trunk/scripts/g.extension/g.extension.py 2009-07-13 17:01:16 UTC (rev 38399)
@@ -52,8 +52,9 @@
#% key: prefix
#% type: string
#% key_desc: path
-#% description: Prefix where to install extension (default: GISBASE)
-#% required: no
+#% description: Prefix where to install extension
+#% answer: $(HOME)/.grass/addons
+#% required: yes
#%end
#%option
#% key: menuitem
@@ -127,7 +128,11 @@
global tmpdir
grass.try_rmdir(tmpdir)
-def install_extension(svnurl, gisbase, module):
+def install_extension(svnurl, prefix, module):
+ gisbase = os.environ['GISBASE']
+ if not gisbase:
+ grass.fatal('$GISBASE not defined')
+
if grass.find_program(module):
grass.warning("Extension '%s' already installed. Will be updated..." % module)
@@ -152,17 +157,19 @@
# can we write ?
try:
# replace with something better
- file = os.path.join(gisbase, 'test')
+ file = os.path.join(prefix, 'test')
f = open(file, "w")
f.close()
os.remove(file)
ret = grass.call(['make',
'MODULE_TOPDIR=%s' % gisbase,
+ 'INST_DIR=%s' % prefix,
'install'])
except IOError:
ret = grass.call(['sudo', 'make',
'MODULE_TOPDIR=%s' % gisbase,
+ 'INST_DIR=%s' % prefix,
'install'])
if ret != 0:
@@ -170,14 +177,14 @@
else:
grass.message("Installation of '%s' successfully finished." % module)
-def remove_extension(gisbase, module):
+def remove_extension(prefix, module):
# is module available?
if not grass.find_program(module):
grass.fatal("'%s' not found" % module)
- for file in [os.path.join(gisbase, 'bin', module),
- os.path.join(gisbase, 'scripts', module),
- os.path.join(gisbase, 'docs', 'html', module + '.html')]:
+ for file in [os.path.join(prefix, 'bin', module),
+ os.path.join(prefix, 'scripts', module),
+ os.path.join(prefix, 'docs', 'html', module + '.html')]:
if os.path.isfile(file):
os.remove(file)
@@ -202,19 +209,25 @@
if not options['extension']:
grass.fatal('You need to define an extension name or use -l')
- module = options['extension']
- if options['prefix']:
- gisbase = options['prefix']
- else:
- gisbase = os.getenv('GISBASE')
+ # TODO: check more variable
+ if '$(HOME)' in options['prefix']:
+ options['prefix'] = options['prefix'].replace('$(HOME)', os.environ['HOME'])
+ if not os.path.isdir(options['prefix']):
+ try:
+ os.makedirs(options['prefix'])
+ except OSError, e:
+ grass.fatal("Unable to create '%s'\n%s" % (options['prefix'], e))
+
+ grass.warning("'%s' created" % options['prefix'])
+
if options['operation'] == 'add':
- install_extension(options['svnurl'], gisbase, module)
+ install_extension(options['svnurl'], options['prefix'], options['extension'])
else: # remove
- remove_extension(gisbase, module)
+ remove_extension(options['prefix'], options['extension'])
if options['menuitem']:
- update_menu(options['menuitem'], module, options['operation'])
+ update_menu(options['menuitem'], options['extension'], options['operation'])
return 0
More information about the grass-commit
mailing list