Vega strike Python Modules doc  0.5.1
Documentation of the " Modules " folder of Vega strike
 All Data Structures Namespaces Files Functions Variables
compileall Namespace Reference

Functions

def compile_dir
 
def compile_path
 
def main
 

Variables

list __all__ = ["compile_dir","compile_path"]
 
tuple exit_status = notmain()
 

Detailed Description

Module/script to "compile" all .py files to .pyc (or .pyo) file.

When called as a script with arguments, this compiles the directories
given as arguments recursively; the -l option prevents it from
recursing into directories.

Without arguments, if compiles all modules on sys.path, without
recursing into subdirectories.  (Even though it should do so for
packages -- for now, you'll have to deal with packages separately.)

See module py_compile for details of the actual byte-compilation.

Function Documentation

def compileall.compile_dir (   dir,
  maxlevels = 10,
  ddir = None,
  force = 0,
  rx = None 
)
Byte-compile all modules in the given directory tree.

Arguments (only dir is required):

dir:       the directory to byte-compile
maxlevels: maximum recursion level (default 10)
ddir:      if given, purported directory name (this is the
           directory name that will show up in error messages)
force:     if 1, force compilation, even if timestamps are up-to-date

Definition at line 22 of file compileall.py.

References py_compile.compile().

22 
23 def compile_dir(dir, maxlevels=10, ddir=None, force=0, rx=None):
24  """Byte-compile all modules in the given directory tree.
25 
26  Arguments (only dir is required):
27 
28  dir: the directory to byte-compile
29  maxlevels: maximum recursion level (default 10)
30  ddir: if given, purported directory name (this is the
31  directory name that will show up in error messages)
32  force: if 1, force compilation, even if timestamps are up-to-date
33 
34  """
35  print 'Listing', dir, '...'
36  try:
37  names = os.listdir(dir)
38  except os.error:
39  print "Can't list", dir
40  names = []
41  names.sort()
42  success = 1
43  for name in names:
44  fullname = os.path.join(dir, name)
45  if ddir:
46  dfile = os.path.join(ddir, name)
47  else:
48  dfile = None
49  if rx:
50  mo = rx.search(fullname)
51  if mo:
52  continue
53  if os.path.isfile(fullname):
54  head, tail = name[:-3], name[-3:]
55  if tail == '.py':
56  cfile = fullname + (__debug__ and 'c' or 'o')
57  ftime = os.stat(fullname)[stat.ST_MTIME]
58  try: ctime = os.stat(cfile)[stat.ST_MTIME]
59  except os.error: ctime = 0
60  if (ctime > ftime) and not force: continue
61  print 'Compiling', fullname, '...'
62  try:
63  ok = py_compile.compile(fullname, None, dfile)
64  except KeyboardInterrupt:
65  raise KeyboardInterrupt
66  except:
67  # XXX py_compile catches SyntaxErrors
68  if type(sys.exc_type) == type(''):
69  exc_type_name = sys.exc_type
70  else: exc_type_name = sys.exc_type.__name__
71  print 'Sorry:', exc_type_name + ':',
72  print sys.exc_value
73  success = 0
74  else:
75  if ok == 0:
76  success = 0
77  elif maxlevels > 0 and \
78  name != os.curdir and name != os.pardir and \
79  os.path.isdir(fullname) and \
80  not os.path.islink(fullname):
81  if not compile_dir(fullname, maxlevels - 1, dfile, force, rx):
82  success = 0
83  return success
def compileall.compile_path (   skip_curdir = 1,
  maxlevels = 0,
  force = 0 
)
Byte-compile all module on sys.path.

Arguments (all optional):

skip_curdir: if true, skip current directory (default true)
maxlevels:   max recursion level (default 0)
force: as for compile_dir() (default 0)

Definition at line 84 of file compileall.py.

References compile_dir().

84 
85 def compile_path(skip_curdir=1, maxlevels=0, force=0):
86  """Byte-compile all module on sys.path.
87 
88  Arguments (all optional):
89 
90  skip_curdir: if true, skip current directory (default true)
91  maxlevels: max recursion level (default 0)
92  force: as for compile_dir() (default 0)
93 
94  """
95  success = 1
96  for dir in sys.path:
97  if (not dir or dir == os.curdir) and skip_curdir:
98  print 'Skipping current directory'
99  else:
100  success = success and compile_dir(dir, maxlevels, None, force)
101  return success
def compileall.main ( )
Script main program.

Definition at line 102 of file compileall.py.

References compile_dir(), compile_path(), and getopt.getopt().

103 def main():
104  """Script main program."""
105  import getopt
106  try:
107  opts, args = getopt.getopt(sys.argv[1:], 'lfd:x:')
108  except getopt.error, msg:
109  print msg
110  print "usage: python compileall.py [-l] [-f] [-d destdir] " \
111  "[-s regexp] [directory ...]"
112  print "-l: don't recurse down"
113  print "-f: force rebuild even if timestamps are up-to-date"
114  print "-d destdir: purported directory name for error messages"
115  print " if no directory arguments, -l sys.path is assumed"
116  print "-x regexp: skip files matching the regular expression regexp"
117  print " the regexp is search for in the full path of the file"
118  sys.exit(2)
119  maxlevels = 10
120  ddir = None
121  force = 0
122  rx = None
123  for o, a in opts:
124  if o == '-l': maxlevels = 0
125  if o == '-d': ddir = a
126  if o == '-f': force = 1
127  if o == '-x':
128  import re
129  rx = re.compile(a)
130  if ddir:
131  if len(args) != 1:
132  print "-d destdir require exactly one directory argument"
133  sys.exit(2)
134  success = 1
135  try:
136  if args:
137  for dir in args:
138  if not compile_dir(dir, maxlevels, ddir, force, rx):
139  success = 0
140  else:
141  success = compile_path()
142  except KeyboardInterrupt:
143  print "\n[interrupt]"
144  success = 0
145  return success

Variable Documentation

list __all__ = ["compile_dir","compile_path"]

Definition at line 20 of file compileall.py.

tuple exit_status = notmain()

Definition at line 147 of file compileall.py.