[GRASS-SVN] r51228 - in grass/trunk/temporal: t.remove t.unregister
svn_grass at osgeo.org
svn_grass at osgeo.org
Sat Mar 31 16:44:23 EDT 2012
Author: huhabla
Date: 2012-03-31 13:44:22 -0700 (Sat, 31 Mar 2012)
New Revision: 51228
Modified:
grass/trunk/temporal/t.remove/t.remove.py
grass/trunk/temporal/t.unregister/t.unregister.py
Log:
Use more efficient removal and unregistration methods.
Modified: grass/trunk/temporal/t.remove/t.remove.py
===================================================================
--- grass/trunk/temporal/t.remove/t.remove.py 2012-03-31 20:41:35 UTC (rev 51227)
+++ grass/trunk/temporal/t.remove/t.remove.py 2012-03-31 20:44:22 UTC (rev 51228)
@@ -53,11 +53,11 @@
def main():
# Get the options
- maps = options["input"]
+ datasets = options["input"]
file = options["file"]
type = options["type"]
- if maps and file:
+ if datasets and file:
core.fata(_("%s= and %s= are mutually exclusive") % ("input","file"))
# Make sure the temporal database exists
@@ -66,16 +66,16 @@
dbif = tgis.sql_database_interface()
dbif.connect()
- maplist = []
+ dataset_list = []
- # Map names as comma separated string
- if maps:
- if maps.find(",") == -1:
- maplist = (maps,)
+ # Dataset names as comma separated string
+ if datasets:
+ if datasets.find(",") == -1:
+ dataset_list = (datasets,)
else:
- maplist = tuple(maps.split(","))
+ dataset_list = tuple(datasets.split(","))
- # Read the map list from file
+ # Read the dataset list from file
if file:
fd = open(file, "r")
@@ -86,12 +86,14 @@
break
line_list = line.split("\n")
- mapname = line_list[0]
- maplist.append(mapname)
+ dataset_name = line_list[0]
+ dataset_list.append(dataset_name)
mapset = grass.gisenv()["MAPSET"]
+
+ statement = ""
- for name in maplist:
+ for name in dataset_list:
name = name.strip()
# Check for the mapset in name
if name.find("@") < 0:
@@ -105,8 +107,20 @@
dbif.close()
grass.fatal(_("%s dataset <%s> not found in temporal database") % (sp.get_type(), name))
- sp.delete(dbif)
+ statement += sp.delete(dbif=dbif, execute=False)
+ # Execute the collected SQL statenents
+ sql_script = ""
+ sql_script += "BEGIN TRANSACTION;\n"
+ sql_script += statement
+ sql_script += "END TRANSACTION;"
+ # print sql_script
+
+ if tgis.dbmi.__name__ == "sqlite3":
+ dbif.cursor.executescript(statement)
+ else:
+ dbif.cursor.execute(statement)
+
dbif.close()
if __name__ == "__main__":
Modified: grass/trunk/temporal/t.unregister/t.unregister.py
===================================================================
--- grass/trunk/temporal/t.unregister/t.unregister.py 2012-03-31 20:41:35 UTC (rev 51227)
+++ grass/trunk/temporal/t.unregister/t.unregister.py 2012-03-31 20:44:22 UTC (rev 51228)
@@ -137,31 +137,49 @@
num_maps = len(maplist)
update_dict = {}
count = 0
+
+ statement = ""
+
+ # Unregister already registered maps
for mapid in maplist:
grass.percent(count, num_maps, 1)
- print mapid
map = tgis.dataset_factory(type, mapid)
# Unregister map if in database
if map.is_in_db(dbif) == True:
# Unregister from a single dataset
if name:
- sp.select(dbif)
- sp.unregister_map(map, dbif)
+ sp.metadata.select(dbif)
+ # Collect SQL statements
+ statement += sp.unregister_map(map=map, dbif=dbif, execute=False)
+
# Unregister from temporal database
else:
# We need to update all datasets after the removement of maps
- map.select(dbif)
+ map.metadata.select(dbif)
datasets = map.get_registered_datasets(dbif)
# Store all unique dataset ids in a dictionary
if datasets:
for dataset in datasets:
update_dict[dataset["id"]] = dataset["id"]
- map.delete(dbif, update=False)
+ # Collect SQL statements
+ statement += map.delete(dbif=dbif, update=False, execute=False)
count += 1
+ # Execute the collected SQL statenents
+ sql_script = ""
+ sql_script += "BEGIN TRANSACTION;\n"
+ sql_script += statement
+ sql_script += "END TRANSACTION;"
+ # print sql_script
+
+ if tgis.dbmi.__name__ == "sqlite3":
+ dbif.cursor.executescript(statement)
+ else:
+ dbif.cursor.execute(statement)
+
# Update space time datasets
if name:
sp.update_from_registered_maps(dbif)
@@ -177,7 +195,7 @@
else:
break
- sp.select(dbif)
+ sp.metadata.select(dbif)
sp.update_from_registered_maps(dbif)
if connect == True:
More information about the grass-commit
mailing list