Back to index

python3.2  3.2.2
Functions | Variables
md5sum Namespace Reference

Functions

def sum
def printsum
def printsumfp
def main

Variables

int bufsize = 8096
 fnfilter = None
string rmode = 'rb'
string usage

Function Documentation

def md5sum.main (   args = sys.argv[1:],
  out = sys.stdout 
)

Definition at line 69 of file md5sum.py.

00069 
00070 def main(args = sys.argv[1:], out=sys.stdout):
00071     global fnfilter, rmode, bufsize
00072     try:
00073         opts, args = getopt.getopt(args, 'blts:')
00074     except getopt.error as msg:
00075         sys.stderr.write('%s: %s\n%s' % (sys.argv[0], msg, usage))
00076         return 2
00077     for o, a in opts:
00078         if o == '-l':
00079             fnfilter = os.path.basename
00080         elif o == '-b':
00081             rmode = 'rb'
00082         elif o == '-t':
00083             rmode = 'r'
00084         elif o == '-s':
00085             bufsize = int(a)
00086     if not args:
00087         args = ['-']
00088     return sum(args, out)

Here is the call graph for this function:

def md5sum.printsum (   filename,
  out = sys.stdout 
)

Definition at line 43 of file md5sum.py.

00043 
00044 def printsum(filename, out=sys.stdout):
00045     try:
00046         fp = open(filename, rmode)
00047     except IOError as msg:
00048         sys.stderr.write('%s: Can\'t open: %s\n' % (filename, msg))
00049         return 1
00050     if fnfilter:
00051         filename = fnfilter(filename)
00052     sts = printsumfp(fp, filename, out)
00053     fp.close()
00054     return sts

Here is the call graph for this function:

Here is the caller graph for this function:

def md5sum.printsumfp (   fp,
  filename,
  out = sys.stdout 
)

Definition at line 55 of file md5sum.py.

00055 
00056 def printsumfp(fp, filename, out=sys.stdout):
00057     m = md5.new()
00058     try:
00059         while 1:
00060             data = fp.read(bufsize)
00061             if not data:
00062                 break
00063             m.update(data)
00064     except IOError as msg:
00065         sys.stderr.write('%s: I/O error: %s\n' % (filename, msg))
00066         return 1
00067     out.write('%s %s\n' % (m.hexdigest(), filename))
00068     return 0

Here is the caller graph for this function:

def md5sum.sum (   files)

Definition at line 25 of file md5sum.py.

00025 
00026 def sum(*files):
00027     sts = 0
00028     if files and isinstance(files[-1], file):
00029         out, files = files[-1], files[:-1]
00030     else:
00031         out = sys.stdout
00032     if len(files) == 1 and not isinstance(files[0], str):
00033         files = files[0]
00034     for f in files:
00035         if isinstance(f, str):
00036             if f == '-':
00037                 sts = printsumfp(sys.stdin, '<stdin>', out) or sts
00038             else:
00039                 sts = printsum(f, out) or sts
00040         else:
00041             sts = sum(f, out) or sts
00042     return sts

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

Definition at line 7 of file md5sum.py.

Definition at line 8 of file md5sum.py.

Definition at line 9 of file md5sum.py.

Initial value:
00001 """
00002 usage: sum5 [-b] [-t] [-l] [-s bufsize] [file ...]
00003 -b        : read files in binary mode (default)
00004 -t        : read files in text mode (you almost certainly don't want this!)
00005 -l        : print last pathname component only
00006 -s bufsize: read buffer size (default %d)
00007 file ...  : files to sum; '-' or no files means stdin
00008 """

Definition at line 11 of file md5sum.py.