blob: 4c8fdac1c6e8c188d11d5e3649a11004374da97c [file] [log] [blame]
Guido van Rossumf06ee5f1996-11-27 19:52:01 +00001#! /usr/bin/env python
Guido van Rossum5c1797a1992-09-08 15:17:02 +00002
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+')
Sjoerd Mullenderc6d846a1993-12-22 12:40:20 +000045 vin = VFile.RandomVinFile(fp)
46 vin.filename = filename
Guido van Rossum5c1797a1992-09-08 15:17:02 +000047 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
56
57 try:
58 vin.readcache()
59 hascache = 1
60 except VFile.Error:
61 hascache = 0
62
63 if hascache:
64 sys.stderr.write(filename + ': already has a cache\n')
65 vin.close()
66 return 1
67
68 vin.printinfo()
69 vin.warmcache()
70 vin.writecache()
71 vin.close()
72 return 0
73
74
75# Don't forget to call the main program
76
77try:
78 main()
79except KeyboardInterrupt:
80 print '[Interrupt]'