def getCommands(removable=removable): cmd = grass.get_commands()[0] for i in removable: cmd.remove(i) commands = {} for i in cmd: command = ("%s --interface-description" % i).split() uidescription = subprocess.Popen(command, stdout=subprocess.PIPE).communicate()[0] commands[str(i)] = uidescription commands = OrderedDict(sorted(commands.items(), key=lambda t: t[0])) return commands
def getCommands(removable=removable): cmd = grass.get_commands()[0] for i in removable: cmd.remove(i) commands = {} for i in cmd: command = ("%s --interface-description" % i).split() uidescription = subprocess.Popen( command, stdout=subprocess.PIPE).communicate()[0] commands[str(i)] = uidescription commands = OrderedDict(sorted(commands.items(), key=lambda t: t[0])) return commands
def __new__(mcs, name, bases, dict): def gen_test(cmd): def test(self): Module(cmd) return test cmds = [c for c in sorted(list(get_commands()[0])) if c not in SKIP and not fnmatch(c, "g.gui.*")] for cmd in cmds: test_name = "test__%s" % cmd.replace('.', '_') dict[test_name] = gen_test(cmd) return type.__new__(mcs, name, bases, dict)
def module_test(): grass_commands = gcore.get_commands()[0] if not 'g.region' in grass_commands: print("No g.region") return 1 if not 'm.proj' in grass_commands: print("No m.proj") return 1 if not 't.rast.univar' in grass_commands: print("No t.rast.univar") return 1 print(get_module_metadata('g.region')) print(get_module_metadata('m.proj')) print(get_module_metadata('t.rast.univar'))
def module_test(): grass_commands = gcore.get_commands()[0] if "g.region" not in grass_commands: print("No g.region") return 1 if "m.proj" not in grass_commands: print("No m.proj") return 1 if "t.rast.univar" not in grass_commands: print("No t.rast.univar") return 1 print(get_module_metadata("g.region")) print(get_module_metadata("m.proj")) print(get_module_metadata("t.rast.univar"))
def module_test(): grass_commands = gcore.get_commands()[0] if not 'g.region' in grass_commands: print "No g.region" return 1 if not 'm.proj' in grass_commands: print "No m.proj" return 1 if not 't.rast.univar' in grass_commands: print "No t.rast.univar" return 1 print get_module_metadata('g.region') print get_module_metadata('m.proj') print get_module_metadata('t.rast.univar')
def __new__(mcs, name, bases, dict): def gen_test(cmd): def test(self): Module(cmd) return test cmds = [ c for c in sorted(list(get_commands()[0])) if c not in SKIP and not fnmatch(c, "g.gui.*") ] for cmd in cmds: test_name = "test__%s" % cmd.replace('.', '_') dict[test_name] = gen_test(cmd) return type.__new__(mcs, name, bases, dict)
def parse_modules(fd): """Writes metadata to xml file.""" # TODO: what about ms windows? does gtask handle this? mlist = list(gcore.get_commands()[0]) indent = 4 for m in mlist: # TODO: get rid of g.mapsets_picker.py if m == 'g.mapsets_picker.py' or m == 'g.parser': continue desc, keyw = get_module_metadata(m) fd.write('%s<module-item name="%s">\n' % (' ' * indent, m)) indent += 4 fd.write('%s<module>%s</module>\n' % (' ' * indent, m)) fd.write('%s<description>%s</description>\n' % (' ' * indent, escapeXML(desc))) fd.write('%s<keywords>%s</keywords>\n' % (' ' * indent, escapeXML(','.join(keyw)))) indent -= 4 fd.write('%s</module-item>\n' % (' ' * indent))
def parse_modules(fd): """Writes metadata to xml file.""" # TODO: what about ms windows? does gtask handle this? mlist = list(gcore.get_commands()[0]) indent = 4 for m in sorted(mlist): # TODO: get rid of g.mapsets_picker.py if m == 'g.mapsets_picker.py' or m == 'g.parser': continue desc, keyw = get_module_metadata(m) fd.write('%s<module-item name="%s">\n' % (' ' * indent, m)) indent += 4 fd.write('%s<module>%s</module>\n' % (' ' * indent, m)) fd.write('%s<description>%s</description>\n' % (' ' * indent, escapeXML(desc))) fd.write('%s<keywords>%s</keywords>\n' % (' ' * indent, escapeXML(','.join(keyw)))) indent -= 4 fd.write('%s</module-item>\n' % (' ' * indent))
# -*- coding: utf-8 -*- from __future__ import (nested_scopes, generators, division, absolute_import, with_statement, print_function, unicode_literals) import fnmatch from grass.script.core import get_commands from grass.pygrass.modules.interface import Module _CMDS = list(get_commands()[0]) _CMDS.sort() class MetaModule(object): """Example how to use MetaModule >>> g = MetaModule('g') >>> g_list = g.list >>> g_list.name 'g.list' >>> g_list.required ['type'] >>> g_list.inputs.type = 'raster' >>> g_list.inputs.mapset = 'PERMANENT' >>> g_list.stdout_ = -1 >>> g_list.run() Module('g.list') >>> g_list.outputs.stdout # doctest: +ELLIPSIS '...basin...soils...' >>> r = MetaModule('r') >>> what = r.what
elemList.append(elem.tag) # now I remove duplicities - by convertion to set and back to list elemList = list(set(elemList)) if tag in elemList: return True else: return False from grass.script import core as gcore # def find_moduls(): # """Find GRASS moduls. # """ cmds = list(gcore.get_commands()[0]) cmds.sort() # file_names = [cmd.replace('.', '_') for cmd in cmds] from grass.script import task as gtask # try to call method get_interface_description, see Issue #7 if sys.platform == 'win32': gtask.get_interface_description('v.db.update') for cmd in cmds: try: # def parser(): root = xml.etree.ElementTree.fromstring( gtask.get_interface_description('{}'.format(cmd)))
Debug.msg(3, "AddOn commands: %s", name) nCmd += 1 if ext == SCT_EXT and \ ext in grassScripts.keys() and \ name not in grassScripts[ext]: grassScripts[ext].append(name) else: if fname not in grassCmd: grassCmd.add(fname) Debug.msg(3, "AddOn commands: %s", fname) nCmd += 1 Debug.msg(1, "Number of GRASS AddOn commands: %d", nCmd) """@brief Collected GRASS-relared binaries/scripts""" grassCmd, grassScripts = get_commands() Debug.msg(1, "Number of core GRASS commands: %d", len(grassCmd)) UpdateGRASSAddOnCommands() """@Toolbar icon size""" toolbarSize = (24, 24) """@Check version of wxPython, use agwStyle for 2.8.11+""" hasAgw = CheckWxVersion([2, 8, 11, 0]) wxPython3 = CheckWxVersion([3, 0, 0, 0]) wxPythonPhoenix = CheckWxPhoenix() gtk3 = True if 'gtk3' in wx.PlatformInfo else False """@Add GUIDIR/scripts into path""" os.environ['PATH'] = os.path.join(GUIDIR, 'scripts') + os.pathsep + os.environ['PATH']
if name not in grassCmd: grassCmd.add(name) Debug.msg(3, "AddOn commands: %s", name) nCmd += 1 if ext == SCT_EXT and \ ext in grassScripts.keys() and \ name not in grassScripts[ext]: grassScripts[ext].append(name) else: if fname not in grassCmd: grassCmd.add(fname) Debug.msg(3, "AddOn commands: %s", fname) nCmd += 1 Debug.msg(1, "Number of GRASS AddOn commands: %d", nCmd) """@brief Collected GRASS-relared binaries/scripts""" grassCmd, grassScripts = get_commands() Debug.msg(1, "Number of core GRASS commands: %d", len(grassCmd)) UpdateGRASSAddOnCommands() """@Toolbar icon size""" toolbarSize = (24, 24) """@Check version of wxPython, use agwStyle for 2.8.11+""" hasAgw = CheckWxVersion([2, 8, 11, 0]) wxPython3 = CheckWxVersion([3, 0, 0, 0]) """@Add GUIDIR/scripts into path""" os.environ['PATH'] = os.path.join(GUIDIR, 'scripts') + os.pathsep + os.environ['PATH']
# -*- coding: utf-8 -*- from __future__ import (nested_scopes, generators, division, absolute_import, with_statement, print_function, unicode_literals) import fnmatch from grass.script.core import get_commands from grass.pygrass.modules.interface import Module _CMDS = list(get_commands()[0]) _CMDS.sort() class MetaModule(object): """Example how to use MetaModule >>> g = MetaModule('g') >>> g_list = g.list >>> g_list.name 'g.list' >>> g_list.required ['type'] >>> g_list.inputs.type = 'rast' >>> g_list.stdout_ = -1 >>> g_list.run() Module('g.list') >>> g_list.outputs.stdout # doctest: +ELLIPSIS '...basins...soils...' >>> r = MetaModule('r') >>> what = r.what >>> what.description 'Queries raster maps on their category values and category labels.'