Back to index

python3.2  3.2.2
Functions
byteyears Namespace Reference

Functions

def main

Function Documentation

def byteyears.main ( void  )

Definition at line 12 of file byteyears.py.

00012 
00013 def main():
00014 
00015     # Use lstat() to stat files if it exists, else stat()
00016     try:
00017         statfunc = os.lstat
00018     except AttributeError:
00019         statfunc = os.stat
00020 
00021     # Parse options
00022     if sys.argv[1] == '-m':
00023         itime = ST_MTIME
00024         del sys.argv[1]
00025     elif sys.argv[1] == '-c':
00026         itime = ST_CTIME
00027         del sys.argv[1]
00028     elif sys.argv[1] == '-a':
00029         itime = ST_CTIME
00030         del sys.argv[1]
00031     else:
00032         itime = ST_MTIME
00033 
00034     secs_per_year = 365.0 * 24.0 * 3600.0   # Scale factor
00035     now = time.time()                       # Current time, for age computations
00036     status = 0                              # Exit status, set to 1 on errors
00037 
00038     # Compute max file name length
00039     maxlen = 1
00040     for filename in sys.argv[1:]:
00041         maxlen = max(maxlen, len(filename))
00042 
00043     # Process each argument in turn
00044     for filename in sys.argv[1:]:
00045         try:
00046             st = statfunc(filename)
00047         except os.error as msg:
00048             sys.stderr.write("can't stat %r: %r\n" % (filename, msg))
00049             status = 1
00050             st = ()
00051         if st:
00052             anytime = st[itime]
00053             size = st[ST_SIZE]
00054             age = now - anytime
00055             byteyears = float(size) * float(age) / secs_per_year
00056             print(filename.ljust(maxlen), end=' ')
00057             print(repr(int(byteyears)).rjust(8))
00058 
00059     sys.exit(status)

Here is the call graph for this function: