[GRASS-SVN] r49257 - grass/trunk/scripts/g.extension
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Nov 15 14:03:46 EST 2011
Author: martinl
Date: 2011-11-15 11:03:46 -0800 (Tue, 15 Nov 2011)
New Revision: 49257
Modified:
grass/trunk/scripts/g.extension/g.extension.py
Log:
g.extension: download precompiled addons on Windows (first attempt)
Modified: grass/trunk/scripts/g.extension/g.extension.py
===================================================================
--- grass/trunk/scripts/g.extension/g.extension.py 2011-11-15 18:13:10 UTC (rev 49256)
+++ grass/trunk/scripts/g.extension/g.extension.py 2011-11-15 19:03:46 UTC (rev 49257)
@@ -99,7 +99,7 @@
import shutil
import glob
-import urllib
+from urllib2 import urlopen, HTTPError
from grass.script import core as grass
@@ -120,7 +120,7 @@
'ps' : 'postscript',
'p' : 'paint',
'r' : 'raster',
- 'r3' : 'raster3D',
+ 'r3' : 'raster3d',
's' : 'sites',
'v' : 'vector',
'gui' : 'gui/wxpython' }
@@ -148,9 +148,10 @@
url = '%s/%s' % (options['svnurl'], modclass)
grass.debug("url = %s" % url, debug = 2)
- f = urllib.urlopen(url)
- if not f:
- grass.warning(_("Unable to fetch '%s'") % url)
+ try:
+ f = urlopen(url)
+ except HTTPError:
+ grass.debug(_("Unable to fetch '%s'") % url, debug = 1)
continue
for line in f.readlines():
@@ -178,7 +179,7 @@
url = '%s/%s' % (options['svnurl'], 'gui/wxpython')
grass.debug("url = %s" % url, debug = 2)
- f = urllib.urlopen(url)
+ f = urlopen(url)
if not f:
grass.warning(_("Unable to fetch '%s'") % url)
return
@@ -221,7 +222,7 @@
def get_module_desc(url, script = True):
grass.debug('url=%s' % url)
- f = urllib.urlopen(url)
+ f = urlopen(url)
if script:
ret = get_module_script(f)
else:
@@ -297,6 +298,31 @@
grass.message(_("Path to the source code:"))
sys.stderr.write('%s\n' % os.path.join(tmpdir, options['extension']))
+def install_extension_win():
+ ### TODO: do not use hardcoded url
+ url = "http://wingrass.fsv.cvut.cz/grass70/addons"
+ success = False
+ grass.message(_("Downloading precompiled GRASS Addons <%s>...") % options['extension'])
+ for comp, ext in [(('bin', ), 'exe'),
+ (('docs', 'html'), 'html'),
+ (('man', 'man1'), None),
+ (('scripts', ), 'py')]:
+ name = options['extension']
+ if ext:
+ name += '.' + ext
+ try:
+ f = urlopen(url + '/' + '/'.join(comp) + '/' + name)
+ fo = open(os.path.join(options['prefix'], os.path.sep.join(comp), name), 'wb')
+ fo.write(f.read())
+ fo.close()
+ if comp[0] in ('bin', 'scripts'):
+ success = True
+ except HTTPError:
+ pass
+
+ if not success:
+ grass.fatal(_("GRASS Addons <%s> not found") % options['extension'])
+
def install_extension():
gisbase = os.getenv('GISBASE')
if not gisbase:
@@ -326,7 +352,7 @@
if grass.call(['svn', 'checkout',
url], stdout = outdev) != 0:
- grass.fatal(_("GRASS Addons '%s' not found in repository") % options['extension'])
+ grass.fatal(_("GRASS Addons <%s> not found") % options['extension'])
dirs = { 'bin' : os.path.join(tmpdir, options['extension'], 'bin'),
'docs' : os.path.join(tmpdir, options['extension'], 'docs'),
@@ -483,7 +509,8 @@
def main():
# check dependecies
- check()
+ if sys.platform != "win32":
+ check()
# list available modules
if flags['l'] or flags['c'] or flags['g']:
@@ -522,7 +549,10 @@
remove_tmpdir = False
if options['operation'] == 'add':
- install_extension()
+ if sys.platform == "win32":
+ install_extension_win()
+ else:
+ install_extension()
else: # remove
remove_extension(flags)
More information about the grass-commit
mailing list