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

svn_grass at osgeo.org svn_grass at osgeo.org
Thu May 1 12:18:29 PDT 2014


Author: huhabla
Date: 2014-05-01 12:18:28 -0700 (Thu, 01 May 2014)
New Revision: 60018

Modified:
   grass/trunk/temporal/t.list/t.list.py
Log:
Use function to list stds and maps that is sensitive to the users mapset access permissions, making the output more g.list like

Modified: grass/trunk/temporal/t.list/t.list.py
===================================================================
--- grass/trunk/temporal/t.list/t.list.py	2014-05-01 19:17:11 UTC (rev 60017)
+++ grass/trunk/temporal/t.list/t.list.py	2014-05-01 19:18:28 UTC (rev 60018)
@@ -81,15 +81,15 @@
 
 import grass.script as grass
 import grass.temporal as tgis
+import sys
 
 ############################################################################
 
-
 def main():
 
     # Get the options
     type = options["type"]
-    temporaltype = options["temporaltype"]
+    temporal_type = options["temporaltype"]
     columns = options["columns"]
     order = options["order"]
     where = options["where"]
@@ -99,69 +99,59 @@
     # Make sure the temporal database exists
     tgis.init()
 
-    id = None
-    sp = tgis.dataset_factory(type, id)
-
-    dbif = tgis.SQLDatabaseInterfaceConnection()
-    dbif.connect()
-    
+    sp = tgis.dataset_factory(type, None)
     first = True
     
-    for ttype in temporaltype.split(","):
-    
-        # Create the sql selection statement
-        # Table name
+    sys.stderr.write("----------------------------------------------\n")
+
+    for ttype in temporal_type.split(","):
         if ttype == "absolute":
-            table = sp.get_type() + "_view_abs_time"
+            time = "absolute time"
         else:
-            table = sp.get_type() + "_view_rel_time"
+            time = "relative time"
+
+        stds_list = tgis.get_dataset_list(type,  ttype,  columns,  where,  order)
     
-        if columns.find("all") == -1:
-            sql = "SELECT " + str(columns) + " FROM " + table
-        else:
-            sql = "SELECT * FROM " + table
-    
-        if where:
-            sql += " WHERE " + where
-    
-        if order:
-            sql += " ORDER BY " + order
-    
-        dbif.cursor.execute(sql)
-        rows = dbif.cursor.fetchall()
-    
-        # Print the query result to stout
-        if rows:
-            if separator is None or separator == "":
-                separator = "\t"
-    
-            # Print the column names if requested
-            if colhead == True and first == True:
-                output = ""
-                count = 0
-                for key in rows[0].keys():
-                    if count > 0:
-                        output += separator + str(key)
-                    else:
-                        output += str(key)
-                    count += 1
-                print output
-                first = False
-    
-            for row in rows:
-                output = ""
-                count = 0
-                for col in row:
-                    if count > 0:
-                        output += separator + str(col)
-                    else:
-                        output += str(col)
-                    count += 1
-    
-                print output
+        # Print for each mapset separately
+        for key in stds_list.keys():
+            rows = stds_list[key]
 
-    dbif.close()
+            if rows:
+                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))
+                else:
+                    sys.stderr.write(_("Space time %s datasets with %s available in mapset <%s>:\n")%\
+                                             (sp.get_new_map_instance(None).get_type(),  time,  key))
+
+                if separator is None or separator == "":
+                    separator = "\t"
         
+                # Print the column names if requested
+                if colhead == True and first == True:
+                    output = ""
+                    count = 0
+                    for key in rows[0].keys():
+                        if count > 0:
+                            output += separator + str(key)
+                        else:
+                            output += str(key)
+                        count += 1
+                    print output
+                    first = False
+        
+                for row in rows:
+                    output = ""
+                    count = 0
+                    for col in row:
+                        if count > 0:
+                            output += separator + str(col)
+                        else:
+                            output += str(col)
+                        count += 1
+        
+                    print output
+
 if __name__ == "__main__":
     options, flags = grass.parser()
     main()



More information about the grass-commit mailing list