Skip to content

Commit e80ad89

Browse files
committed
adding import of calculation of folder size from utils
1 parent 092ea10 commit e80ad89

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

singularity/package.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from singularity.logman import bot
99

1010
from singularity.utils import (
11+
calculate_folder_size,
1112
format_container_name,
1213
read_file,
1314
zip_up

singularity/tests/test_package.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,6 @@ def test_packaging(self):
6262
self.assertTrue(os.path.exists(image1_extraction))
6363
shutil.rmtree(os.path.dirname(image1_extraction))
6464

65+
6566
if __name__ == '__main__':
6667
unittest.main()

singularity/utils.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,24 @@ def read_file(filename,mode="r"):
229229
return content
230230

231231

232+
############################################################################
233+
## OTHER MISC. #############################################################
234+
############################################################################
235+
236+
237+
def calculate_folder_size(folder_path):
238+
'''calculate_folder size recursively walks a directory to calculate
239+
a total size (in)
240+
:param folder_path: the path to calculate size for
241+
'''
242+
total_size = 0
243+
for dirpath, dirnames, filenames in os.walk(folder_path):
244+
for filey in filenames:
245+
fp = os.path.join(dirpath, filey)
246+
total_size += os.path.getsize(fp)
247+
return total_size
248+
249+
232250
def remove_unicode_dict(input_dict):
233251
'''remove unicode keys and values from dict, encoding in utf8
234252
'''

0 commit comments

Comments
 (0)