[GRASS-SVN] r47199 - in grass/branches/releasebranch_6_4/gui: scripts wxpython/gui_modules

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Jul 21 07:38:02 EDT 2011


Author: martinl
Date: 2011-07-21 04:38:02 -0700 (Thu, 21 Jul 2011)
New Revision: 47199

Modified:
   grass/branches/releasebranch_6_4/gui/scripts/g.extension.py
   grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/ghelp.py
Log:
wxGUI: sync g.extension.py with trunk
       don't close window on install


Modified: grass/branches/releasebranch_6_4/gui/scripts/g.extension.py
===================================================================
--- grass/branches/releasebranch_6_4/gui/scripts/g.extension.py	2011-07-21 11:27:18 UTC (rev 47198)
+++ grass/branches/releasebranch_6_4/gui/scripts/g.extension.py	2011-07-21 11:38:02 UTC (rev 47199)
@@ -20,7 +20,9 @@
 #%module
 #% label: Tool to maintain the extensions in local GRASS installation.
 #% description: Downloads, installs extensions from GRASS Addons SVN repository into local GRASS installation or removes installed extensions.
-#% keywords: general, installation, extensions
+#% keywords: general
+#% keywords: installation
+#% keywords: extensions
 #%end
 
 #%option
@@ -34,7 +36,7 @@
 #% key: operation
 #% type: string
 #% description: Operation to be performed
-#% required: no
+#% required: yes
 #% options: add,remove
 #% answer: add
 #%end
@@ -44,7 +46,7 @@
 #% key_desc: url
 #% description: SVN Addons repository URL
 #% required: yes
-#% answer: https://svn.osgeo.org/grass/grass-addons
+#% answer: https://svn.osgeo.org/grass/grass-addons/grass7
 #%end
 #%option
 #% key: prefix
@@ -52,7 +54,7 @@
 #% key_desc: path
 #% description: Prefix where to install extension (ignored when flag -s is given)
 #% answer: $GRASS_ADDON_PATH
-#% required: yes
+#% required: no
 #%end
 
 #%flag
@@ -94,12 +96,11 @@
 
 # temp dir
 remove_tmpdir = True
-tmpdir = grass.tempdir()
 
 def check():
-    for prog in ('svn', 'make', 'install', 'gcc'):
+    for prog in ('svn', 'make', 'gcc'):
         if not grass.find_program(prog, ['--help']):
-            grass.fatal(_("%s required. Please install '%s' first.") % (prog, prog))
+            grass.fatal(_("'%s' required. Please install '%s' first.") % (prog, prog))
     
 def expand_module_class_name(c):
     name = { 'd'   : 'display',
@@ -281,18 +282,17 @@
     return ret
 
 def cleanup():
-    global tmpdir, remove_tmpdir
     if remove_tmpdir:
         grass.try_rmdir(tmpdir)
     else:
-        grass.info(_("Path to the source code: '%s'") % tmpdir)
+        grass.info(_("Path to the source code: '%s'") % os.path.join(tmpdir, options['extension']))
                         
 def install_extension():
     gisbase = os.getenv('GISBASE')
     if not gisbase:
         grass.fatal(_('$GISBASE not defined'))
     
-    if grass.find_program(options['extension']):
+    if grass.find_program(options['extension'], ['--help']):
         grass.warning(_("Extension '%s' already installed. Will be updated...") % options['extension'])
     
     gui_list = list_wxgui_extensions(print_module = False)
@@ -307,7 +307,7 @@
             grass.fatal(_("Installation of wxGUI extension requires -%s flag.") % 's')
         
     grass.message(_("Fetching '%s' from GRASS-Addons SVN (be patient)...") % options['extension'])
-    global tmpdir
+    
     os.chdir(tmpdir)
     if grass.verbosity() == 0:
         outdev = open(os.devnull, 'w')
@@ -317,29 +317,46 @@
     if grass.call(['svn', 'checkout',
                    url], stdout = outdev) != 0:
         grass.fatal(_("GRASS Addons '%s' not found in repository") % options['extension'])
-
+    
+    dirs = { 'bin' : os.path.join(tmpdir, options['extension'], 'bin'),
+             'docs' : os.path.join(tmpdir, options['extension'], 'docs'),
+             'html' : os.path.join(tmpdir, options['extension'], 'docs', 'html'),
+             'man' : os.path.join(tmpdir, options['extension'], 'man'),
+             'man1' : os.path.join(tmpdir, options['extension'], 'man', 'man1'),
+             'scripts' : os.path.join(tmpdir, options['extension'], 'scripts'),
+             'etc' : os.path.join(tmpdir, options['extension'], 'etc'),
+             }
+    
+    makeCmd = ['make',
+               'MODULE_TOPDIR=%s' % gisbase.replace(' ', '\ '),
+               'BIN=%s' % dirs['bin'],
+               'HTMLDIR=%s' % dirs['html'],
+               'MANDIR=%s' % dirs['man1'],
+               'SCRIPTDIR=%s' % dirs['scripts'],
+               'ETC=%s' % dirs['etc']
+               ]
+    
+    installCmd = ['make',
+                  'MODULE_TOPDIR=%s' % gisbase,
+                  'ARCH_DISTDIR=%s' % os.path.join(tmpdir, options['extension']),
+                  'INST_DIR=%s' % options['prefix'],
+                  'install'
+                  ]
+    
     if flags['d']:
+        sys.stderr.write(' '.join(makeCmd) + '\n')
+        sys.stderr.write(' '.join(installCmd) + '\n')
         return
     
     os.chdir(os.path.join(tmpdir, options['extension']))
-
+    
     grass.message(_("Compiling '%s'...") % options['extension'])    
     if options['extension'] not in gui_list:
-        bin_dir  = os.path.join(tmpdir, options['extension'], 'bin')
-        docs_dir = os.path.join(tmpdir, options['extension'], 'docs')
-        html_dir = os.path.join(docs_dir, 'html')
-        man_dir  = os.path.join(tmpdir, options['extension'], 'man')
-        man1_dir = os.path.join(man_dir, 'man1')
-        script_dir = os.path.join(tmpdir, options['extension'], 'scripts')
-        for d in (bin_dir, docs_dir, html_dir, man_dir, man1_dir, script_dir):
-            os.mkdir(d)
+        for d in dirs.itervalues():
+            if not os.path.exists(d):
+                os.makedirs(d)
         
-        ret = grass.call(['make',
-                          'MODULE_TOPDIR=%s' % gisbase.replace(' ', '\ '),
-                          'BIN=%s' % bin_dir,
-                          'HTMLDIR=%s' % html_dir,
-                          'MANDIR=%s' % man1_dir,
-                          'SCRIPTDIR=%s' % script_dir],
+        ret = grass.call(makeCmd,
                          stdout = outdev)
     else:
         ret = grass.call(['make',
@@ -354,11 +371,7 @@
     
     grass.message(_("Installing '%s'...") % options['extension'])
     
-    ret = grass.call(['make',
-                      'MODULE_TOPDIR=%s' % gisbase,
-                      'ARCH_DISTDIR=%s' % os.path.join(tmpdir, options['extension']),
-                      'INST_DIR=%s' % options['prefix'],
-                      'install'],
+    ret = grass.call(installCmd,
                      stdout = outdev)
     
     if ret != 0:
@@ -366,6 +379,11 @@
     else:
         grass.message(_("Installation of '%s' successfully finished.") % options['extension'])
 
+    if not os.environ.has_key('GRASS_ADDON_PATH') or \
+            not os.environ['GRASS_ADDON_PATH']:
+        grass.warning(_('This add-on module will not function until you set the '
+                        'GRASS_ADDON_PATH environment variable (see "g.manual variables")'))
+
 def remove_extension():
     # is module available?
     if not os.path.exists(os.path.join(options['prefix'], 'bin', options['extension'])):
@@ -414,10 +432,17 @@
     if options['prefix'] == '$GRASS_ADDON_PATH':
         if not os.environ.has_key('GRASS_ADDON_PATH') or \
                 not os.environ['GRASS_ADDON_PATH']:
-            grass.warning(_("GRASS_ADDON_PATH is not defined, installing to ~/.grass7/addons/"))
-            options['prefix'] = os.path.join(os.environ['HOME'], '.grass7', 'addons')
+            major_version = int(grass.version()['version'].split('.', 1)[0])
+            grass.warning(_("GRASS_ADDON_PATH is not defined, "
+                            "installing to ~/.grass%d/addons/") % major_version)
+            options['prefix'] = os.path.join(os.environ['HOME'], '.grass%d' % major_version, 'addons')
         else:
-            options['prefix'] = os.environ['GRASS_ADDON_PATH']
+            path_list = os.environ['GRASS_ADDON_PATH'].split(os.pathsep)
+            if len(path_list) < 1:
+                grass.fatal(_("Invalid GRASS_ADDON_PATH value - '%s'") % os.environ['GRASS_ADDON_PATH'])
+            if len(path_list) > 1:
+                grass.warning(_("GRASS_ADDON_PATH has more items, using first defined - '%s'") % path_list[0])
+            options['prefix'] = path_list[0]
     
     # check dirs
     check_dirs()
@@ -438,5 +463,7 @@
 
 if __name__ == "__main__":
     options, flags = grass.parser()
+    global tmpdir
+    tmpdir = grass.tempdir()
     atexit.register(cleanup)
     sys.exit(main())

Modified: grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/ghelp.py
===================================================================
--- grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/ghelp.py	2011-07-21 11:27:18 UTC (rev 47198)
+++ grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/ghelp.py	2011-07-21 11:38:02 UTC (rev 47199)
@@ -908,7 +908,7 @@
         
         log.RunCmd(['g.extension.py'] + flags + ['extension=' + name,
                                                  'svnurl=' + self.repo.GetValue().strip()])
-        self.OnCloseWindow(None)
+        ### self.OnCloseWindow(None)
         
     def OnUpdateStatusBar(self, event):
         """!Update statusbar text"""



More information about the grass-commit mailing list