[GRASS-SVN] r53062 - in grass-addons/grass7/general: . g.copyall
svn_grass at osgeo.org
svn_grass at osgeo.org
Sun Sep 2 16:09:56 PDT 2012
Author: cmbarton
Date: 2012-09-02 16:09:55 -0700 (Sun, 02 Sep 2012)
New Revision: 53062
Added:
grass-addons/grass7/general/g.copyall/
grass-addons/grass7/general/g.copyall/Makefile
grass-addons/grass7/general/g.copyall/g.copyall.html
grass-addons/grass7/general/g.copyall/g.copyall.py
Log:
script to copy all or filtered set of maps from one mapset to another
Added: grass-addons/grass7/general/g.copyall/Makefile
===================================================================
--- grass-addons/grass7/general/g.copyall/Makefile (rev 0)
+++ grass-addons/grass7/general/g.copyall/Makefile 2012-09-02 23:09:55 UTC (rev 53062)
@@ -0,0 +1,7 @@
+MODULE_TOPDIR = ../..
+
+PGM=g.copyall
+
+include $(MODULE_TOPDIR)/include/Make/Script.make
+
+default: script
Added: grass-addons/grass7/general/g.copyall/g.copyall.html
===================================================================
--- grass-addons/grass7/general/g.copyall/g.copyall.html (rev 0)
+++ grass-addons/grass7/general/g.copyall/g.copyall.html 2012-09-02 23:09:55 UTC (rev 53062)
@@ -0,0 +1,34 @@
+<h2>DESCRIPTION</h2>
+
+<em><b>g.copyall</b></em> copies maps/files of a specified from a selected mapset
+to the current working mapset. All maps/files can be copied or a subset of
+maps/files specified by a wildcard pattern or regular expression. Optionally, a
+prefix can be added to all files copied and vector topology can be rebuilt to match
+currently running version of GRASS.
+
+<h2>EXAMPLES</h2>
+
+Copy all raster maps from mapset "test" to current mapset and prefix them
+with "fromtest":
+
+<div class="code"><pre>
+g.copyall mapset=test output_prefix=fromtest
+</pre></div>
+
+Copy all vector maps beginning with "s" from mapset "test" to current mapset:
+
+<div class="code"><pre>
+g.copyall mapset=test datatype=vect filter=s*
+</pre></div>
+<h2>SEE ALSO</h2>
+
+<em>
+<a href="g.mlist">g.mlist</a>,
+<a href="g.copy">g.copy</a>,
+</em>
+
+
+<h2>AUTHOR</h2>
+
+Michael Barton (Arizona State University, USA)
+<p><i>Last changed: $Date: $</i>
Added: grass-addons/grass7/general/g.copyall/g.copyall.py
===================================================================
--- grass-addons/grass7/general/g.copyall/g.copyall.py (rev 0)
+++ grass-addons/grass7/general/g.copyall/g.copyall.py 2012-09-02 23:09:55 UTC (rev 53062)
@@ -0,0 +1,115 @@
+#!/usr/bin/env python
+
+############################################################################
+#
+# MODULE: g.copyall
+#
+# AUTHOR(S): Michael Barton (ASU)
+#
+# PURPOSE: Copies all or a filtered subset of GRASS files of a selected type
+# from another mapset to the current working mapset
+#
+# COPYRIGHT: (C) 2002-2012 by the GRASS Development Team
+#
+# This program is free software under the GNU General Public
+# License (>=v2). Read the file COPYING that comes with GRASS
+# for details.
+#
+#
+#############################################################################
+
+#%Module
+#% description: Copies all or a filtered subset of files of selected type from another mapset to the current working mapset
+#% keywords: copy
+#% keywords: general
+#% overwrite: yes
+#%End
+#%option G_OPT_M_MAPSET
+#% key: mapset
+#% description: Mapset to copy files from
+#% required: yes
+#%end
+#%option
+#% key: datatype
+#% type: string
+#% description: Choose type of GRASS data to copy
+#% options: rast,vect,labels,rast3d,region,group
+#% answer: rast
+#% required: yes
+#%end
+#%option
+#% key: filter
+#% type: string
+#% description: Search pattern to filter data files to copy
+#% required : no
+#%end
+#%option
+#% key: filter_type
+#% type: string
+#% description: Type of search pattern to use
+#% options: select all, wildcards,regular expressions,extended regular expressions
+#% answer: select all
+#% required : no
+#%end
+#%option
+#% key: output_prefix
+#% type: string
+#% description: Optional prefix for output raster maps
+#% required : no
+#%end
+#% Flag
+#% key: t
+#% description: Update vector topology to match current GRASS version
+#% End
+
+
+import grass.script as grass
+
+def main():
+ #
+ # define variables
+ #
+
+ overwrite = False
+ mapset = options['mapset'] # prefix for copied maps
+ datatype = options['datatype'] # prefix for copied maps
+ filter = options['filter'] # prefix for copied maps
+ filter_type = options['filter_type'] # prefix for copied maps
+ prefix = options['output_prefix'] # prefix for copied maps
+ datalist = [] #list of GRASS data files to copy
+ input = ''
+ output = ''
+ if grass.overwrite(): overwrite = True
+
+ if filter_type == 'select all': filter = '*'
+
+ filterflag = ''
+ if filter_type == 'regular expressions': filterflag = 'r'
+ if filter_type == 'extended regular expressions': filterflag = 'e'
+
+ #
+ # first run g.list to get list of maps to parse
+ #
+ l = grass.mlist_grouped(type=datatype, pattern=filter, check_search_path = True, flag=filterflag)
+ if mapset not in l:
+ grass.warning(_('You do not have access to mapset %s. Run g.mapsets (under settings menu) to change mapset access') % mapset)
+ return
+
+ datalist = l[mapset]
+
+ #
+ # then loop through the maps copying them with g.copy and optionally adding prefix
+ #
+ for input in datalist:
+ if prefix: output = '%s_%s' % (prefix, input)
+ else: output = input
+
+ params = {datatype: '%s@%s,%s' % (input, mapset, output)}
+ grass.run_command('g.copy', overwrite=overwrite, **params)
+
+ if datatype == 'vect' and flags['t']:
+ grass.run_command('v.build', map=output)
+
+if __name__ == "__main__":
+ options, flags = grass.parser()
+ main()
Property changes on: grass-addons/grass7/general/g.copyall/g.copyall.py
___________________________________________________________________
Added: svn:executable
+ *
More information about the grass-commit
mailing list