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

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Sep 16 15:04:53 PDT 2018


Author: wenzeslaus
Date: 2018-09-16 15:04:53 -0700 (Sun, 16 Sep 2018)
New Revision: 73350

Modified:
   grass/trunk/lib/init/grass.py
Log:
init: restructure for quick overview and PEP8 compliance

Modified: grass/trunk/lib/init/grass.py
===================================================================
--- grass/trunk/lib/init/grass.py	2018-09-16 21:04:38 UTC (rev 73349)
+++ grass/trunk/lib/init/grass.py	2018-09-16 22:04:53 UTC (rev 73350)
@@ -1737,9 +1737,10 @@
     if not os.getenv('HISTSIZE') and not os.getenv('HISTFILESIZE'):
         os.environ['HISTSIZE'] = "3000"
 
-    # instead of changing $HOME, start bash with: --rcfile "$LOCATION/.bashrc" ?
-    #   if so, must care be taken to explicitly call .grass.bashrc et al for
-    #   non-interactive bash batch jobs?
+    # instead of changing $HOME, start bash with:
+    #   --rcfile "$LOCATION/.bashrc" ?
+    #   if so, must care be taken to explicitly call .grass.bashrc et al
+    #   for non-interactive bash batch jobs?
     userhome = os.getenv('HOME')      # save original home
     home = location                   # save .bashrc in $LOCATION
     os.environ['HOME'] = home
@@ -1749,25 +1750,37 @@
 
     f = open(bashrc, 'w')
     f.write("test -r ~/.alias && . ~/.alias\n")
+
     if os.getenv('ISISROOT'):
-        f.write("PS1='ISIS-GRASS %s (%s):\\w > '\n" % (grass_version, location_name))
+        # GRASS GIS and ISIS blend
+        grass_name = "ISIS-GRASS"
     else:
-        f.write("PS1='GRASS %s (%s):\\w > '\n" % (grass_version, location_name))
+        grass_name = "GRASS"
+    f.write("PS1='{name} {version} ({location}):\\w > '\n".format(
+        name=grass_name, version=grass_version, location=location_name))
 
-    f.write("""grass_prompt() {
-	LOCATION="`g.gisenv get=GISDBASE,LOCATION_NAME,MAPSET separator='/'`"
-	if test -d "$LOCATION/grid3/G3D_MASK" && test -f "$LOCATION/cell/MASK" ; then
-		echo [%s]
-	elif test -f "$LOCATION/cell/MASK" ; then
-		echo [%s]
-	elif test -d "$LOCATION/grid3/G3D_MASK" ; then
-		echo [%s]
-	fi
-}
-PROMPT_COMMAND=grass_prompt\n""" % (_("2D and 3D raster MASKs present"),
-                                    _("Raster MASK present"),
-                                    _("3D raster MASK present")))
+    mask2d_test = 'test -f "$LOCATION/cell/MASK"'
+    mask3d_test = 'test -d "$LOCATION/grid3/G3D_MASK"'
 
+    # double curly brackets means single one for format function
+    f.write(
+        """grass_prompt() {{
+    LOCATION="`g.gisenv get=GISDBASE,LOCATION_NAME,MAPSET separator='/'`"
+    if {mask2d_test} && {mask3d_test} ; then
+        echo [{both_masks}]
+    elif {mask2d_test} ; then
+        echo [{mask2d}]
+    elif {mask3d_test} ; then
+        echo [{mask3d}]
+    fi
+}}
+PROMPT_COMMAND=grass_prompt\n""".format(
+            both_masks=_("2D and 3D raster MASKs present"),
+            mask2d=_("Raster MASK present"),
+            mask3d=_("3D raster MASK present"),
+            mask2d_test=mask2d_test, mask3d_test=mask3d_test
+            ))
+
     # read other settings (aliases, ...) since environmental variables
     # have been already set by load_env(), see #3462
     for env_file in [os.path.join(userhome, ".grass.bashrc"),



More information about the grass-commit mailing list