blob: d89a78ab8ef5b0ad3c26d411be726d4e336a2211 [file] [log] [blame]
Guido van Rossum5c1797a1992-09-08 15:17:02 +00001#! /usr/local/python
2
3# Add a cache to each of the files given as command line arguments
4
5
6# Usage:
7#
8# Vaddcache [file] ...
9
10
11# Options:
12#
Guido van Rossumba066151992-09-22 17:23:17 +000013# file ... : file(s) to modify; default film.video
Guido van Rossum5c1797a1992-09-08 15:17:02 +000014
15
16import sys
17sys.path.append('/ufs/guido/src/video')
18import VFile
19import getopt
20
21
22# Global options
23
24# None
25
26
27# Main program -- mostly command line parsing
28
29def 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)
38
39
40# Process one file
41
42def process(filename):
43 try:
44 fp = open(filename, 'r+')
45 vin = VFile.RandomVinFile().initfp(fp, filename)
46 except IOError, msg:
47 sys.stderr.write(filename + ': I/O error: ' + `msg` + '\n')
48 return 1
49 except VFile.Error, msg:
50 sys.stderr.write(msg + '\n')
51 return 1
52 except EOFError:
53 sys.stderr.write(filename + ': EOF in video file\n')
54 return 1
55
56 try:
57 vin.readcache()
58 hascache = 1
59 except VFile.Error:
60 hascache = 0
61
62 if hascache:
63 sys.stderr.write(filename + ': already has a cache\n')
64 vin.close()
65 return 1
66
67 vin.printinfo()
68 vin.warmcache()
69 vin.writecache()
70 vin.close()
71 return 0
72
73
74# Don't forget to call the main program
75
76try:
77 main()
78except KeyboardInterrupt:
79 print '[Interrupt]'