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

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Mar 22 10:43:53 EDT 2011


Author: martinl
Date: 2011-03-22 07:43:53 -0700 (Tue, 22 Mar 2011)
New Revision: 45726

Modified:
   grass/trunk/lib/init/grass.py
Log:
startup: create new location using -c


Modified: grass/trunk/lib/init/grass.py
===================================================================
--- grass/trunk/lib/init/grass.py	2011-03-22 14:17:56 UTC (rev 45725)
+++ grass/trunk/lib/init/grass.py	2011-03-22 14:43:53 UTC (rev 45726)
@@ -48,7 +48,7 @@
 
 # i18N
 import gettext
-gettext.install('grasslibs', os.path.join(gisbase, 'locale'), unicode=True)
+gettext.install('grasslibs', os.path.join(gisbase, 'locale'), unicode = True)
 
 tmpdir = None
 lockfile = None
@@ -152,7 +152,7 @@
        _("Flags"),
        _("print this help message"),
        _("show version information and exit"),
-       _("create given mapset if it doesn't exist"),
+       _("create given location/mapset if it doesn't exist"),
        _("use text based interface"),
        _("and set as default"),
        _("use $DEFAULT_GUI graphical user interface"),
@@ -428,7 +428,7 @@
 	kv['GRASS_GUI'] = grass_gui
 	write_gisrc(kv)
 
-def non_interactive(arg):
+def non_interactive(arg, geofile = None):
     global gisdbase, location_name, mapset, location
     # Try non-interactive startup
     l = None
@@ -460,9 +460,20 @@
 	    else:
 		# the user wants to create mapset on the fly
 		if create_new:
-		    if not os.access(os.path.join(os.path.join(gisdbase, location_name, "PERMANENT", "DEFAULT_WIND")), os.F_OK):
-			fatal(_("The location <%s> does not exist. Please create it first.") % location_name)
+		    if not os.access(os.path.join(os.path.join(gisdbase, location_name,
+                                                               "PERMANENT", "DEFAULT_WIND")), os.F_OK):
+                        # create new location
+                        gisdbase = os.path.join(gisdbase, location_name)
+                        location_name = mapset
+                        mapset = "PERMANENT"
+                        if os.access(os.path.join(os.path.join(gisdbase, location_name,
+                                                               "PERMANENT", "DEFAULT_WIND")), os.F_OK):
+                            fatal(_("Failed to create new location. The location <%s> already exists." % location_name))
+                        sys.path.append(gfile('etc', 'python'))
+                        from grass.script import core as grass
+                        grass.create_location(gisdbase, location_name, filename = geofile)
 		    else:
+                        # create new mapset
 			os.mkdir(location)
 			# copy PERMANENT/DEFAULT_WIND to <mapset>/WIND
 			s = readfile(os.path.join(gisdbase, location_name, "PERMANENT", "DEFAULT_WIND"))
@@ -826,11 +837,11 @@
     args = []
     for i in sys.argv[1:]:
 	# Check if the user asked for the version
-	if i in ["-v","--version"]:
+	if i in ["-v", "--version"]:
 	    message('\n' + readfile(gfile("etc", "license")))
 	    sys.exit()
 	# Check if the user asked for help
-	elif i in ["help","-h","-help","--help"]:
+	elif i in ["help", "-h", "-help", "--help"]:
 	    help_message()
 	    sys.exit()
 	# Check if the -text flag was given
@@ -840,7 +851,7 @@
 	elif i == "-gui":
 	    grass_gui = default_gui
 	# Check if the -wxpython flag was given
-	elif i in ["-wxpython","-wx"]:
+	elif i in ["-wxpython", "-wx"]:
 	    grass_gui = 'wxpython'
 	# Check if the user wants to create a new mapset
 	elif i == "-c":
@@ -954,7 +965,11 @@
     # Try interactive startup
     location = None
 else:
-    non_interactive(args[0])
+    if create_new:
+        if len(args) > 1:
+            non_interactive(args[1], args[0])
+        else:
+            non_interactive(args[0])
 
 # User selects LOCATION and MAPSET if not set
 set_data()



More information about the grass-commit mailing list