home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_318 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  3.6 KB  |  168 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import os
  5. import sys
  6. import py_compile
  7. __all__ = [
  8.     'compile_dir',
  9.     'compile_path']
  10.  
  11. def compile_dir(dir, maxlevels = 10, ddir = None, force = 0, rx = None, quiet = 0):
  12.     if not quiet:
  13.         print 'Listing', dir, '...'
  14.     
  15.     
  16.     try:
  17.         names = os.listdir(dir)
  18.     except os.error:
  19.         print "Can't list", dir
  20.         names = []
  21.  
  22.     names.sort()
  23.     success = 1
  24.     for name in names:
  25.         fullname = os.path.join(dir, name)
  26.         if ddir is not None:
  27.             dfile = os.path.join(ddir, name)
  28.         else:
  29.             dfile = None
  30.         if rx is not None:
  31.             mo = rx.search(fullname)
  32.             if mo:
  33.                 continue
  34.             
  35.         
  36.         if os.path.isfile(fullname):
  37.             head = name[:-3]
  38.             tail = name[-3:]
  39.             if tail == '.py':
  40.                 if not __debug__ or 'c':
  41.                     pass
  42.                 cfile = fullname + 'o'
  43.                 ftime = os.stat(fullname).st_mtime
  44.                 
  45.                 try:
  46.                     ctime = os.stat(cfile).st_mtime
  47.                 except os.error:
  48.                     ctime = 0
  49.  
  50.                 if ctime > ftime and not force:
  51.                     continue
  52.                 
  53.                 if not quiet:
  54.                     print 'Compiling', fullname, '...'
  55.                 
  56.                 
  57.                 try:
  58.                     ok = py_compile.compile(fullname, None, dfile, True)
  59.                 except KeyboardInterrupt:
  60.                     raise KeyboardInterrupt
  61.                 except py_compile.PyCompileError:
  62.                     err = None
  63.                     if quiet:
  64.                         print 'Compiling', fullname, '...'
  65.                     
  66.                     print err.msg
  67.                     success = 0
  68.                 except IOError:
  69.                     e = None
  70.                     print 'Sorry', e
  71.                     success = 0
  72.  
  73.                 if ok == 0:
  74.                     success = 0
  75.                 
  76.             
  77.         tail == '.py'
  78.         if maxlevels > 0 and name != os.curdir and name != os.pardir and os.path.isdir(fullname) and not os.path.islink(fullname):
  79.             if not compile_dir(fullname, maxlevels - 1, dfile, force, rx, quiet):
  80.                 success = 0
  81.             
  82.         compile_dir(fullname, maxlevels - 1, dfile, force, rx, quiet)
  83.     
  84.     return success
  85.  
  86.  
  87. def compile_path(skip_curdir = 1, maxlevels = 0, force = 0, quiet = 0):
  88.     success = 1
  89.     for dir in sys.path:
  90.         if (not dir or dir == os.curdir) and skip_curdir:
  91.             print 'Skipping current directory'
  92.             continue
  93.         if success:
  94.             pass
  95.         success = compile_dir(dir, maxlevels, None, force, quiet = quiet)
  96.     
  97.     return success
  98.  
  99.  
  100. def main():
  101.     import getopt
  102.     
  103.     try:
  104.         (opts, args) = getopt.getopt(sys.argv[1:], 'lfqd:x:')
  105.     except getopt.error:
  106.         msg = None
  107.         print msg
  108.         print 'usage: python compileall.py [-l] [-f] [-q] [-d destdir] [-x regexp] [directory ...]'
  109.         print "-l: don't recurse down"
  110.         print '-f: force rebuild even if timestamps are up-to-date'
  111.         print '-q: quiet operation'
  112.         print '-d destdir: purported directory name for error messages'
  113.         print '   if no directory arguments, -l sys.path is assumed'
  114.         print '-x regexp: skip files matching the regular expression regexp'
  115.         print '   the regexp is searched for in the full path of the file'
  116.         sys.exit(2)
  117.  
  118.     maxlevels = 10
  119.     ddir = None
  120.     force = 0
  121.     quiet = 0
  122.     rx = None
  123.     for o, a in opts:
  124.         if o == '-l':
  125.             maxlevels = 0
  126.         
  127.         if o == '-d':
  128.             ddir = a
  129.         
  130.         if o == '-f':
  131.             force = 1
  132.         
  133.         if o == '-q':
  134.             quiet = 1
  135.         
  136.         if o == '-x':
  137.             import re
  138.             rx = re.compile(a)
  139.             continue
  140.     
  141.     if ddir:
  142.         if len(args) != 1:
  143.             print '-d destdir require exactly one directory argument'
  144.             sys.exit(2)
  145.         
  146.     
  147.     success = 1
  148.     
  149.     try:
  150.         if args:
  151.             for dir in args:
  152.                 if not compile_dir(dir, maxlevels, ddir, force, rx, quiet):
  153.                     success = 0
  154.                     continue
  155.             
  156.         else:
  157.             success = compile_path()
  158.     except KeyboardInterrupt:
  159.         print '\n[interrupt]'
  160.         success = 0
  161.  
  162.     return success
  163.  
  164. if __name__ == '__main__':
  165.     exit_status = int(not main())
  166.     sys.exit(exit_status)
  167.  
  168.