[GRASS-SVN] r49266 - grass/trunk/scripts/g.extension
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed Nov 16 07:45:14 EST 2011
Author: martinl
Date: 2011-11-16 04:45:14 -0800 (Wed, 16 Nov 2011)
New Revision: 49266
Modified:
grass/trunk/scripts/g.extension/g.extension.py
Log:
g.extension: major speed up when listing extensions (-l/c/g) - using daily updated XML files from http://grass.osgeo.org/addons instead of parsing html's and modules itself
Modified: grass/trunk/scripts/g.extension/g.extension.py
===================================================================
--- grass/trunk/scripts/g.extension/g.extension.py 2011-11-16 09:57:32 UTC (rev 49265)
+++ grass/trunk/scripts/g.extension/g.extension.py 2011-11-16 12:45:14 UTC (rev 49266)
@@ -101,6 +101,11 @@
from urllib2 import urlopen, HTTPError
+try:
+ import xml.etree.ElementTree as etree
+except ImportError:
+ import elementtree.ElementTree as etree # Python <= 2.4
+
from grass.script import core as grass
# temp dir
@@ -132,6 +137,37 @@
def list_available_modules():
mlist = list()
+
+ # try to download XML metadata file first
+ url = "http://grass.osgeo.org/addons/grass%s.xml" % grass.version()['version'].split('.')[0]
+ try:
+ f = urlopen(url)
+ tree = etree.fromstring(f.read())
+ for mnode in tree.findall('task'):
+ name = mnode.get('name')
+ if flags['c'] or flags['g']:
+ desc = mnode.find('description').text
+ if not desc:
+ desc = ''
+ keyw = mnode.find('keywords').text
+ if not keyw:
+ keyw = ''
+
+ if flags['g']:
+ print 'name=' + name
+ print 'description=' + desc
+ print 'keywords=' + keyw
+ elif flags['c']:
+ print name + ' - ' + desc
+ else:
+ print name
+ except HTTPError:
+ return list_available_modules_svn()
+
+ return mlist
+
+def list_available_modules_svn():
+ mlist = list()
grass.message(_('Fetching list of modules from GRASS-Addons SVN (be patient)...'))
pattern = re.compile(r'(<li><a href=".+">)(.+)(</a></li>)', re.IGNORECASE)
i = 0
@@ -211,7 +247,7 @@
desc = get_module_desc(url + '/' + name + '/main.c', script = False)
if not desc:
if not flags['g']:
- print name + '-'
+ print name + ' - '
return
if flags['g']:
@@ -222,7 +258,11 @@
def get_module_desc(url, script = True):
grass.debug('url=%s' % url)
- f = urlopen(url)
+ try:
+ f = urlopen(url)
+ except HTTPError:
+ return {}
+
if script:
ret = get_module_script(f)
else:
@@ -300,7 +340,8 @@
def install_extension_win():
### TODO: do not use hardcoded url
- url = "http://wingrass.fsv.cvut.cz/grass70/addons"
+ version = grass.version()['version'].split('.')
+ url = "http://wingrass.fsv.cvut.cz/grass%s%s/addons" % (version[0], version[1])
success = False
grass.message(_("Downloading precompiled GRASS Addons <%s>...") % options['extension'])
for comp, ext in [(('bin', ), 'exe'),
More information about the grass-commit
mailing list