3
############################################################################
5
# MODULE: g.extension.all
7
# AUTHOR(S): Martin Landa <landa.martin gmail.com>
9
# PURPOSE: Rebuilds or removes locally installed GRASS Addons extensions
11
# COPYRIGHT: (C) 2011-2013 by Martin Landa, and the GRASS Development Team
13
# This program is free software under the GNU General
14
# Public License (>=v2). Read the file COPYING that
15
# comes with GRASS for details.
17
#############################################################################
20
#% label: Rebuilds or removes all locally installed GRASS Addons extensions.
21
#% description: By default only extensions built against different GIS Library are rebuilt.
23
#% keyword: installation
24
#% keyword: extensions
29
#% description: Operation to be performed
31
#% options: rebuild,remove
36
#% label: Force operation (required for removal)
43
import xml.etree.ElementTree as etree
45
import elementtree.ElementTree as etree # Python <= 2.4
47
import grass.script as grass
48
from grass.exceptions import CalledModuleError
52
addon_base = os.getenv('GRASS_ADDON_BASE')
54
grass.fatal(_("%s not defined") % "GRASS_ADDON_BASE")
55
fXML = os.path.join(addon_base, 'modules.xml')
56
if not os.path.exists(fXML):
62
tree = etree.fromstring(fo.read())
63
except StandardError as e:
64
grass.error(_("Unable to parse metadata file: %s") % e)
70
libgis_rev = grass.version()['libgis_revision']
72
for tnode in tree.findall('task'):
73
gnode = tnode.find('libgis')
74
if gnode is not None and \
75
gnode.get('revision', '') != libgis_rev:
76
ret.append(tnode.get('name'))
81
remove = options['operation'] == 'remove'
82
if remove or flags['f']:
83
extensions = grass.read_command('g.extension',
84
quiet = True, flags = 'a').splitlines()
86
extensions = get_extensions()
90
grass.info(_("No extension found. Nothing to remove."))
92
grass.info(_("Nothing to rebuild. Rebuilding process can be forced with -f flag."))
95
if remove and not flags['f']:
96
grass.message(_("List of extensions to be removed:"))
97
print os.linesep.join(extensions)
98
grass.message(_("You must use the force flag (-f) to actually remove them. Exiting."))
101
for ext in extensions:
102
grass.message('-' * 60)
104
grass.message(_("Removing extension <%s>...") % ext)
106
grass.message(_("Reinstalling extension <%s>...") % ext)
107
grass.message('-' * 60)
110
operation_flags = 'f'
115
grass.run_command('g.extension', flags=operation_flags,
116
extension=ext, operation=operation)
117
except CalledModuleError:
118
grass.error(_("Unable to process extension:%s") % ext)
122
if __name__ == "__main__":
123
options, flags = grass.parser()