Pārlūkot izejas kodu

startup script: added flag -e in startup script to exit after creation of location or mapset (backport from trunk: https://trac.osgeo.org/grass/changeset/60146 + https://trac.osgeo.org/grass/changeset/60147)

git-svn-id: https://svn.osgeo.org/grass/grass/branches/releasebranch_7_0@60182 15284696-431f-4ddb-bdfa-cd5b030d7da7
Markus Neteler 11 gadi atpakaļ
vecāks
revīzija
26c0edd439
1 mainītis faili ar 19 papildinājumiem un 6 dzēšanām
  1. 19 6
      lib/init/grass.py

+ 19 - 6
lib/init/grass.py

@@ -68,7 +68,7 @@ remove_lockfile = True
 location = None
 location = None
 create_new = None
 create_new = None
 grass_gui = None
 grass_gui = None
-
+exit_grass = None
 
 
 def warning(text):
 def warning(text):
     sys.stderr.write(_("WARNING") + ': ' + text + os.linesep)
     sys.stderr.write(_("WARNING") + ': ' + text + os.linesep)
@@ -168,13 +168,14 @@ Geographic Resources Analysis Support System (GRASS GIS).
 
 
 %s:
 %s:
   $CMD_NAME [-h | -help | --help] [-v | --version] [-c | -c geofile | -c EPSG:code]
   $CMD_NAME [-h | -help | --help] [-v | --version] [-c | -c geofile | -c EPSG:code]
-          [-text | -gui] [--config param]
+          [-e] [-text | -gui] [--config param]
           [[[<GISDBASE>/]<LOCATION_NAME>/]<MAPSET>]
           [[[<GISDBASE>/]<LOCATION_NAME>/]<MAPSET>]
 
 
 %s:
 %s:
   -h or -help or --help          %s
   -h or -help or --help          %s
   -v or --version                %s
   -v or --version                %s
   -c                             %s
   -c                             %s
+  -e                             %s
   -text                          %s
   -text                          %s
                                    %s
                                    %s
   -gtext                         %s
   -gtext                         %s
@@ -204,6 +205,7 @@ Geographic Resources Analysis Support System (GRASS GIS).
        _("print this help message"),
        _("print this help message"),
        _("show version information and exit"),
        _("show version information and exit"),
        _("create given database, location or mapset if it doesn't exist"),
        _("create given database, location or mapset if it doesn't exist"),
+       _("exit after creation of location or mapset. Only with -c flag"),
        _("use text based interface (skip welcome screen)"),
        _("use text based interface (skip welcome screen)"),
        _("and set as default"),
        _("and set as default"),
        _("use text based interface (show welcome screen)"),
        _("use text based interface (show welcome screen)"),
@@ -969,7 +971,7 @@ def clear_screen():
     # TODO: uncomment when PDCurses works.
     # TODO: uncomment when PDCurses works.
     #   cls
     #   cls
     else:
     else:
-        if not os.getenv('GRASS_BATCH_JOB') and not grass_debug:
+        if not os.getenv('GRASS_BATCH_JOB') and not grass_debug and not exit_grass:
             call(["tput", "clear"])
             call(["tput", "clear"])
 
 
 
 
@@ -1214,7 +1216,7 @@ def get_username():
 
 
 
 
 def parse_cmdline():
 def parse_cmdline():
-    global args, grass_gui, create_new
+    global args, grass_gui, create_new, exit_grass
     args = []
     args = []
     for i in sys.argv[1:]:
     for i in sys.argv[1:]:
         # Check if the user asked for the version
         # Check if the user asked for the version
@@ -1240,6 +1242,8 @@ def parse_cmdline():
         # Check if the user wants to create a new mapset
         # Check if the user wants to create a new mapset
         elif i == "-c":
         elif i == "-c":
             create_new = True
             create_new = True
+        elif i == "-e":
+            exit_grass = True
         elif i == "--config":
         elif i == "--config":
             print_params()
             print_params()
             sys.exit()
             sys.exit()
@@ -1307,6 +1311,8 @@ get_username()
 # Parse the command-line options
 # Parse the command-line options
 parse_cmdline()
 parse_cmdline()
 
 
+if exit_grass and not create_new:
+    fatal(_("Flag -e required also flag -c"))
 # Set language
 # Set language
 # This has to be called before any _() function call!
 # This has to be called before any _() function call!
 # Subsequent functions are using _() calls and
 # Subsequent functions are using _() calls and
@@ -1358,7 +1364,10 @@ if not os.access(gisrc, os.F_OK):
 else:
 else:
     clean_temp()
     clean_temp()
 
 
-message(_("Starting GRASS GIS..."))
+if create_new:
+    message(_("Creating new GRASS GIS location/mapset..."))
+else:
+    message(_("Starting GRASS GIS..."))
 
 
 # Check that the GUI works
 # Check that the GUI works
 check_gui()
 check_gui()
@@ -1395,7 +1404,7 @@ if not os.access(os.path.join(location, "VAR"), os.F_OK):
 
 
 check_batch_job()
 check_batch_job()
 
 
-if not batch_job:       
+if not batch_job and not exit_grass:       
     start_gui()
     start_gui()
 
 
 clear_screen()
 clear_screen()
@@ -1407,6 +1416,10 @@ if batch_job:
     clean_temp()
     clean_temp()
     try_remove(lockfile)
     try_remove(lockfile)
     sys.exit(0)
     sys.exit(0)
+elif exit_grass:
+    clean_temp()
+    try_remove(lockfile)
+    sys.exit(0)
 else:
 else:
     show_banner()
     show_banner()
     say_hello()
     say_hello()