summaryrefslogtreecommitdiffstats
path: root/Tools/scripts/byteyears.py
diff options
context:
space:
mode:
authorAndrew M. Kuchling <amk@amk.ca>2004-08-09 17:27:55 (GMT)
committerAndrew M. Kuchling <amk@amk.ca>2004-08-09 17:27:55 (GMT)
commite236b38731823aeb87bb6d101062f54a72044954 (patch)
tree6283b4999bb585c11ae1dfeb87dfb6e083f78e6c /Tools/scripts/byteyears.py
parent6c542b731cfe3e17991643bfc41bb785331e7e5c (diff)
downloadcpython-e236b38731823aeb87bb6d101062f54a72044954.zip
cpython-e236b38731823aeb87bb6d101062f54a72044954.tar.gz
cpython-e236b38731823aeb87bb6d101062f54a72044954.tar.bz2
[Patch #1005491 ] use __name__ == '__main__' in scripts
Diffstat (limited to 'Tools/scripts/byteyears.py')
-rwxr-xr-xTools/scripts/byteyears.py93
1 files changed, 49 insertions, 44 deletions
diff --git a/Tools/scripts/byteyears.py b/Tools/scripts/byteyears.py
index b2a114f..ba38caf 100755
--- a/Tools/scripts/byteyears.py
+++ b/Tools/scripts/byteyears.py
@@ -9,48 +9,53 @@
import sys, os, time
from stat import *
-# Use lstat() to stat files if it exists, else stat()
-try:
- statfunc = os.lstat
-except AttributeError:
- statfunc = os.stat
-
-# Parse options
-if sys.argv[1] == '-m':
- itime = ST_MTIME
- del sys.argv[1]
-elif sys.argv[1] == '-c':
- itime = ST_CTIME
- del sys.argv[1]
-elif sys.argv[1] == '-a':
- itime = ST_CTIME
- del sys.argv[1]
-else:
- itime = ST_MTIME
-
-secs_per_year = 365.0 * 24.0 * 3600.0 # Scale factor
-now = time.time() # Current time, for age computations
-status = 0 # Exit status, set to 1 on errors
-
-# Compute max file name length
-maxlen = 1
-for filename in sys.argv[1:]:
- maxlen = max(maxlen, len(filename))
-
-# Process each argument in turn
-for filename in sys.argv[1:]:
+def main():
+
+ # Use lstat() to stat files if it exists, else stat()
try:
- st = statfunc(filename)
- except os.error, msg:
- sys.stderr.write("can't stat %r: %r\n" % (filename, msg))
- status = 1
- st = ()
- if st:
- anytime = st[itime]
- size = st[ST_SIZE]
- age = now - anytime
- byteyears = float(size) * float(age) / secs_per_year
- print filename.ljust(maxlen),
- print repr(int(byteyears)).rjust(8)
-
-sys.exit(status)
+ statfunc = os.lstat
+ except AttributeError:
+ statfunc = os.stat
+
+ # Parse options
+ if sys.argv[1] == '-m':
+ itime = ST_MTIME
+ del sys.argv[1]
+ elif sys.argv[1] == '-c':
+ itime = ST_CTIME
+ del sys.argv[1]
+ elif sys.argv[1] == '-a':
+ itime = ST_CTIME
+ del sys.argv[1]
+ else:
+ itime = ST_MTIME
+
+ secs_per_year = 365.0 * 24.0 * 3600.0 # Scale factor
+ now = time.time() # Current time, for age computations
+ status = 0 # Exit status, set to 1 on errors
+
+ # Compute max file name length
+ maxlen = 1
+ for filename in sys.argv[1:]:
+ maxlen = max(maxlen, len(filename))
+
+ # Process each argument in turn
+ for filename in sys.argv[1:]:
+ try:
+ st = statfunc(filename)
+ except os.error, msg:
+ sys.stderr.write("can't stat %r: %r\n" % (filename, msg))
+ status = 1
+ st = ()
+ if st:
+ anytime = st[itime]
+ size = st[ST_SIZE]
+ age = now - anytime
+ byteyears = float(size) * float(age) / secs_per_year
+ print filename.ljust(maxlen),
+ print repr(int(byteyears)).rjust(8)
+
+ sys.exit(status)
+
+if __name__ == '__main__':
+ main()