Back to index

python3.2  3.2.2
Functions | Variables
ndiff Namespace Reference

Functions

def fail
def fopen
def fcompare
def main
def restore

Variables

int __version__ = 1
list args = sys.argv[1:]
string statf = "ndiff.pro"
tuple stats = pstats.Stats(statf)

Function Documentation

def ndiff.fail (   msg)

Definition at line 53 of file ndiff.py.

00053 
00054 def fail(msg):
00055     out = sys.stderr.write
00056     out(msg + "\n\n")
00057     out(__doc__)
00058     return 0
00059 
00060 # open a file & return the file object; gripe and return 0 if it
# couldn't be opened

Here is the caller graph for this function:

def ndiff.fcompare (   f1name,
  f2name 
)

Definition at line 68 of file ndiff.py.

00068 
00069 def fcompare(f1name, f2name):
00070     f1 = fopen(f1name)
00071     f2 = fopen(f2name)
00072     if not f1 or not f2:
00073         return 0
00074 
00075     a = f1.readlines(); f1.close()
00076     b = f2.readlines(); f2.close()
00077     for line in difflib.ndiff(a, b):
00078         print(line, end=' ')
00079 
00080     return 1
00081 
00082 # crack args (sys.argv[1:] is normal) & compare;
00083 # return false iff a problem

Here is the call graph for this function:

Here is the caller graph for this function:

def ndiff.fopen (   fname)

Definition at line 61 of file ndiff.py.

00061 
00062 def fopen(fname):
00063     try:
00064         return open(fname, 'U')
00065     except IOError as detail:
00066         return fail("couldn't open " + fname + ": " + str(detail))
00067 
# open two files & spray the diff to stdout; return false iff a problem

Here is the call graph for this function:

Here is the caller graph for this function:

def ndiff.main (   args)

Definition at line 84 of file ndiff.py.

00084 
00085 def main(args):
00086     import getopt
00087     try:
00088         opts, args = getopt.getopt(args, "qr:")
00089     except getopt.error as detail:
00090         return fail(str(detail))
00091     noisy = 1
00092     qseen = rseen = 0
00093     for opt, val in opts:
00094         if opt == "-q":
00095             qseen = 1
00096             noisy = 0
00097         elif opt == "-r":
00098             rseen = 1
00099             whichfile = val
00100     if qseen and rseen:
00101         return fail("can't specify both -q and -r")
00102     if rseen:
00103         if args:
00104             return fail("no args allowed with -r option")
00105         if whichfile in ("1", "2"):
00106             restore(whichfile)
00107             return 1
00108         return fail("-r value must be 1 or 2")
00109     if len(args) != 2:
00110         return fail("need 2 filename args")
00111     f1name, f2name = args
00112     if noisy:
00113         print('-:', f1name)
00114         print('+:', f2name)
00115     return fcompare(f1name, f2name)
00116 
00117 # read ndiff output from stdin, and print file1 (which=='1') or
00118 # file2 (which=='2') to stdout

Here is the call graph for this function:

def ndiff.restore (   which)

Definition at line 119 of file ndiff.py.

00119 
00120 def restore(which):
00121     restored = difflib.restore(sys.stdin.readlines(), which)
00122     sys.stdout.writelines(restored)

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Definition at line 49 of file ndiff.py.

list ndiff.args = sys.argv[1:]

Definition at line 124 of file ndiff.py.

string ndiff.statf = "ndiff.pro"

Definition at line 128 of file ndiff.py.

Definition at line 130 of file ndiff.py.