Commits

cvs2svn  committed 0861eb0

This commit was manufactured by cvs2svn to create tag 'r152b1'.

  • Participants
  • Parent commits a3c9ce2
  • Branches legacy-trunk
  • Tags v1.5.2b1

Comments (0)

Files changed (765)

File Demo/pdist/new

-test

File Demo/scripts/freeze.py

-#! /usr/local/bin/python
-
-# Given a Python script, create a binary that runs the script.
-# The binary is 100% independent of Python libraries and binaries.
-# It will not contain any Python source code -- only "compiled" Python
-# (as initialized static variables containing marshalled code objects).
-# It even does the right thing for dynamically loaded modules!
-# The module search path of the binary is set to the current directory.
-#
-# Some problems remain:
-# - It's highly non-portable, since it knows about paths and libraries
-#   (there's a customization section though, and it knows how to
-#   distinguish an SGI from a Sun SPARC system -- adding knowledge
-#   about more systems is left as an exercise for the reader).
-# - You need to have the Python source tree lying around as well as
-#   the "libpython.a" used to generate the Python binary.
-# - For scripts that use many modules it generates absurdly large
-#   files (frozen.c and config.o as well as the final binary),
-#   and is consequently rather slow.
-#
-# Caveats:
-# - The search for modules sometimes finds modules that are never
-#   actually imported since the code importing them is never executed.
-# - If an imported module isn't found, you get a warning but the
-#   process of freezing continues.  The binary will fail if it
-#   actually tries to import one of these modules.
-# - This often happens with the module 'mac', which module 'os' tries
-#   to import (to determine whether it is running on a Macintosh).
-#   You can ignore the warning about this.
-# - If the program dynamically reads or generates Python code and
-#   executes it, this code may reference built-in or library modules
-#   that aren't present in the frozen binary, and this will fail.
-# - Your program may be using external data files, e.g. compiled
-#   forms definitions (*.fd).  These aren't incorporated.  Since
-#   sys.path in the resulting binary only contains '.', if your
-#   program searches its data files along sys.path (as the 'flp'
-#   modules does to find its forms definitions), you may need to
-#   change the program to extend the search path or instruct its users
-#   to set the environment variable PYTHONPATH to point to your data
-#   files.
-#
-# Usage hints:
-# - If you have a bunch of scripts that you want to freeze, instead
-#   of freezing each of them separately, you might consider writing
-#   a tiny main script that looks at sys.argv[0] and then imports
-#   the corresponding module.  You can then make links to the
-#   frozen binary named after the various scripts you support.
-#   Pass the additional scripts as arguments after the main script.
-#   A minimal script to do this is the following.
-#       import sys, posixpath
-#       exec('import ' + posixpath.basename(sys.argv[0]) + '\n')
-
-
-import os
-import sys
-import regex
-import getopt
-import regsub
-import string
-import marshal
-
-# Function to join two pathnames with a slash in between
-j = os.path.join
-
-##################################
-# START OF CONFIGURATION SECTION #
-##################################
-
-# Attempt to guess machine architecture
-if os.path.exists('/usr/lib/libgl_s'): ARCH = 'sgi'
-elif os.path.exists('/etc/issue'): ARCH = 'sequent'
-else: ARCH = 'sun4'
-
-# Site parametrizations (change to match your site)
-CC = 'cc'				# C compiler
-TOP = '/ufs/guido/src'			# Parent of all source trees
-PYTHON = j(TOP, 'python')		# Top of the Python source tree
-SRC = j(PYTHON, 'src')			# Python source directory
-BLD = j(PYTHON, 'build.' + ARCH)	# Python build directory
-#BLD = SRC				# Use this if you build in SRC
-
-LIBINST = '/ufs/guido/src/python/irix4/tmp/lib/python/lib' # installed libraries
-INCLINST = '/ufs/guido/src/python/irix4/tmp/include/Py' # installed include files
-
-# Other packages (change to match your site)
-DL = j(TOP, 'dl')			# Top of the dl source tree
-DL_DLD = j(TOP, 'dl-dld')		# The dl-dld source directory
-DLD = j(TOP, 'dld-3.2.3')		# The dld source directory
-FORMS = j(TOP, 'forms')			# Top of the FORMS source tree
-STDWIN = j(TOP, 'stdwin')		# Top of the STDWIN source tree
-READLINE = j(TOP, 'readline.' + ARCH)	# Top of the GNU Readline source tree
-SUN_X11 = '/usr/local/X11R5/lib/libX11.a'
-
-# File names (usually no need to change)
-LIBP = [				# Main Python libraries
-        j(LIBINST, 'libPython.a'),
-        j(LIBINST, 'libParser.a'),
-        j(LIBINST, 'libObjects.a'),
-        j(LIBINST, 'libModules.a')
-       ]
-CONFIG_IN = j(LIBINST, 'config.c.in')	# Configuration source file
-FMAIN = j(LIBINST, 'frozenmain.c')	# Special main source file
-
-# Libraries needed when linking.  First tuple item is built-in module
-# for which it is needed (or '*' for always), rest are ld arguments.
-# There is a separate list per architecture.
-libdeps_sgi = [ \
-	  ('stdwin',	j(STDWIN, 'Build/' + ARCH + '/x11/lib/lib.a')), \
-	  ('fl',	j(FORMS, 'FORMS/libforms.a'), '-lfm_s'), \
-	  ('*',		j(READLINE, 'libreadline.a'), '-ltermcap'), \
-	  ('al',	'-laudio'), \
-	  ('sv',	'-lsvideo', '-lXext'), \
-	  ('cd',	'-lcdaudio', '-lds'), \
-	  ('cl',	'-lcl'), \
-	  ('imgfile',	'-limage', '-lgutil', '-lm'), \
-	  ('mpz',	'/ufs/guido/src/gmp/libgmp.a'), \
-	  ('*',		'-lsun'), \
-	  ('*',		j(DL, 'libdl.a'), '-lmld'), \
-	  ('*',		'-lmpc'), \
-	  ('fm',	'-lfm_s'), \
-	  ('gl',	'-lgl_s', '-lX11_s'), \
-	  ('stdwin',	'-lX11_s'), \
-	  ('*',		'-lm'), \
-	  ('*',		'-lc_s'), \
-	  ]
-libdeps_sun4 = [ \
-	  ('*',		'-Bstatic'), \
-	  ('stdwin',	j(STDWIN, 'Build/' + ARCH + '/x11/lib/lib.a')), \
-	  ('*',		j(READLINE, 'libreadline.a')), \
-	  ('*',		'-lm'), \
-	  ('*',		j(DL_DLD,'libdl.a'), j(DLD,'libdld.a')), \
-	  ('*',		SUN_X11), \
-	  ('*',		'-ltermcap'), \
-	  ('*',		'-lc'), \
-	  ]
-libdeps_sequent = [ \
-	  ('*',		j(LIBINST, 'libreadline.a'), '-ltermcap'), \
-	  ('*',		'-lsocket'), \
-	  ('*',		'-linet'), \
-	  ('*',		'-lnsl'), \
-	  ('*',		'-lm'), \
-	  ('*',		'-lc'), \
-	  ]
-libdeps = eval('libdeps_' + ARCH)
-
-################################
-# END OF CONFIGURATION SECTION #
-################################
-
-# Exception used when scanfile fails
-NoSuchFile = 'NoSuchFile'
-
-# Global options
-quiet = 0				# -q
-verbose = 0				# -v
-noexec = 0				# -n
-nowrite = 0				# -N
-ofile = 'a.out'				# -o file
-
-# Main program -- argument parsing etc.
-def main():
-	global quiet, verbose, noexec, nowrite, ofile
-	try:
-		opts, args = getopt.getopt(sys.argv[1:], 'nNo:qv')
-	except getopt.error, msg:
-		usage(str(msg))
-		sys.exit(2)
-	for o, a in opts:
-		if o == '-n': noexec = 1
-		if o == '-N': nowrite = 1
-		if o == '-o': ofile = a
-		if o == '-q': verbose = 0; quiet = 1
-		if o == '-v': verbose = verbose + 1; quiet = 0
-	if len(args) < 1:
-		usage('please pass at least one file argument')
-		sys.exit(2)
-	process(args[0], args[1:])
-
-# Print usage message to stderr
-def usage(*msgs):
-	sys.stdout = sys.stderr
-	for msg in msgs: print msg
-	print 'Usage: freeze [options] scriptfile [modulefile ...]'
-	print '-n      : generate the files but don\'t compile and link'
-	print '-N      : don\'t write frozen.c (do compile unless -n given)'
-	print '-o file : binary output file (default a.out)'
-	print '-q      : quiet (no messages at all except errors)'
-	print '-v      : verbose (lots of extra messages)'
-
-# Process the script file
-def process(filename, addmodules):
-	global noexec
-	#
-	if not quiet: print 'Computing needed modules ...'
-	todo = {}
-	todo['__main__'] = filename
-	for name in addmodules:
-		mod = os.path.basename(name)
-		if mod[-3:] == '.py': mod = mod[:-3]
-		todo[mod] = name
-	try:
-		dict = closure(todo)
-	except NoSuchFile, filename:
-		sys.stderr.write('Can\'t open file %s\n' % filename)
-		sys.exit(1)
-	#
-	mods = dict.keys()
-	mods.sort()
-	#
-	if verbose:
-		print '%-15s %s' % ('Module', 'Filename')
-		for mod in mods:
-			print '%-15s %s' % (`mod`, dict[mod])
-	#
-	if not quiet: print 'Looking for dynamically linked modules ...'
-	dlmodules = []
-	objs = []
-	libs = []
-	for mod in mods:
-		if dict[mod][-2:] == '.o':
-			if verbose: print 'Found', mod, dict[mod]
-			dlmodules.append(mod)
-			objs.append(dict[mod])
-			libsname = dict[mod][:-2] + '.libs'
-			try:
-				f = open(libsname, 'r')
-			except IOError:
-				f = None
-			if f:
-				libtext = f.read()
-				f.close()
-				for lib in string.split(libtext):
-					if lib in libs: libs.remove(lib)
-					libs.append(lib)
-	#
-	if not nowrite:
-		if not quiet: print 'Writing frozen.c ...'
-		writefrozen('frozen.c', dict)
-	else:
-		if not quiet: print 'NOT writing frozen.c ...'
-	#
-##	if not dlmodules:
-	if 0:
-		config = CONFIG
-		if not quiet: print 'Using existing', config, '...'
-	else:
-		config = 'tmpconfig.c'
-		if nowrite:
-			if not quiet: print 'NOT writing config.c ...'
-		else:
-			if not quiet:
-				print 'Writing config.c with dl modules ...'
-			f = open(CONFIG_IN, 'r')
-			g = open(config, 'w')
-			m1 = regex.compile('-- ADDMODULE MARKER 1 --')
-			m2 = regex.compile('-- ADDMODULE MARKER 2 --')
-			builtinmodules = []
-			stdmodules = ('sys', '__main__', '__builtin__',
-				      'marshal')
-			todomodules = builtinmodules + dlmodules
-			for mod in dict.keys():
-				if dict[mod] == '<builtin>' and \
-					  mod not in stdmodules:
-					builtinmodules.append(mod)
-			while 1:
-				line = f.readline()
-				if not line: break
-				g.write(line)
-				if m1.search(line) >= 0:
-					if verbose: print 'Marker 1 ...'
-					for mod in todomodules:
-						g.write('extern void init' + \
-						  mod + '();\n')
-				if m2.search(line) >= 0:
-					if verbose: print 'Marker 2 ...'
-					for mod in todomodules:
-						g.write('{"' + mod + \
-						  '", init' + mod + '},\n')
-			g.close()
-	#
-	if not quiet:
-		if noexec: print 'Generating compilation commands ...'
-		else: print 'Starting compilation ...'
-	defs = ['-DNO_MAIN', '-DUSE_FROZEN', '-DPYTHONPATH=\'"."\'']
-	#
-	incs = ['-I.', '-I' + INCLINST]
-	if dict.has_key('stdwin'):
-		incs.append('-I' + j(STDWIN, 'H'))
-	#
-	srcs = [config, FMAIN]
-	#
-	if type(LIBP) == type(''):
-		libs.append(LIBP)
-	else:
-		for lib in LIBP:
-			libs.append(lib)
-	for item in libdeps:
-		m = item[0]
-		if m == '*' or dict.has_key(m):
-			for l in item[1:]:
-				if l in libs: libs.remove(l)
-				libs.append(l)
-	#
-	sts = 0
-	#
-	cmd = CC + ' -c'
-	cmd = cmd + ' ' + string.join(defs)
-	cmd = cmd + ' ' + string.join(incs)
-	cmd = cmd + ' ' + string.join(srcs)
-	print cmd
-	#
-	if not noexec:
-		sts = os.system(cmd)
-		if sts:
-			print 'Exit status', sts, '-- turning on -n'
-			noexec = 1
-	#
-	for s in srcs:
-		s = os.path.basename(s)
-		if s[-2:] == '.c': s = s[:-2]
-		o = s + '.o'
-		objs.insert(0, o)
-	#
-	cmd = CC
-	cmd = cmd + ' ' + string.join(objs)
-	cmd = cmd + ' ' + string.join(libs)
-	cmd = cmd + ' -o ' + ofile
-	print cmd
-	#
-	if not noexec:
-		sts = os.system(cmd)
-		if sts:
-			print 'Exit status', sts
-		else:
-			print 'Done.'
-	#
-	if not quiet and not noexec and sts == 0:
-		print 'Note: consider this:'; print '\tstrip', ofile
-	#
-	sys.exit(sts)
-
-
-# Generate code for a given module
-def makecode(filename):
-	if filename[-2:] == '.o':
-		return None
-	try:
-		f = open(filename, 'r')
-	except IOError:
-		return None
-	if verbose: print 'Making code from', filename, '...'
-	text = f.read()
-	code = compile(text, filename, 'exec')
-	f.close()
-	return marshal.dumps(code)
-
-
-# Write the C source file containing the frozen Python code
-def writefrozen(filename, dict):
-	f = open(filename, 'w')
-	codelist = []
-	for mod in dict.keys():
-		codestring = makecode(dict[mod])
-		if codestring is not None:
-			codelist.append((mod, codestring))
-	write = sys.stdout.write
-	save_stdout = sys.stdout
-	try:
-		sys.stdout = f
-		for mod, codestring in codelist:
-			if verbose:
-				write('Writing initializer for %s\n'%mod)
-			print 'static unsigned char M_' + mod + '[' + \
-				  str(len(codestring)) + '+1] = {'
-			for i in range(0, len(codestring), 16):
-				for c in codestring[i:i+16]:
-					print str(ord(c)) + ',',
-				print
-			print '};'
-		print 'struct frozen {'
-		print '  char *name;'
-		print '  unsigned char *code;'
-		print '  int size;'
-		print '} frozen_modules[] = {'
-		for mod, codestring in codelist:
-			print '  {"' + mod + '",',
-			print 'M_' + mod + ',',
-			print str(len(codestring)) + '},'
-		print '  {0, 0, 0} /* sentinel */'
-		print '};'
-	finally:
-		sys.stdout = save_stdout
-	f.close()
-
-
-# Determine the names and filenames of the modules imported by the
-# script, recursively.  This is done by scanning for lines containing
-# import statements.  (The scanning has only superficial knowledge of
-# Python syntax and no knowledge of semantics, so in theory the result
-# may be incorrect -- however this is quite unlikely if you don't
-# intentionally obscure your Python code.)
-
-# Compute the closure of scanfile() -- special first file because of script
-def closure(todo):
-	done = {}
-	while todo:
-		newtodo = {}
-		for modname in todo.keys():
-			if not done.has_key(modname):
-				filename = todo[modname]
-				if filename is None:
-					filename = findmodule(modname)
-				done[modname] = filename
-				if filename in ('<builtin>', '<unknown>'):
-					continue
-				modules = scanfile(filename)
-				for m in modules:
-					if not done.has_key(m):
-						newtodo[m] = None
-		todo = newtodo
-	return done
-
-# Scan a file looking for import statements
-importstr = '\(^\|:\)[ \t]*import[ \t]+\([a-zA-Z0-9_, \t]+\)'
-fromstr   = '\(^\|:\)[ \t]*from[ \t]+\([a-zA-Z0-9_]+\)[ \t]+import[ \t]+'
-isimport = regex.compile(importstr)
-isfrom = regex.compile(fromstr)
-def scanfile(filename):
-	allmodules = {}
-	try:
-		f = open(filename, 'r')
-	except IOError, msg:
-		raise NoSuchFile, filename
-	while 1:
-		line = f.readline()
-		if not line: break # EOF
-		while line[-2:] == '\\\n': # Continuation line
-			line = line[:-2] + ' '
-			line = line + f.readline()
-		if isimport.search(line) >= 0:
-			rawmodules = isimport.group(2)
-			modules = string.splitfields(rawmodules, ',')
-			for i in range(len(modules)):
-				modules[i] = string.strip(modules[i])
-		elif isfrom.search(line) >= 0:
-			modules = [isfrom.group(2)]
-		else:
-			continue
-		for mod in modules:
-			allmodules[mod] = None
-	f.close()
-	return allmodules.keys()
-
-# Find the file containing a module, given its name; None if not found
-builtins = sys.builtin_module_names + ['sys']
-def findmodule(modname):
-	if modname in builtins: return '<builtin>'
-	for dirname in sys.path:
-		dlfullname = os.path.join(dirname, modname + 'module.o')
-		try:
-			f = open(dlfullname, 'r')
-		except IOError:
-			f = None
-		if f:
-			f.close()
-			return dlfullname
-		fullname = os.path.join(dirname, modname + '.py')
-		try:
-			f = open(fullname, 'r')
-		except IOError:
-			continue
-		f.close()
-		return fullname
-	if not quiet:
-		sys.stderr.write('Warning: module %s not found\n' % modname)
-	return '<unknown>'
-
-
-# Call the main program
-main()

File Demo/sgi/video/IN.py

-IPPROTO_IP = 0
-IPPROTO_ICMP = 1
-IPPROTO_IGMP = 2
-IPPROTO_GGP = 3
-IPPROTO_TCP = 6
-IPPROTO_EGP = 8
-IPPROTO_PUP = 12
-IPPROTO_UDP = 17
-IPPROTO_IDP = 22
-IPPROTO_TP = 29
-IPPROTO_XTP = 36
-IPPROTO_EON = 80
-IPPROTO_RAW = 255
-IPPROTO_MAX = 256
-IPPORT_RESERVED = 1024
-IPPORT_USERRESERVED = 5000
-IN_CLASSA_NET = 0xff000000
-IN_CLASSA_NSHIFT = 24
-IN_CLASSA_HOST = 0x00ffffff
-IN_CLASSA_MAX = 128
-IN_CLASSB_NET = 0xffff0000
-IN_CLASSB_NSHIFT = 16
-IN_CLASSB_HOST = 0x0000ffff
-IN_CLASSB_MAX = 65536
-IN_CLASSC_NET = 0xffffff00
-IN_CLASSC_NSHIFT = 8
-IN_CLASSC_HOST = 0x000000ff
-IN_CLASSD_NET = 0xf0000000
-IN_CLASSD_NSHIFT = 28
-IN_CLASSD_HOST = 0x0fffffff
-INADDR_ANY = 0x00000000
-INADDR_BROADCAST = 0xffffffff
-INADDR_LOOPBACK = 0x7F000001
-INADDR_UNSPEC_GROUP = 0xe0000000
-INADDR_ALLHOSTS_GROUP = 0xe0000001
-INADDR_MAX_LOCAL_GROUP = 0xe00000ff
-INADDR_NONE = 0xffffffff
-IN_LOOPBACKNET = 127
-IP_OPTIONS = 1
-IP_HDRINCL = 7
-IP_TOS = 8
-IP_TTL = 9
-IP_RECVOPTS = 10
-IP_RECVRETOPTS = 11
-IP_RECVDSTADDR = 12
-IP_RETOPTS = 13
-IP_MULTICAST_IF = 2
-IP_MULTICAST_TTL = 3
-IP_MULTICAST_LOOP = 4
-IP_ADD_MEMBERSHIP = 5
-IP_DROP_MEMBERSHIP = 6
-IP_DEFAULT_MULTICAST_TTL = 1
-IP_DEFAULT_MULTICAST_LOOP = 1
-IP_MAX_MEMBERSHIPS = 20

File Demo/sgi/video/Makefile

-all:	v2i i2v
-
-v2i:	v2i.o
-	$(CC) v2i.o -limage -o v2i
-
-i2v:	i2v.o
-	$(CC) i2v.o -limage -o i2v

File Demo/sgi/video/Vrecc.py

-#! /ufs/guido/bin/sgi/python-405
-#! /ufs/guido/bin/sgi/python
-
-# Capture a continuous CMIF movie using the Indigo video library and board
-
-
-# Usage:
-#
-# makemovie [-r rate] [-w width] [moviefile]
-
-
-# Options:
-#
-# -r rate       : capture 1 out of every 'rate' frames (default 1)
-# -w width      : initial window width (default interactive placement)
-# -d		: drop fields if needed
-# -g bits	: greyscale (2, 4 or 8 bits)
-# -G            : 2-bit greyscale dithered
-# -m		: monochrome dithered
-# -M value	: monochrome tresholded with value
-# -f		: Capture fields (in stead of frames)
-# -n number     : Capture 'number' fields (default 60)
-# 
-# moviefile     : here goes the movie data (default film.video);
-#                 the format is documented in cmif-film.ms
-
-
-# User interface:
-#
-# Start the application.  Resize the window to the desired movie size.
-# Press the left mouse button to start recording, release it to end
-# recording.  You can record as many times as you wish, but each time
-# you overwrite the output file(s), so only the last recording is
-# kept.
-#
-# Press ESC or select the window manager Quit or Close window option
-# to quit.  If you quit before recording anything, the output file(s)
-# are not touched.
-
-
-import sys
-sys.path.append('/ufs/guido/src/video')
-import sv, SV
-import VFile
-import gl, GL, DEVICE
-import al, AL
-import time
-import posix
-import getopt
-import string
-import imageop
-import sgi
-
-# Main program
-
-def main():
-	format = SV.RGB8_FRAMES
-	rate = 1
-	width = 0
-	drop = 0
-	mono = 0
-	grey = 0
-	greybits = 0
-	monotreshold = -1
-	fields = 0
-	number = 60
-
-	opts, args = getopt.getopt(sys.argv[1:], 'r:w:dg:mM:Gfn:')
-	for opt, arg in opts:
-		if opt == '-r':
-			rate = string.atoi(arg)
-			if rate < 2:
-				sys.stderr.write('-r rate must be >= 2\n')
-				sys.exit(2)
-		elif opt == '-w':
-			width = string.atoi(arg)
-		elif opt == '-d':
-			drop = 1
-		elif opt == '-g':
-			grey = 1
-			greybits = string.atoi(arg)
-			if not greybits in (2,4,8):
-				print 'Only 2, 4 or 8 bit greyscale supported'
-		elif opt == '-G':
-			grey = 1
-			greybits = -2
-		elif opt == '-m':
-			mono = 1
-		elif opt == '-M':
-			mono = 1
-			monotreshold = string.atoi(arg)
-		elif opt == '-f':
-			fields = 1
-		elif opt == '-n':
-			number = string.atoi(arg)
-
-	if args[2:]:
-		sys.stderr.write('usage: Vrec [options] [file]\n')
-		sys.exit(2)
-
-	if args:
-		filename = args[0]
-	else:
-		filename = 'film.video'
-
-	v = sv.OpenVideo()
-	# Determine maximum window size based on signal standard
-	param = [SV.BROADCAST, 0]
-	v.GetParam(param)
-	if param[1] == SV.PAL:
-		x = SV.PAL_XMAX
-		y = SV.PAL_YMAX
-	elif param[1] == SV.NTSC:
-		x = SV.NTSC_XMAX
-		y = SV.NTSC_YMAX
-	else:
-		print 'Unknown video standard', param[1]
-		sys.exit(1)
-
-	gl.foreground()
-	gl.maxsize(x, y)
-	gl.keepaspect(x, y)
-	gl.stepunit(8, 6)
-	if width:
-		gl.prefsize(width, width*3/4)
-	win = gl.winopen(filename)
-	if width:
-		gl.maxsize(x, y)
-		gl.keepaspect(x, y)
-		gl.stepunit(8, 6)
-		gl.winconstraints()
-	x, y = gl.getsize()
-	print x, 'x', y
-
-	v.SetSize(x, y)
-
-	if drop:
-		param = [SV.FIELDDROP, 1, SV.GENLOCK, SV.GENLOCK_OFF]
-	else:
-		param = [SV.FIELDDROP, 0, SV.GENLOCK, SV.GENLOCK_ON]
-	if mono or grey:
-		param = param+[SV.COLOR, SV.MONO, SV.INPUT_BYPASS, 1]
-	else:
-		param = param+[SV.COLOR, SV.DEFAULT_COLOR, SV.INPUT_BYPASS, 0]
-	v.SetParam(param)
-
-	v.BindGLWindow(win, SV.IN_REPLACE)
-
-	gl.qdevice(DEVICE.LEFTMOUSE)
-	gl.qdevice(DEVICE.WINQUIT)
-	gl.qdevice(DEVICE.WINSHUT)
-	gl.qdevice(DEVICE.ESCKEY)
-
-	print 'Press left mouse to start recording'
-
-	while 1:
-		dev, val = gl.qread()
-		if dev == DEVICE.LEFTMOUSE:
-			if val == 1:
-				info = format, x, y, number, rate
-				record(v, info, filename, mono, grey, \
-					  greybits, monotreshold, fields)
-		elif dev == DEVICE.REDRAW:
-			# Window resize (or move)
-			x, y = gl.getsize()
-			print x, 'x', y
-			v.SetSize(x, y)
-			v.BindGLWindow(win, SV.IN_REPLACE)
-		elif dev in (DEVICE.ESCKEY, DEVICE.WINQUIT, DEVICE.WINSHUT):
-			# Quit
-			v.CloseVideo()
-			gl.winclose(win)
-			break
-
-
-# Record until the mouse is released (or any other GL event)
-# XXX audio not yet supported
-
-def record(v, info, filename, mono, grey, greybits, monotreshold, fields):
-	import thread
-	format, x, y, number, rate = info
-	fps = 59.64 # Fields per second
-	# XXX (Strange: need fps of Indigo monitor, not of PAL or NTSC!)
-	tpf = 1000.0 / fps # Time per field in msec
-	#
-	# Go grab
-	#
-	gl.wintitle('(rec) ' + filename)
-	try:
-		ninfo, data, bitvec = v.CaptureBurst(info)
-	except sv.error, arg:
-		print 'CaptureBurst failed:', arg
-		print 'info:', info
-		gl.wintitle(filename)
-		return
-	gl.wintitle('(save) '+ filename)
-	#
-	# Check results
-	#
-	if info <> ninfo:
-		print 'Sorry, format changed.'
-		print 'Wanted:',info
-		print 'Got   :',ninfo
-		gl.wintitle(filename)
-		return
-	# print bitvec
-	if x*y*number <> len(data):
-		print 'Funny data length: wanted',x,'*',y,'*', number,'=',\
-			  x*y*number,'got',len(data)
-		gl.wintitle(filename)
-		return
-	#
-	# Save
-	#
-	if filename:
-		#
-		# Construct header and write it
-		#
-		vout = VFile.VoutFile().init(filename)
-		if mono:
-			vout.format = 'mono'
-		elif grey and greybits == 8:
-			vout.format = 'grey'
-		elif grey:
-			vout.format = 'grey'+`abs(greybits)`
-		else:
-			vout.format = 'rgb8'
-		vout.width = x
-		vout.height = y
-		if fields:
-			vout.packfactor = (1,-2)
-		else:
-			print 'Sorry, can only save fields at the moment'
-			gl.wintitle(filename)
-			return
-		vout.writeheader()
-		#
-		# Compute convertor, if needed
-		#
-		convertor = None
-		if grey:
-			if greybits == 2:
-				convertor = imageop.grey2grey2
-			elif greybits == 4:
-				convertor = imageop.grey2grey4
-			elif greybits == -2:
-				convertor = imageop.dither2grey2
-		fieldsize = x*y/2
-		nskipped = 0
-		realframeno = 0
-		tpf = 1000 / 50.0     #XXXX
-		for frameno in range(0, number*2):
-			if frameno <> 0 and \
-				  bitvec[frameno] == bitvec[frameno-1]:
-				nskipped = nskipped + 1
-				continue
-			#
-			# Save field.
-			# XXXX Works only for fields and top-to-bottom
-			#
-			start = frameno*fieldsize
-			field = data[start:start+fieldsize]
-			if convertor:
-				field = convertor(field, x, y)
-			elif mono and monotreshold >= 0:
-				field = imageop.grey2mono(field, x, y, \
-					  1, monotreshold)
-			elif mono:
-				field = imageop.dither2mono(field, x, y)
-			vout.writeframe(int(realframeno*tpf), field, None)
-		print 'Skipped',nskipped,'duplicate frames'
-		vout.close()
-			
-	gl.wintitle('(done) ' + filename)
-
-# Don't forget to call the main program
-
-try:
-	main()
-except KeyboardInterrupt:
-	print '[Interrupt]'

File Demo/sgi/video/cam.py

-import sys
-from socket import *
-from gl import *
-from GL import *
-from DEVICE import *
-from time import millitimer
-
-HS = 40 # Header size (must be same as in tv.py)
-
-# Rely on UDP packet (de)fragmentation for smoother images
-# (Changed for broadcast)
-MAX = 16000
-
-PF = 2 # Default packfactor
-
-# Default receiver station is voorn.
-# Kwik has no yellow pages, so...
-HOST = '192.16.201.121'
-PORT = 5555
-
-if sys.argv[1:]:
-	PF = eval(sys.argv[1])
-
-if sys.argv[2:]:
-	HOST = sys.argv[2]
-	if HOST == 'all':
-		HOST = '<broadcast>'
-		MAX = 1400
-
-PF2 = PF*PF
-
-def main():
-	centerx, centery = 400, 300
-
-	foreground()
-	wid = winopen('cam')
-	RGBmode()
-	doublebuffer()
-	gconfig()
-	qdevice(ESCKEY)
-
-	w, h = getsize()
-	ortho2(0, w, 0, h)
-	w = w/PF*PF
-	h = h/PF*PF
-
-	readsource(SRC_FRAMEGRABBER)
-
-	s = socket(AF_INET, SOCK_DGRAM)
-	if HOST == '<broadcast>':
-		s.allowbroadcast(1)
-	addr = HOST, PORT
-
-	bytesperline = w/PF2
-	linesperchunk = MAX/bytesperline
-	linesperchunk = linesperchunk/PF*PF
-	nchunks = (h+linesperchunk-1)/linesperchunk
-
-	print 'MAX=', MAX,
-	print 'linesperchunk=', linesperchunk,
-	print 'nchunks=', nchunks,
-	print 'w=', w, 'h=', h
-
-	x1, x2 = 0, w-1
-
-	t1 = millitimer()
-	nframes = 0
-	fps = 0
-
-	msg = ''
-
-	while 1:
-		while qtest():
-			dev, val = qread()
-			if dev == REDRAW:
-				reshapeviewport()
-				w, h = getsize()
-				ortho2(0, w, 0, h)
-				w = w/PF*PF
-				h = h/PF*PF
-
-				bytesperline = w/PF2
-				linesperchunk = MAX/bytesperline
-				linesperchunk = linesperchunk/PF*PF
-				nchunks = (h+linesperchunk-1)/linesperchunk
-
-				print 'MAX=', MAX,
-				print 'linesperchunk=', linesperchunk,
-				print 'nchunks=', nchunks,
-				print 'w=', w, 'h=', h
-
-				x1, x2 = 0, w-1
-
-				fps = 0
-
-			elif dev == ESCKEY:
-				winclose(wid)
-				return
-
-		readsource(SRC_FRAMEGRABBER)
-
-		nframes = nframes+1
-		if nframes >= fps:
-			t2 = millitimer()
-			if t2 <> t1:
-				fps = int(10000.0*nframes/(t2-t1)) * 0.1
-				msg = `fps` +  ' frames/sec'
-				t1 = t2
-				nframes = 0
-
-		RGBcolor(255,255,255)
-		cmov2i(9,9)
-		charstr(msg)
-
-		swapbuffers()
-		rectcopy(centerx-w/2, centery-w/2, centerx+w/2, centery+w/2, 0, 0)
-
-		for i in range(nchunks):
-			y1 = i*linesperchunk
-			y2 = y1 + linesperchunk-1
-			if y2 >= h: y2 = h-1
-			data = lrectread(x1, y1, x2, y2)
-			data2 = packrect(x2-x1+1, y2-y1+1, PF, data)
-			prefix = `w, h, PF, x1, y1, x2, y2`
-			prefix = prefix + ' ' * (HS-len(prefix))
-			data3 = prefix + data2
-			s.sendto(data3, addr)
-
-main()

File Demo/sgi/video/camcorder.py

-from gl import *
-from GL import *
-from DEVICE import *
-import time
-import sys
-import getopt
-import socket
-import posix
-import vtime
-
-# Preallocation parameter
-PREALLOC = 4 # Megabyte
-
-# Sync audio parameters
-SYNCPORT = 10000
-CTLPORT = 10001
-
-from vpregs import *
-
-class Struct(): pass
-epoch = Struct()
-
-def getvideosize():
-    w = getvideo(VP_WIDTH)
-    h = getvideo(VP_HEIGHT)
-    print 'WIDTH,HEIGHT:', w, h
-    print 'GB{X,Y}ORG:', getvideo(VP_GBXORG), getvideo(VP_GBYORG)
-    print 'FB{X,Y}ORG:',  getvideo(VP_FBXORG), getvideo(VP_FBYORG)
-    x = 0
-    y = 0
-    return x,y,w,h
-
-framelist = []
-
-def prealloc(w, h):
-	nbytes = w*h*4
-	limit = PREALLOC*1024*1024
-	total = 0
-	list = []
-	print 'Prealloc to', PREALLOC, 'Megabytes...'
-	while total+nbytes <=  limit:
-		list.append('x'*nbytes)
-		total = total + nbytes
-	print 'Done.'
-
-def grabframe(f,x,y,w,h,pf):
-    readsource(SRC_FRONT)
-    if pf:
-    	w = w/pf*pf
-    	h = h/pf*pf
-    data = lrectread(x,y,x+w-1,y+h-1)
-    t = time.millitimer()-epoch.epoch
-    framelist.append(data, t)
-    readsource(SRC_FRAMEGRABBER)
-
-def saveframes(f, w, h, pf):
-	for data, t in framelist:
-		if pf:
-		    	w = w/pf*pf
-		    	h = h/pf*pf
-			data = packrect(w,h,pf,data)
-		f.write(`t` + ',' + `len(data)` + '\n')
-		f.write(data)
-	framelist[:] = []
-
-def saveframe(f,x,y,w,h,pf, notime):
-    readsource(SRC_FRONT)
-    if pf:
-    	w = w/pf*pf
-    	h = h/pf*pf
-    data = lrectread(x,y,x+w-1,y+h-1)
-    if pf: data = packrect(w,h,pf,data)
-    if notime: t = 0
-    else: t = time.millitimer()-epoch.epoch
-    f.write(`t` + ',' + `len(data)` + '\n')
-    f.write(data)
-    readsource(SRC_FRAMEGRABBER)
-
-def drawframe(x,y,w,h,col):
-    drawmode(OVERDRAW)
-    color(col)
-    bgnline()
-    v2i(x-1,y-1) ; v2i(x+w,y-1); v2i(x+w,y+h); v2i(x-1,y+h); v2i(x-1,y-1)
-    endline()
-    drawmode(NORMALDRAW)
-
-def usage():
-    sys.stderr.write('Usage: camcorder ' + \
-	'[-c] [-p packfactor] [-a audiomachine [-s]] [outputfile]\n')
-    sys.exit(2)
-
-def wrheader(f, w, h, pf):
-    	f.write('CMIF video 1.0\n')
-	f.write(`w,h,pf` + '\n')
-	print 'width,height,pf:', w, h, pf,
-	if pf == 0: pf = 4
-	print '(i.e.,', w*h*pf, 'bytes/frame)'
-
-def main():
-    foreground()
-    pf = 2
-    ausync = 0
-    austart = 0
-    optlist, args = getopt.getopt(sys.argv[1:],'ca:sp:')
-    for opt, arg in optlist:
-	if opt == '-c':
-	    pf = 0
-	elif opt == '-a':
-	    ausync = 1
-	    aumachine = arg
-	elif opt == '-s':
-	    austart = 1
-	elif opt == '-p':
-	    pf = int(eval(arg))
-	else:
-	    usage()
-    if args:
-    	if len(args) > 1:
-    	    print 'Too many arguments'
-    	    usage()
-    	filename = args[0]
-    else:
-    	filename = 'film.video'
-    if austart:
-	if not ausync:
-	    print 'Cannot use -s without -a'
-	    usage()
-	print 'Starting audio recorder...'
-	posix.system('rsh '+aumachine+' syncrecord '+socket.gethostname()+' &')
-    if ausync:
-	print 'Syncing to audio recorder...'
-	globtime = vtime.VTime().init(1,aumachine,SYNCPORT)
-	ctl = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
-	ctl.bind((socket.gethostname(),CTLPORT))
-	aua = (socket.gethostbyname(aumachine), CTLPORT)
-	print 'Done.'
-    vidx, vidy, w, h = getvideosize()
-    #prefsize(w,h)
-    winx, winy = 1280-w-10, 1024-h-30
-    prefposition(winx,winx+w-1,winy,winy+h-1)
-    win = winopen(filename)
-    f = open(filename, 'w')
-    w, h = getsize()
-    realw, realh = w, h
-    ####doublebuffer()
-    RGBmode()
-    gconfig()
-    qdevice(LEFTMOUSE)
-    qdevice(RKEY)
-    qdevice(SKEY)
-    qdevice(CKEY)
-    qdevice(PKEY)
-    qdevice(ESCKEY)
-    qdevice(WINQUIT)
-    qdevice(WINSHUT)
-    inrunning = 1
-    outrunning = 0
-    stop = 'stop'
-    readsource(SRC_FRAMEGRABBER)
-    mousing = 0
-    epoch.epoch = time.millitimer()
-    stoptime = epoch.epoch
-    sizewritten = 0
-    x, y = realw/4, realh/4
-    w, h = w/2, h/2
-    prealloc(w, h)
-    try:
-	drawframe(x,y,w,h,1)
-	nframe = 0
-	num = 0
-	while 1:
-	    insingle = 0
-	    outsingle = 0
-	    if mousing:
-		drawframe(x,y,w,h,0)