Back to index

python3.2  3.2.2
Functions
which Namespace Reference

Functions

def msg
def main

Function Documentation

def which.main ( void  )

Definition at line 16 of file which.py.

00016 
00017 def main():
00018     pathlist = os.environ['PATH'].split(os.pathsep)
00019 
00020     sts = 0
00021     longlist = ''
00022 
00023     if sys.argv[1:] and sys.argv[1][:2] == '-l':
00024         longlist = sys.argv[1]
00025         del sys.argv[1]
00026 
00027     for prog in sys.argv[1:]:
00028         ident = ()
00029         for dir in pathlist:
00030             filename = os.path.join(dir, prog)
00031             try:
00032                 st = os.stat(filename)
00033             except os.error:
00034                 continue
00035             if not S_ISREG(st[ST_MODE]):
00036                 msg(filename + ': not a disk file')
00037             else:
00038                 mode = S_IMODE(st[ST_MODE])
00039                 if mode & 0o111:
00040                     if not ident:
00041                         print(filename)
00042                         ident = st[:3]
00043                     else:
00044                         if st[:3] == ident:
00045                             s = 'same as: '
00046                         else:
00047                             s = 'also: '
00048                         msg(s + filename)
00049                 else:
00050                     msg(filename + ': not executable')
00051             if longlist:
00052                 sts = os.system('ls ' + longlist + ' ' + filename)
00053                 if sts: msg('"ls -l" exit status: ' + repr(sts))
00054         if not ident:
00055             msg(prog + ': not found')
00056             sts = 1
00057 
00058     sys.exit(sts)

Here is the call graph for this function:

def which.msg (   str)

Definition at line 13 of file which.py.

00013 
00014 def msg(str):
00015     sys.stderr.write(str + '\n')

Here is the caller graph for this function: