Back to index

python3.2  3.2.2
Classes | Functions | Variables
cleanfuture Namespace Reference

Classes

class  FutureFinder

Functions

def errprint
def main
def check

Variables

int dryrun = 0
int recurse = 0
int verbose = 0

Function Documentation

def cleanfuture.check (   file)

Definition at line 78 of file cleanfuture.py.

00078 
00079 def check(file):
00080     if os.path.isdir(file) and not os.path.islink(file):
00081         if verbose:
00082             print("listing directory", file)
00083         names = os.listdir(file)
00084         for name in names:
00085             fullname = os.path.join(file, name)
00086             if ((recurse and os.path.isdir(fullname) and
00087                  not os.path.islink(fullname))
00088                 or name.lower().endswith(".py")):
00089                 check(fullname)
00090         return
00091 
00092     if verbose:
00093         print("checking", file, "...", end=' ')
00094     try:
00095         f = open(file)
00096     except IOError as msg:
00097         errprint("%r: I/O Error: %s" % (file, str(msg)))
00098         return
00099 
00100     ff = FutureFinder(f, file)
00101     changed = ff.run()
00102     if changed:
00103         ff.gettherest()
00104     f.close()
00105     if changed:
00106         if verbose:
00107             print("changed.")
00108             if dryrun:
00109                 print("But this is a dry run, so leaving it alone.")
00110         for s, e, line in changed:
00111             print("%r lines %d-%d" % (file, s+1, e+1))
00112             for i in range(s, e+1):
00113                 print(ff.lines[i], end=' ')
00114             if line is None:
00115                 print("-- deleted")
00116             else:
00117                 print("-- change to:")
00118                 print(line, end=' ')
00119         if not dryrun:
00120             bak = file + ".bak"
00121             if os.path.exists(bak):
00122                 os.remove(bak)
00123             os.rename(file, bak)
00124             if verbose:
00125                 print("renamed", file, "to", bak)
00126             g = open(file, "w")
00127             ff.write(g)
00128             g.close()
00129             if verbose:
00130                 print("wrote new", file)
00131     else:
00132         if verbose:
00133             print("unchanged.")

Here is the call graph for this function:

Here is the caller graph for this function:

def cleanfuture.errprint (   args)

Definition at line 50 of file cleanfuture.py.

00050 
00051 def errprint(*args):
00052     strings = map(str, args)
00053     msg = ' '.join(strings)
00054     if msg[-1:] != '\n':
00055         msg += '\n'
00056     sys.stderr.write(msg)

Here is the caller graph for this function:

Definition at line 57 of file cleanfuture.py.

00057 
00058 def main():
00059     import getopt
00060     global verbose, recurse, dryrun
00061     try:
00062         opts, args = getopt.getopt(sys.argv[1:], "drv")
00063     except getopt.error as msg:
00064         errprint(msg)
00065         return
00066     for o, a in opts:
00067         if o == '-d':
00068             dryrun += 1
00069         elif o == '-r':
00070             recurse += 1
00071         elif o == '-v':
00072             verbose += 1
00073     if not args:
00074         errprint("Usage:", __doc__)
00075         return
00076     for arg in args:
00077         check(arg)

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Definition at line 46 of file cleanfuture.py.

Definition at line 47 of file cleanfuture.py.

Definition at line 48 of file cleanfuture.py.