Updated for 2.1b2 distribution.
[python/dscho.git] / Demo / sgi / video / Vaddcache.py
blob4c8fdac1c6e8c188d11d5e3649a11004374da97c
1 #! /usr/bin/env python
3 # Add a cache to each of the files given as command line arguments
6 # Usage:
8 # Vaddcache [file] ...
11 # Options:
13 # file ... : file(s) to modify; default film.video
16 import sys
17 sys.path.append('/ufs/guido/src/video')
18 import VFile
19 import getopt
22 # Global options
24 # None
27 # Main program -- mostly command line parsing
29 def main():
30 opts, args = getopt.getopt(sys.argv[1:], '')
31 if not args:
32 args = ['film.video']
33 sts = 0
34 for filename in args:
35 if process(filename):
36 sts = 1
37 sys.exit(sts)
40 # Process one file
42 def process(filename):
43 try:
44 fp = open(filename, 'r+')
45 vin = VFile.RandomVinFile(fp)
46 vin.filename = filename
47 except IOError, msg:
48 sys.stderr.write(filename + ': I/O error: ' + `msg` + '\n')
49 return 1
50 except VFile.Error, msg:
51 sys.stderr.write(msg + '\n')
52 return 1
53 except EOFError:
54 sys.stderr.write(filename + ': EOF in video file\n')
55 return 1
57 try:
58 vin.readcache()
59 hascache = 1
60 except VFile.Error:
61 hascache = 0
63 if hascache:
64 sys.stderr.write(filename + ': already has a cache\n')
65 vin.close()
66 return 1
68 vin.printinfo()
69 vin.warmcache()
70 vin.writecache()
71 vin.close()
72 return 0
75 # Don't forget to call the main program
77 try:
78 main()
79 except KeyboardInterrupt:
80 print '[Interrupt]'