Commit 0ad47f89 by Peter Weidenbach

hurry.filesize replaced with bitmath

parent 3de2ab42
......@@ -3,7 +3,7 @@ from .file_functions import read_in_chunks, get_directory_for_filename, create_d
from .git_functions import get_version_string_from_git
__version__ = '0.1.9'
__version__ = '0.2'
__all__ = [
'get_directory_for_filename',
......
import os
from hurry.filesize import size, alternative
import bitmath
def read_in_chunks(file_object, chunk_size=1024):
"""
'''
Helper function to read large file objects iteratively in smaller chunks. Can be used like this::
file_object = open('somelargefile.xyz', 'rb')
......@@ -14,7 +14,7 @@ def read_in_chunks(file_object, chunk_size=1024):
:param chunk_size: Number of bytes to read per chunk.
:type chunk_size: int
:return: Returns a generator to iterate over all chunks, see above for usage.
"""
'''
while True:
data = file_object.read(chunk_size)
if not data:
......@@ -23,34 +23,35 @@ def read_in_chunks(file_object, chunk_size=1024):
def get_directory_for_filename(filename):
"""
'''
Convenience function which returns the absolute path to the directory that contains the given file name.
:param filename: Path of the file. Can be absolute or relative to the current directory.
:type filename: str
:return: Absolute path of the directory
"""
'''
return os.path.dirname(os.path.abspath(filename))
def create_dir_for_file(file_path):
"""
'''
Creates all directories of file path. File path may include the file as well.
:param file_path: Path of the file. Can be absolute or relative to the current directory.
:type file_path: str
:return: None
"""
'''
directory = os.path.dirname(os.path.abspath(file_path))
os.makedirs(directory, exist_ok=True)
def human_readable_file_size(size_in_bytes):
"""
'''
Returns a nicly human readable file size
:param size_in_bytes: Size in Bytes
:type size_in_bytes: int
:return: str
"""
return size(size_in_bytes, system=alternative)
'''
tmp = bitmath.Byte(bytes=size_in_bytes).best_prefix()
return tmp.format('{value:.2f} {unit}')
hurry.filesize
\ No newline at end of file
......@@ -2,15 +2,15 @@ from setuptools import setup, find_packages
from common_helper_files import __version__
setup(
name="common_helper_files",
name='common_helper_files',
version=__version__,
packages=find_packages(),
install_requires=[
'hurry.filesize'
'bitmath'
],
description="file operation helper functions",
author="Fraunhofer FKIE",
author_email="peter.weidenbach@fkie.fraunhofer.de",
url="http://www.fkie.fraunhofer.de",
license="GPL-3.0"
description='file operation helper functions',
author='Fraunhofer FKIE',
author_email='peter.weidenbach@fkie.fraunhofer.de',
url='http://www.fkie.fraunhofer.de',
license='GPL-3.0'
)
......@@ -5,8 +5,5 @@ from common_helper_files import human_readable_file_size
class Test_file_functions(unittest.TestCase):
def test_human_readable_file_size(self):
self.assertEqual(human_readable_file_size(1024), "1 KB")
if __name__ == "__main__":
unittest.main()
self.assertEqual(human_readable_file_size(1024), '1.00 KiB')
self.assertEqual(human_readable_file_size(5000), '4.88 KiB')
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment