[GRASS-SVN] r67841 - grass/trunk/temporal/t.list

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Feb 15 23:09:20 PST 2016


Author: lucadelu
Date: 2016-02-15 23:09:20 -0800 (Mon, 15 Feb 2016)
New Revision: 67841

Modified:
   grass/trunk/temporal/t.list/t.list.py
Log:
t.list: added output option, started working on #2319

Modified: grass/trunk/temporal/t.list/t.list.py
===================================================================
--- grass/trunk/temporal/t.list/t.list.py	2016-02-16 05:05:07 UTC (rev 67840)
+++ grass/trunk/temporal/t.list/t.list.py	2016-02-16 07:09:20 UTC (rev 67841)
@@ -71,6 +71,10 @@
 #% guisection: Formatting
 #%end
 
+#%option G_OPT_F_OUTPUT
+#% required: no
+#%end
+
 #%flag
 #% key: c
 #% description: Print the column names as first row
@@ -93,6 +97,7 @@
     order = options["order"]
     where = options["where"]
     separator = gscript.separator(options["separator"])
+    outpath = options["output"]
     colhead = flags['c']
 
     # Make sure the temporal database exists
@@ -103,7 +108,7 @@
     dbif.connect()
     first = True
     
-    if  gscript.verbosity() > 0:
+    if  gscript.verbosity() > 0 and not outpath:
         sys.stderr.write("----------------------------------------------\n")
 
     for ttype in temporal_type.split(","):
@@ -117,6 +122,9 @@
         # Use the correct order of the mapsets, hence first the current mapset, then
         # alphabetic ordering
         mapsets = tgis.get_tgis_c_library_interface().available_mapsets()
+        
+        if outpath:
+            outfile = open(outpath, 'w') 
 
         # Print for each mapset separately
         for key in mapsets:
@@ -124,7 +132,7 @@
                 rows = stds_list[key]
 
                 if rows:
-                    if  gscript.verbosity() > 0:
+                    if  gscript.verbosity() > 0 and not outpath:
                         if issubclass(sp.__class__,  tgis.AbstractMapDataset):
                             sys.stderr.write(_("Time stamped %s maps with %s available in mapset <%s>:\n")%\
                                                      (sp.get_type(),  time,  key))
@@ -142,7 +150,10 @@
                             else:
                                 output += str(key)
                             count += 1
-                        print output
+                        if outpath:
+                            outfile.write("{st}\n".format(st=output))
+                        else:
+                            print output
                         first = False
             
                     for row in rows:
@@ -154,8 +165,10 @@
                             else:
                                 output += str(col)
                             count += 1
-            
-                        print output
+                        if outpath:
+                            outfile.write("{st}\n".format(st=output))
+                        else:
+                            print output
 
     dbif.close()
 



More information about the grass-commit mailing list