Back to index

python3.2  3.2.2
Functions
finddiv Namespace Reference

Functions

def main
def usage
def process
def processdir

Function Documentation

def finddiv.main ( void  )

Definition at line 23 of file finddiv.py.

00023 
00024 def main():
00025     try:
00026         opts, args = getopt.getopt(sys.argv[1:], "lh")
00027     except getopt.error as msg:
00028         usage(msg)
00029         return 2
00030     if not args:
00031         usage("at least one file argument is required")
00032         return 2
00033     listnames = 0
00034     for o, a in opts:
00035         if o == "-h":
00036             print(__doc__)
00037             return
00038         if o == "-l":
00039             listnames = 1
00040     exit = None
00041     for filename in args:
00042         x = process(filename, listnames)
00043         exit = exit or x
00044     return exit

Here is the call graph for this function:

Here is the caller graph for this function:

def finddiv.process (   filename,
  listnames 
)

Definition at line 50 of file finddiv.py.

00050 
00051 def process(filename, listnames):
00052     if os.path.isdir(filename):
00053         return processdir(filename, listnames)
00054     try:
00055         fp = open(filename)
00056     except IOError as msg:
00057         sys.stderr.write("Can't open: %s\n" % msg)
00058         return 1
00059     g = tokenize.generate_tokens(fp.readline)
00060     lastrow = None
00061     for type, token, (row, col), end, line in g:
00062         if token in ("/", "/="):
00063             if listnames:
00064                 print(filename)
00065                 break
00066             if row != lastrow:
00067                 lastrow = row
00068                 print("%s:%d:%s" % (filename, row, line), end=' ')
00069     fp.close()

Here is the call graph for this function:

Here is the caller graph for this function:

def finddiv.processdir (   dir,
  listnames 
)

Definition at line 70 of file finddiv.py.

00070 
00071 def processdir(dir, listnames):
00072     try:
00073         names = os.listdir(dir)
00074     except os.error as msg:
00075         sys.stderr.write("Can't list directory: %s\n" % dir)
00076         return 1
00077     files = []
00078     for name in names:
00079         fn = os.path.join(dir, name)
00080         if os.path.normcase(fn).endswith(".py") or os.path.isdir(fn):
00081             files.append(fn)
00082     files.sort(key=os.path.normcase)
00083     exit = None
00084     for fn in files:
00085         x = process(fn, listnames)
00086         exit = exit or x
00087     return exit

Here is the call graph for this function:

Here is the caller graph for this function:

def finddiv.usage (   msg)

Definition at line 45 of file finddiv.py.

00045 
00046 def usage(msg):
00047     sys.stderr.write("%s: %s\n" % (sys.argv[0], msg))
00048     sys.stderr.write("Usage: %s [-l] file ...\n" % sys.argv[0])
00049     sys.stderr.write("Try `%s -h' for more information.\n" % sys.argv[0])

Here is the caller graph for this function: