Back to index

python3.2  3.2.2
Functions | Variables
pathfix Namespace Reference

Functions

def main
def ispython
def recursedown
def fix
def fixline

Variables

 err = sys.stderr.write
 dbg = err
 rep = sys.stdout.write
 new_interpreter = None
 preserve_timestamps = False
tuple ispythonprog = re.compile('^[a-zA-Z0-9_]+\.py$')
tuple f = open(filename, 'rb')
 dbg('fix(r)
' % (filename,))
tuple line = f.readline()
tuple fixed = fixline(line)
tuple tempname = os.path.join(head, '@' + tail)
tuple g = open(tempname, 'wb')
int BUFSIZE = 8
tuple buf = f.read(BUFSIZE)
 mtime = None
 atime = None
tuple statbuf = os.stat(filename)

Function Documentation

def pathfix.fix (   filename)

Definition at line 93 of file pathfix.py.

00093 
def fix(filename):

Here is the caller graph for this function:

def pathfix.fixline (   line)

Definition at line 157 of file pathfix.py.

00157 
00158 def fixline(line):
00159     if not line.startswith(b'#!'):
00160         return line
00161     if b"python" not in line:
00162         return line
00163     return b'#! ' + new_interpreter + b'\n'

Here is the call graph for this function:

def pathfix.ispython (   name)

Definition at line 68 of file pathfix.py.

00068 
00069 def ispython(name):
00070     return bool(ispythonprog.match(name))

Here is the caller graph for this function:

def pathfix.main ( void  )

Definition at line 35 of file pathfix.py.

00035 
00036 def main():
00037     global new_interpreter
00038     global preserve_timestamps
00039     usage = ('usage: %s -i /interpreter -p file-or-directory ...\n' %
00040              sys.argv[0])
00041     try:
00042         opts, args = getopt.getopt(sys.argv[1:], 'i:p')
00043     except getopt.error as msg:
00044         err(str(msg) + '\n')
00045         err(usage)
00046         sys.exit(2)
00047     for o, a in opts:
00048         if o == '-i':
00049             new_interpreter = a.encode()
00050         if o == '-p':
00051             preserve_timestamps = True
00052     if not new_interpreter or not new_interpreter.startswith(b'/') or \
00053            not args:
00054         err('-i option or file-or-directory missing\n')
00055         err(usage)
00056         sys.exit(2)
00057     bad = 0
00058     for arg in args:
00059         if os.path.isdir(arg):
00060             if recursedown(arg): bad = 1
00061         elif os.path.islink(arg):
00062             err(arg + ': will not process symbolic links\n')
00063             bad = 1
00064         else:
00065             if fix(arg): bad = 1
00066     sys.exit(bad)

Here is the call graph for this function:

Here is the caller graph for this function:

def pathfix.recursedown (   dirname)

Definition at line 71 of file pathfix.py.

00071 
00072 def recursedown(dirname):
00073     dbg('recursedown(%r)\n' % (dirname,))
00074     bad = 0
00075     try:
00076         names = os.listdir(dirname)
00077     except os.error as msg:
00078         err('%s: cannot list directory: %r\n' % (dirname, msg))
00079         return 1
00080     names.sort()
00081     subdirs = []
00082     for name in names:
00083         if name in (os.curdir, os.pardir): continue
00084         fullname = os.path.join(dirname, name)
00085         if os.path.islink(fullname): pass
00086         elif os.path.isdir(fullname):
00087             subdirs.append(fullname)
00088         elif ispython(name):
00089             if fix(fullname): bad = 1
00090     for fullname in subdirs:
00091         if recursedown(fullname): bad = 1
00092     return bad

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

pathfix.atime = None

Definition at line 127 of file pathfix.py.

tuple pathfix.buf = f.read(BUFSIZE)

Definition at line 118 of file pathfix.py.

Definition at line 116 of file pathfix.py.

Definition at line 29 of file pathfix.py.

pathfix.err = sys.stderr.write

Definition at line 28 of file pathfix.py.

tuple pathfix.f = open(filename, 'rb')

dbg('fix(r)
' % (filename,))

Definition at line 96 of file pathfix.py.

Definition at line 101 of file pathfix.py.

tuple pathfix.g = open(tempname, 'wb')

Definition at line 109 of file pathfix.py.

tuple pathfix.ispythonprog = re.compile('^[a-zA-Z0-9_]+\.py$')

Definition at line 67 of file pathfix.py.

tuple pathfix.line = f.readline()

Definition at line 100 of file pathfix.py.

pathfix.mtime = None

Definition at line 126 of file pathfix.py.

Definition at line 32 of file pathfix.py.

Definition at line 33 of file pathfix.py.

pathfix.rep = sys.stdout.write

Definition at line 30 of file pathfix.py.

Definition at line 130 of file pathfix.py.

tuple pathfix.tempname = os.path.join(head, '@' + tail)

Definition at line 107 of file pathfix.py.