Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
e8bb04f0
Commit
e8bb04f0
authored
Jul 01, 1991
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add options -amc; do lstat if possible; columnize properly.
parent
ce9c1ec7
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
10 deletions
+38
-10
Tools/scripts/byteyears.py
Tools/scripts/byteyears.py
+38
-10
No files found.
Tools/scripts/byteyears.py
View file @
e8bb04f0
#! /usr/local/python
#
byteyears file ..
.
#
Print the product of age and size of each file, in suitable units
.
#
# Print a number representing 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
,
posix
,
time
import
string
from
stat
import
*
secs_per_year
=
365.0
*
24.0
*
3600.0
now
=
time
.
time
()
status
=
0
# Use lstat() to stat files if it exists, else stat()
try
:
statfunc
=
posix
.
lstat
except
NameError
:
statfunc
=
posix
.
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
file
in
sys
.
argv
[
1
:]:
if
len
(
file
)
>
maxlen
:
maxlen
=
len
(
file
)
# Process each argument in turn
for
file
in
sys
.
argv
[
1
:]:
try
:
st
=
posix
.
stat
(
file
)
st
=
statfunc
(
file
)
except
posix
.
error
,
msg
:
sys
.
stderr
.
write
(
'can
\
'
t stat '
+
`file`
+
': '
+
`msg`
+
'
\
n
'
)
status
=
1
st
=
()
if
st
:
mtime
=
st
[
ST_MTIME
]
anytime
=
st
[
itime
]
size
=
st
[
ST_SIZE
]
age
=
now
-
m
time
age
=
now
-
any
time
byteyears
=
float
(
size
)
*
float
(
age
)
/
secs_per_year
print
file
+
'
\
t
\
t
'
+
`int(byteyears)`
print
string
.
ljust
(
file
,
maxlen
),
print
string
.
rjust
(
`int(byteyears)`
,
8
)
sys
.
exit
(
status
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment