process_pending_bag.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 import sys
00004 import os
00005 import re
00006 from os import path
00007 import subprocess as sp
00008 import time
00009 
00010 if len(sys.argv)<2:
00011     print "Usage: process_pending_bag.py DIRECTORY"
00012     sys.exit(1)
00013 
00014 def sort_key(f):
00015     return -path.getmtime(f)
00016 
00017 def is_completed_bag(f):
00018     # Only process bags that are at least two hours old
00019     # this is a hacky way to avoid processing a bag that's currently being scp-ed over
00020     return re.match(".*\.bag", f) and \
00021            time.time()-path.getmtime(f)>7200
00022 
00023 def invoke_cmd(cmd):
00024     print("Invoking {0}".format(cmd))
00025     sp.check_call(cmd.split(' '))
00026     
00027     
00028 files = sorted(["{0}/{1}".format(sys.argv[1], f) for f in os.listdir(sys.argv[1])], key=sort_key)
00029 bags = filter(is_completed_bag, files)
00030 
00031 if bags:
00032     invoke_cmd("rosparam set current_bagfile tmp") # So delete never fails
00033     invoke_cmd("rosparam delete current_bagfile") # Avoid race condition on playbag.sh setting this fast enough
00034     invoke_cmd("rosrun semanticmodel bags_to_database.py {0}".format(bags[0]))
00035     invoke_cmd("mv {0} {1}".format(bags[0], "{0}/processed".format(sys.argv[1])))
00036 
00037 else:
00038     print("No bags to process")
00039     


semanticmodel
Author(s): Julian ("Mac") Mason
autogenerated on Thu Dec 12 2013 12:39:10