parser.add_argument('-d', '--description', metavar='DESCRIPTION', dest='description', type=str, default='') parser.add_argument('-a', '--author', metavar='AUTHOR_NAME', dest='author_name', type=str, default='') parser.add_argument('-e', '--email', metavar='EMAIL_ADDRESS', dest='author_email', type=str, default='') parser.add_argument('tags', metavar='TAGS', type=str, nargs='+', help='Tags to add to object description.') add_db_options(parser) args = parser.parse_args() if len(args.bag) < 1: parser.print_help() sys.exit(1) return args if "__main__" == __name__: args = parse_args() bag = open(args.bag, 'rb') obj = models.Object(object_name=args.object_name, description=args.description, tags=args.tags, author_name=args.author_name, author_email=args.author_email, ) if args.commit: bag_up = upload_bag(obj, bag, couchdb_url=args.db_root) print "Uploaded bag has id =", bag_up.id else: print 'Did not upload. Please pass --commit to actually upload the bag.'
import cgi import cgitb import tempfile import sys import couchdb import os from object_recognition import models, dbtools from object_recognition.ingest.bag_upload import upload_bag sys.stderr = sys.stdout form = cgi.FieldStorage() try: bag_item = form['bag_file'] except KeyError: print "Content-Type: text/plain\n" print "You must supply a bag file." sys.exit(-1) if bag_item.file and bag_item.done: obj = models.Object(object_name=form.getfirst('object_name', ''), description=form.getfirst('description', ''), tags=[x.strip() for x in form.getfirst('tags', '').split(',')], author_name=form.getfirst('author_name', 'J. Doe'), author_email=form.getfirst('author_email', 'j.doe@nowhere'), ) upload_bag(obj,bag_item.file) print "Content-Type: text/plain\n" print "Upload successful." else: print "Content-Type: text/plain\n" print "Could not upload."
# process all the bags in the folder for file_name in os.listdir(args.folder): if not file_name.endswith('.bag'): continue # persist the bad to the DB object_index = int(file_name[7:9]) print '------- %s' % file_name bag_path = convert_bag(args.folder, file_name) print 'uploading file "%s"' % file_name obj = models.Object(object_name=NIST_IDS[object_index], description=NIST_IDS[object_index], tags='nist', author_name='NIST', author_email='', ) bag_file = open(bag_path, 'rb') bag = upload_bag(obj, bag_file, args.db_root) # Compute the observations print 'computing the observations' command = [ '../../compute_observations.py', '-i', bag.id, '--db_root', args.db_root ] stdout, stderr = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0:2] print stdout print stderr if stderr: print stderr break
object_index = int(file_name[7:9]) print '------- %s' % file_name bag_path = convert_bag(args.folder, file_name) print 'uploading file "%s"' % file_name obj = models.Object( object_name=NIST_IDS[object_index], description=NIST_IDS[object_index], tags='nist', author_name='NIST', author_email='', ) bag_file = open(bag_path, 'rb') bag = upload_bag(obj, bag_file, args.db_root) # Compute the observations print 'computing the observations' command = [ '../../compute_observations.py', '-i', bag.id, '--db_root', args.db_root ] stdout, stderr = subprocess.Popen( command, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0:2] print stdout print stderr if stderr: print stderr break