home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / pyos2bin.zip / Demo / sgi / video / Vaddcache.py < prev    next >
Text File  |  1996-11-27  |  1KB  |  81 lines

  1. #! /usr/bin/env 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. #
  13. # file ... : file(s) to modify; default film.video
  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+')
  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
  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]'
  81.