Go to the documentation of this file.00001
00002
00003 from optparse import OptionParser
00004 import os
00005 import sys
00006
00007 import roslib;
00008 roslib.load_manifest('slider_gui')
00009
00010 from ProgramQueue import ProgramQueue
00011
00012 if __name__ == '__main__':
00013 parser = OptionParser('usage: %prog [options] filename')
00014
00015 parser.add_option('-u', '--username', dest='username', default='admin', type='str', metavar='USERNAME',
00016 help='The username for the service calls')
00017 parser.add_option('-p', '--password', dest='password', default='admin', type='str', metavar='PASSWORD',
00018 help='The password for the service calls')
00019 parser.add_option('-l', '--label', dest='label', default='program', type='str', metavar='LABEL',
00020 help='The label for the uploaded program')
00021 parser.add_option('-r', '--run', dest='run', default=False, action="store_true",
00022 help='Run the program after uploading it')
00023
00024 options, args = parser.parse_args(sys.argv[1:])
00025 if len(args) != 1:
00026 parser.parse_args(['--help'])
00027
00028 filename = args[0]
00029
00030 if not os.path.isfile(filename):
00031 print 'could not find file %s' % filename
00032 sys.exit(-1)
00033
00034 program_data = open(filename, 'rb').read()
00035
00036 queue = ProgramQueue(options.username, options.password)
00037
00038 try:
00039 rc = queue.login()
00040 except:
00041 rc = False
00042 if not rc:
00043 sys.exit(1)
00044
00045 try:
00046 id = queue.upload_program(program_data, options.label)
00047 except:
00048 id = False
00049 if not id:
00050 sys.exit(2)
00051
00052 if options.run:
00053 try:
00054 rc = queue.run_program(id)
00055 except:
00056 rc = False
00057 if not rc:
00058 sys.exit(3)
00059
00060 try:
00061 rc = queue.logout()
00062 except:
00063 rc = False
00064 if not rc:
00065 sys.exit(4)
00066
00067 sys.exit(0)