Guido van Rossum | f06ee5f | 1996-11-27 19:52:01 +0000 | [diff] [blame] | 1 | #! /usr/bin/env python |
Guido van Rossum | 5c1797a | 1992-09-08 15:17:02 +0000 | [diff] [blame] | 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 Rossum | ba06615 | 1992-09-22 17:23:17 +0000 | [diff] [blame] | 13 | # file ... : file(s) to modify; default film.video |
Guido van Rossum | 5c1797a | 1992-09-08 15:17:02 +0000 | [diff] [blame] | 14 | |
| 15 | |
| 16 | import sys |
| 17 | sys.path.append('/ufs/guido/src/video') |
| 18 | import VFile |
| 19 | import getopt |
| 20 | |
| 21 | |
| 22 | # Global options |
| 23 | |
| 24 | # None |
| 25 | |
| 26 | |
| 27 | # Main program -- mostly command line parsing |
| 28 | |
| 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) |
| 38 | |
| 39 | |
| 40 | # Process one file |
| 41 | |
| 42 | def process(filename): |
| 43 | try: |
| 44 | fp = open(filename, 'r+') |
Sjoerd Mullender | c6d846a | 1993-12-22 12:40:20 +0000 | [diff] [blame] | 45 | vin = VFile.RandomVinFile(fp) |
| 46 | vin.filename = filename |
Guido van Rossum | 5c1797a | 1992-09-08 15:17:02 +0000 | [diff] [blame] | 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 |
| 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 | |
| 77 | try: |
| 78 | main() |
| 79 | except KeyboardInterrupt: |
| 80 | print '[Interrupt]' |