[GRASS-SVN] r57523 - grass/trunk/lib/python/script
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed Aug 28 01:32:14 PDT 2013
Author: martinl
Date: 2013-08-28 01:32:13 -0700 (Wed, 28 Aug 2013)
New Revision: 57523
Modified:
grass/trunk/lib/python/script/core.py
Log:
pythonlib: add overwrite argument to create_location()
Modified: grass/trunk/lib/python/script/core.py
===================================================================
--- grass/trunk/lib/python/script/core.py 2013-08-28 08:10:38 UTC (rev 57522)
+++ grass/trunk/lib/python/script/core.py 2013-08-28 08:32:13 UTC (rev 57523)
@@ -1331,7 +1331,7 @@
def create_location(dbase, location, epsg=None, proj4=None, filename=None,
- wkt=None, datum=None, datum_trans=None, desc=None):
+ wkt=None, datum=None, datum_trans=None, desc=None, overwrite=False):
"""!Create new location
Raise ScriptError on error.
@@ -1345,15 +1345,26 @@
@param datum GRASS format datum code
@param datum_trans datum transformation parameters (used for epsg and proj4)
@param desc description of the location (creates MYNAME file)
+ @param overwrite True to overwrite location if exists (WARNING: ALL DATA from existing location ARE DELETED!)
"""
gisdbase = None
if epsg or proj4 or filename or wkt:
# FIXME: changing GISDBASE mid-session is not background-job safe
gisdbase = gisenv()['GISDBASE']
run_command('g.gisenv', set='GISDBASE=%s' % dbase)
+ # create dbase if not exists
if not os.path.exists(dbase):
os.mkdir(dbase)
+ # check if location already exists
+ if os.path.exists(os.path.join(dbase, location)):
+ if not overwrite:
+ warning(_("Location <%s> already exists. Operation canceled.") % location)
+ return
+ else:
+ warning(_("Location <%s> already exists and will be overwritten") % location)
+ shutil.rmtree(os.path.join(dbase, location))
+
kwargs = dict()
if datum:
kwargs['datum'] = datum
More information about the grass-commit
mailing list