Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
common_helper_files
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
fact-gitdep
common_helper_files
Commits
0ad47f89
Commit
0ad47f89
authored
Aug 17, 2017
by
Peter Weidenbach
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
hurry.filesize replaced with bitmath
parent
3de2ab42
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
21 additions
and
25 deletions
+21
-25
__init__.py
common_helper_files/__init__.py
+1
-1
file_functions.py
common_helper_files/file_functions.py
+11
-10
requirements.txt
requirements.txt
+0
-2
setup.py
setup.py
+7
-7
test_file_functions.py
tests/test_file_functions.py
+2
-5
No files found.
common_helper_files/__init__.py
View file @
0ad47f89
...
...
@@ -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'
,
...
...
common_helper_files/file_functions.py
View file @
0ad47f89
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}'
)
requirements.txt
deleted
100644 → 0
View file @
3de2ab42
hurry.filesize
\ No newline at end of file
setup.py
View file @
0ad47f89
...
...
@@ -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'
)
tests/test_file_functions.py
View file @
0ad47f89
...
...
@@ -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'
)
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