NCast Presentation Recorder Reference Manual
try:
getopt_func = getopt.gnu_getopt
except AttributeError:
getopt_func = getopt.getopt
shortopts = 'dhp:v1:2:3:4:'
longopts = ('debug', 'help', 'pswd=', 'version', 'g1=', 'g2=', 'g3=', 'g4=')
try:
opts, args = getopt_func(sys.argv[1:], shortopts, longopts)
except getopt.GetoptError, e:
print >>sys.stderr, 'Error: %s' % str(e)
print >>sys.stderr
usage(sys.stderr)
sys.exit(1)
for optname, optvalue in opts:
if optname in ('-d', '--debug'):
debug = True
elif optname in ('-h', '--help'):
usage(sys.stdout)
sys.exit(0)
elif optname in ('-p', '--pswd'):
password = optvalue
elif optname in ('-v', '--version'):
print __version__
sys.exit(0)
elif optname in ('-1', '-2', '-3', '-4', '--g1', '--g2', '--g3', '--g4'):
imgnum = int(optname[-1])
if not os.path.exists(optvalue):
raise Exception('Invalid image file', optvalue)
images[imgnum] = optvalue
else:
raise Exception('BUG: should have caught %s but didn\'t' % `optname`)
if not images:
print >>sys.stderr, 'Error: no images specified'
print >>sys.stderr
usage(sys.stderr)
sys.exit(1)
if not args:
print >>sys.stderr, 'Error: no server specified'
print >>sys.stderr
usage(sys.stderr)
sys.exit(1)
server = args[0]
upload(server, username, password, images)
def usage(stream):
stream.write(__doc__)
def upload(server, username, password, filenames):
# build payload
print 'ncgo: building payload'
fields = {}
for key, filename in filenames.items():
fields['overlay_%d_file' % key] = {
'filename': os.path.basename(filename),
'value': file(filename).read(),
'content-type': get_content_type(filename),
}
content_type, data = encode_multipart_formdata(fields)
NCast Corporation
Revision 1.1
Page 94