Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F92795439
libsize.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Sat, Nov 23, 19:01
Size
1 KB
Mime Type
text/x-python
Expires
Mon, Nov 25, 19:01 (1 d, 21 h)
Engine
blob
Format
Raw Data
Handle
22515206
Attached To
R7581 SP4E Homework
libsize.py
View Options
from
__future__
import
print_function
,
division
import
os
import
sys
# Internal build script for generating debugging test .so size.
# Usage:
# python libsize.py file.so save.txt -- displays the size of file.so and, if save.txt exists, compares it to the
# size in it, then overwrites save.txt with the new size for future runs.
if
len
(
sys
.
argv
)
!=
3
:
sys
.
exit
(
"Invalid arguments: usage: python libsize.py file.so save.txt"
)
lib
=
sys
.
argv
[
1
]
save
=
sys
.
argv
[
2
]
if
not
os
.
path
.
exists
(
lib
):
sys
.
exit
(
"Error: requested file ({}) does not exist"
.
format
(
lib
))
libsize
=
os
.
path
.
getsize
(
lib
)
print
(
"------"
,
os
.
path
.
basename
(
lib
),
"file size:"
,
libsize
,
end
=
''
)
if
os
.
path
.
exists
(
save
):
with
open
(
save
)
as
sf
:
oldsize
=
int
(
sf
.
readline
())
if
oldsize
>
0
:
change
=
libsize
-
oldsize
if
change
==
0
:
print
(
" (no change)"
)
else
:
print
(
" (change of {:+} bytes = {:+.2%})"
.
format
(
change
,
change
/
oldsize
))
else
:
print
()
with
open
(
save
,
'w'
)
as
sf
:
sf
.
write
(
str
(
libsize
))
Event Timeline
Log In to Comment