Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
KADMOS
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
LR-FPP-MDO
KADMOS
Commits
33cdd29f
Commit
33cdd29f
authored
7 years ago
by
imcovangent
Browse files
Options
Downloads
Patches
Plain Diff
Added utility function for file size determination.
Former-commit-id: 034561970dae25ae0b9c755129464f1e5fcf9755
parent
1548cb35
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
kadmos/utilities/general.py
+32
-0
32 additions, 0 deletions
kadmos/utilities/general.py
with
32 additions
and
0 deletions
kadmos/utilities/general.py
+
32
−
0
View file @
33cdd29f
...
...
@@ -624,3 +624,35 @@ def translate_dict_keys(dictionary, translations):
dictionary
[
key
]
=
value
return
dictionary
def
convert_bytes
(
num
):
"""
this function will convert bytes to MB.... GB... etc
"""
for
x
in
[
'
bytes
'
,
'
KB
'
,
'
MB
'
,
'
GB
'
,
'
TB
'
]:
if
num
<
1024.0
:
return
"
%3.1f %s
"
%
(
num
,
x
)
num
/=
1024.0
def
file_size
(
file_path
):
"""
this function will return the file size
"""
if
os
.
path
.
isfile
(
file_path
):
file_info
=
os
.
stat
(
file_path
)
return
convert_bytes
(
file_info
.
st_size
)
else
:
raise
IOError
(
'
Could not find file: {}
'
.
format
(
file_path
))
def
file_size_MB
(
file_path
):
"""
this function will return the file size
"""
if
os
.
path
.
isfile
(
file_path
):
file_info
=
os
.
stat
(
file_path
)
return
file_info
.
st_size
/
1024.0
/
1024.0
else
:
raise
IOError
(
'
Could not find file: {}
'
.
format
(
file_path
))
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment