#!/usr/bin/env python
# -*- coding: utf-8 -*-
############################################################################
#
# MODULE: v.pack
# AUTHOR(S): Luca Delucchi, Fondazione E. Mach (Italy)
#
# PURPOSE: Pack up a vector map, collect vector map elements => gzip
# COPYRIGHT: (C) 2011 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: Packs up a vector map and support files for copying.
#% keywords: vector, export, copying
#%end
#%option
#% key: input
#% type: string
#% gisprompt: old,vector,vector
#% description: Name of vector map to pack up
#% key_desc: name
#% required : yes
#%end
#%option G_OPT_F_OUTPUT
#% description: Name for output file (default is .pack)
#% required : no
#%end
#%flag
#% key: c
#% description: Switch the compression off
#%end
import os
import sys
import shutil
import tarfile
from grass.script import core as grass
from grass.script import vector as vector
def main():
infile = options['input']
compression_off = flags['c']
#search if file exist
gfile = grass.find_file(infile, element = 'vector')
if not gfile['name']:
grass.fatal(_("Vector map <%s> not found") % infile)
#split the name if there is the mapset name
if infile.find('@'):
infile = infile.split('@')[0]
#output name
if options['output']:
outfile = options['output']
else:
outfile = infile + '.pack'
#check if exists the output file
if os.path.exists(outfile):
if os.getenv('GRASS_OVERWRITE'):
grass.warning(_("Pack file <%s> already exists and will be overwritten") % outfile)
grass.try_remove(outfile)
else:
grass.fatal(_("option