summaryrefslogtreecommitdiff
path: root/sys/src/cmd/python/Tools/scripts/byteyears.py
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@localhost>2011-05-03 11:25:13 +0000
committercinap_lenrek <cinap_lenrek@localhost>2011-05-03 11:25:13 +0000
commit458120dd40db6b4df55a4e96b650e16798ef06a0 (patch)
tree8f82685be24fef97e715c6f5ca4c68d34d5074ee /sys/src/cmd/python/Tools/scripts/byteyears.py
parent3a742c699f6806c1145aea5149bf15de15a0afd7 (diff)
add hg and python
Diffstat (limited to 'sys/src/cmd/python/Tools/scripts/byteyears.py')
-rwxr-xr-xsys/src/cmd/python/Tools/scripts/byteyears.py61
1 files changed, 61 insertions, 0 deletions
diff --git a/sys/src/cmd/python/Tools/scripts/byteyears.py b/sys/src/cmd/python/Tools/scripts/byteyears.py
new file mode 100755
index 000000000..ba38cafd1
--- /dev/null
+++ b/sys/src/cmd/python/Tools/scripts/byteyears.py
@@ -0,0 +1,61 @@
+#! /usr/bin/env python
+
+# Print the product of age and size of each file, in suitable units.
+#
+# Usage: byteyears [ -a | -m | -c ] file ...
+#
+# Options -[amc] select atime, mtime (default) or ctime as age.
+
+import sys, os, time
+from stat import *
+
+def main():
+
+ # 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:]:
+ 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()