[GRASS-SVN] r47557 - grass/trunk/lib/init

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Aug 11 16:21:19 EDT 2011


Author: lucadelu
Date: 2011-08-11 13:21:18 -0700 (Thu, 11 Aug 2011)
New Revision: 47557

Modified:
   grass/trunk/lib/init/grass.py
Log:
add --config option in the startup script; it is usefull to return some paramaters of GRASS installation

Modified: grass/trunk/lib/init/grass.py
===================================================================
--- grass/trunk/lib/init/grass.py	2011-08-11 20:14:07 UTC (rev 47556)
+++ grass/trunk/lib/init/grass.py	2011-08-11 20:21:18 UTC (rev 47557)
@@ -10,6 +10,7 @@
 #		Hamish Bowman <hamish_b yahoo,com>
 #		Converted to Python (based on init.sh) by Glynn Clements
 #               Martin Landa <landa.martin gmail.com>
+#               Luca Delucchi <lucadeluge at gmail.com>
 # PURPOSE:  	Sets up environment variables, parses any remaining 
 #               command line options for setting the GISDBASE, LOCATION,
 #               and/or MAPSET. Finally it starts GRASS with the appropriate user
@@ -143,6 +144,8 @@
                                    %s
   -gui                           %s
                                    %s
+  --config                       %s
+                                   %s
 
 %s:
   GISDBASE                       %s
@@ -167,6 +170,8 @@
        _("and set as default"),
        _("use $DEFAULT_GUI graphical user interface"),
        _("and set as default"),
+       _("print GRASS configuration parameters"),
+       _("options: arch,build,compiler,path"),
        _("Parameters"),
        _("initial database (path to GIS data)"),
        _("initial location"),
@@ -849,6 +854,32 @@
     nul = open(os.devnull, 'w')
     call([gfile("etc", "clean_temp")], stdout = nul, stderr = nul)
     nul.close()
+
+def grep(string,list):
+    expr = re.compile(string)
+    return [elem for elem in list if expr.match(elem)]
+
+def print_params():
+       plat = os.path.join(gisbase,'include','Make','Platform.make')
+       fileplat = open(plat)
+       linesplat = fileplat.readlines()
+       fileplat.close()
+       for i in sys.argv[2:]:
+               if i == 'path':
+                       print gisbase
+               elif i == 'arch':
+                       val = grep('ARCH',linesplat)
+                       print val[0].split('=')[1].strip()
+               elif i == 'build':
+                       build = os.path.join(gisbase,'include','grass','confparms.h')
+                       filebuild = open(build)
+                       val = filebuild.readline()
+                       print val.strip().strip('"').strip()
+               elif i == 'compiler':
+                       val = grep('CC',linesplat)
+                       print val[0].split('=')[1].strip()
+               else:
+                       print "Parameter not supported"
     
 def get_username():
     global user
@@ -895,6 +926,9 @@
 	# Check if the user wants to create a new mapset
 	elif i == "-c":
 	    create_new = True
+	elif i == "--config":
+            print_params()
+            sys.exit()
 	else:
 	    args.append(i)
 



More information about the grass-commit mailing list