batch_process.py
Go to the documentation of this file.
00001 #!/usr/bin/python
00002 """
00003 Copyright (c) 2012,
00004 Systems, Robotics and Vision Group
00005 University of the Balearican Islands
00006 All rights reserved.
00007 
00008 Redistribution and use in source and binary forms, with or without
00009 modification, are permitted provided that the following conditions are met:
00010     * Redistributions of source code must retain the above copyright
00011       notice, this list of conditions and the following disclaimer.
00012     * Redistributions in binary form must reproduce the above copyright
00013       notice, this list of conditions and the following disclaimer in the
00014       documentation and/or other materials provided with the distribution.
00015     * Neither the name of Systems, Robotics and Vision Group, University of 
00016       the Balearican Islands nor the names of its contributors may be used to 
00017       endorse or promote products derived from this software without specific 
00018       prior written permission.
00019 
00020 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00021 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00022 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00023 DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
00024 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00025 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00026 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00027 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00028 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00029 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00030 """
00031 
00032 
00033 PKG = 'bag_tools' # this package name
00034 
00035 import roslib; roslib.load_manifest(PKG)
00036 import rospy
00037 import os
00038 import sys
00039 import argparse
00040 import glob
00041 import subprocess
00042 
00043 def process(in_dir,out_dir,command):
00044     bagfiles = glob.glob(in_dir + "/*.bag")
00045     for bagfile in bagfiles:
00046         outbag = out_dir + "/" + os.path.basename(bagfile)
00047         if os.path.exists(outbag):
00048             print outbag, "exists, skipping."
00049         else:
00050             cmd = command.split()
00051             cmd.append("-i")
00052             cmd.append(bagfile)
00053             cmd.append("-o")
00054             cmd.append(outbag)
00055             subprocess.check_call(cmd)
00056 
00057 if __name__ == "__main__":
00058   parser = argparse.ArgumentParser(
00059       description='batch processes all bagfiles in INPUT_DIR, writing output to OUTPUT_DIR by calling given command with -i and -o arguments.')
00060   parser.add_argument('-i', metavar='INPUT_DIR', required=True, help='input directory with input bagfiles')
00061   parser.add_argument('-o', metavar='OUTPUT_DIR', required=True, help='output directory for bagfiles')
00062   parser.add_argument('-c', metavar='COMMAND', required=True, help='command to execute with each bagfile as input and with same name in output OUTPUT_DIR')
00063   args = parser.parse_args()
00064 
00065   try:
00066     process(args.i,args.o,args.c)
00067   except Exception, e:
00068     import traceback
00069     traceback.print_exc()


bag_tools
Author(s): Stephan Wirth , Miquel Massot
autogenerated on Mon Oct 6 2014 07:48:00