def main(): env = grass.gisenv() mapset = env['MAPSET'] ret = 0 vectors = grass.list_grouped('vect')[mapset] num_vectors = len(vectors) if grass.verbosity() < 2: quiet = True else: quiet = False i = 1 for vect in vectors: map = "%s@%s" % (vect, mapset) grass.message(_("%s\nBuilding topology for vector map <%s> (%d of %d)...\n%s") % \ ('-' * 80, map, i, num_vectors, '-' * 80)) grass.verbose(_("v.build map=%s") % map) if grass.run_command("v.build", map = map, quiet = quiet) != 0: grass.error(_("Building topology for vector map <%s> failed") % map) ret = 1 i += 1 return ret
def main(): env = grass.gisenv() mapset = env['MAPSET'] ret = 0 vectors = grass.list_grouped('vect')[mapset] num_vectors = len(vectors) if grass.verbosity() < 2: quiet = True else: quiet = False i = 1 for vect in vectors: map = "%s@%s" % (vect, mapset) grass.message( _("%s\nBuilding topology for vector map <%s> (%d of %d)...\n%s") % ('-' * 80, map, i, num_vectors, '-' * 80)) grass.verbose(_("v.build map=%s") % map) try: grass.run_command("v.build", map=map, quiet=quiet) except CalledModuleError: grass.error( _("Building topology for vector map <%s> failed") % map) ret = 1 i += 1 return ret
def install_extension_other(): gisbase = os.getenv('GISBASE') gui_list = list_wxgui_extensions(print_module = False) if options['extension'] not in gui_list: classchar = options['extension'].split('.', 1)[0] moduleclass = expand_module_class_name(classchar) url = options['svnurl'] + '/' + moduleclass + '/' + options['extension'] else: url = options['svnurl'] + '/gui/wxpython/' + options['extension'] if not flags['s']: grass.fatal(_("Installation of wxGUI extension requires -%s flag.") % 's') grass.message(_("Fetching <%s> from GRASS-Addons SVN (be patient)...") % options['extension']) os.chdir(tmpdir) if grass.verbosity() <= 2: outdev = open(os.devnull, 'w') else: outdev = sys.stdout if grass.call(['svn', 'checkout', url], stdout = outdev) != 0: 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'), '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(' ', '\ '), 'ARCH_BINDIR=%s' % dirs['bin'], 'BIN=%s' % dirs['bin'], 'HTMLDIR=%s' % dirs['html'], 'MANDIR=%s' % dirs['man1'], 'SCRIPTDIR=%s' % dirs['scripts'], 'ETC=%s' % os.path.join(dirs['etc'],options['extension']) ] installCmd = ['make', 'MODULE_TOPDIR=%s' % gisbase, 'ARCH_DISTDIR=%s' % os.path.join(tmpdir, options['extension']), 'INST_DIR=%s' % options['prefix'], 'install' ] if flags['d']: grass.message(_("To compile run:")) sys.stderr.write(' '.join(makeCmd) + '\n') grass.message(_("To install run:\n\n")) sys.stderr.write(' '.join(installCmd) + '\n') return os.chdir(os.path.join(tmpdir, options['extension'])) grass.message(_("Compiling...")) if options['extension'] not in gui_list: ret = grass.call(makeCmd, stdout = outdev) else: ret = grass.call(['make', 'MODULE_TOPDIR=%s' % gisbase.replace(' ', '\ ')], stdout = outdev) if ret != 0: grass.fatal(_('Compilation failed, sorry. Please check above error messages.')) if flags['i'] or options['extension'] in gui_list: return grass.message(_("Installing...")) return grass.call(installCmd, stdout = outdev)
def install_extension(): gisbase = os.getenv('GISBASE') if not gisbase: grass.fatal(_('$GISBASE not defined')) 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) if options['extension'] not in gui_list: classchar = options['extension'].split('.', 1)[0] moduleclass = expand_module_class_name(classchar) url = options['svnurl'] + '/' + moduleclass + '/' + options['extension'] else: url = options['svnurl'] + '/gui/wxpython/' + options['extension'] if not flags['s']: grass.fatal(_("Installation of wxGUI extension requires -%s flag.") % 's') grass.message(_("Fetching '%s' from GRASS-Addons SVN (be patient)...") % options['extension']) os.chdir(tmpdir) if grass.verbosity() == 0: outdev = open(os.devnull, 'w') else: outdev = sys.stdout 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']: grass.message(_("To compile run:")) sys.stderr.write(' '.join(makeCmd) + '\n') grass.message(_("To install run:\n\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: for d in dirs.itervalues(): if not os.path.exists(d): os.makedirs(d) ret = grass.call(makeCmd, stdout = outdev) else: ret = grass.call(['make', 'MODULE_TOPDIR=%s' % gisbase.replace(' ', '\ ')], stdout = outdev) if ret != 0: grass.fatal(_('Compilation failed, sorry. Please check above error messages.')) if flags['i'] or options['extension'] in gui_list: return grass.message(_("Installing '%s'...") % options['extension']) ret = grass.call(installCmd, stdout = outdev) if ret != 0: grass.warning(_('Installation failed, sorry. Please check above error messages.')) else: grass.message(_("Installation of '%s' successfully finished.") % options['extension']) # manual page: fix href if os.getenv('GRASS_ADDON_PATH'): html_man = os.path.join(os.getenv('GRASS_ADDON_PATH'), 'docs', 'html', options['extension'] + '.html') if os.path.exists(html_man): fd = open(html_man) html_str = '\n'.join(fd.readlines()) fd.close() for rep in ('grassdocs.css', 'grass_logo.png'): patt = re.compile(rep, re.IGNORECASE) html_str = patt.sub(os.path.join(gisbase, 'docs', 'html', rep), html_str) patt = re.compile(r'(<a href=")(d|db|g|i|m|p|ps|r|r3|s|v|wxGUI)(\.)(.+)(.html">)', re.IGNORECASE) while True: m = patt.search(html_str) if not m: break html_str = patt.sub(m.group(1) + os.path.join(gisbase, 'docs', 'html', m.group(2) + m.group(3) + m.group(4)) + m.group(5), html_str, count = 1) fd = open(html_man, "w") fd.write(html_str) fd.close() 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 install_extension_other(name): gisbase = os.getenv('GISBASE') classchar = name.split('.', 1)[0] moduleclass = expand_module_class_name(classchar) url = options['svnurl'] + '/' + moduleclass + '/' + name grass.message(_("Fetching <%s> from GRASS-Addons SVN repository (be patient)...") % name) os.chdir(TMPDIR) if grass.verbosity() <= 2: outdev = open(os.devnull, 'w') else: outdev = sys.stdout if grass.call(['svn', 'checkout', url], stdout = outdev) != 0: grass.fatal(_("GRASS Addons <%s> not found") % name) dirs = { 'bin' : os.path.join(TMPDIR, name, 'bin'), 'docs' : os.path.join(TMPDIR, name, 'docs'), 'html' : os.path.join(TMPDIR, name, 'docs', 'html'), 'rest' : os.path.join(TMPDIR, name, 'docs', 'rest'), 'man' : os.path.join(TMPDIR, name, 'docs', 'man', 'man1'), 'script' : os.path.join(TMPDIR, name, 'scripts'), ### TODO: handle locales also for addons # 'string' : os.path.join(TMPDIR, name, 'locale'), 'string' : os.path.join(TMPDIR, name), 'etc' : os.path.join(TMPDIR, name, 'etc'), } makeCmd = ['make', 'MODULE_TOPDIR=%s' % gisbase.replace(' ', '\ '), 'RUN_GISRC=%s' % os.environ['GISRC'], 'BIN=%s' % dirs['bin'], 'HTMLDIR=%s' % dirs['html'], 'RESTDIR=%s' % dirs['rest'], 'MANDIR=%s' % dirs['man'], 'SCRIPTDIR=%s' % dirs['script'], 'STRINGDIR=%s' % dirs['string'], 'ETC=%s' % os.path.join(dirs['etc'], name) ] installCmd = ['make', 'MODULE_TOPDIR=%s' % gisbase, 'ARCH_DISTDIR=%s' % os.path.join(TMPDIR, name), 'INST_DIR=%s' % options['prefix'], 'install' ] if flags['d']: grass.message("\n%s\n" % _("To compile run:")) sys.stderr.write(' '.join(makeCmd) + '\n') grass.message("\n%s\n" % _("To install run:")) sys.stderr.write(' '.join(installCmd) + '\n') return 0 os.chdir(os.path.join(TMPDIR, name)) grass.message(_("Compiling...")) if 0 != grass.call(makeCmd, stdout = outdev): grass.fatal(_('Compilation failed, sorry. Please check above error messages.')) if flags['i']: return 0 grass.message(_("Installing...")) return grass.call(installCmd, stdout = outdev)