Commit c03949db by Peter Weidenbach

cleanup and license change

parent cdec6f04
# Common Helper Files
File and filesystem related helper functions.
File and filesystem related helper functions incl.:
* Fail safe file operations: *They log errors but never throw an exception*
* Git version string generator
* Large file handling
## Known Issues
It seems that recent versions of setuptools can't handle a "." in the requirements list.
......
from .file_functions import read_in_chunks, get_directory_for_filename, create_dir_for_file, human_readable_file_size
from .git_functions import get_version_string_from_git
from .hash_functions import md5sum
from .fail_safe_file_operations import get_binary_from_file, get_string_list_from_file, write_binary_to_file, get_safe_name, delete_file, get_files_in_dir, get_dirs_in_dir
from .config_functions import update_config_from_env
__version__ = '0.1.7'
......@@ -12,7 +10,6 @@ __all__ = [
'human_readable_file_size',
'read_in_chunks',
'get_version_string_from_git',
'md5sum',
'get_binary_from_file',
'get_string_list_from_file',
'write_binary_to_file',
......@@ -20,5 +17,4 @@ __all__ = [
'delete_file',
'get_files_in_dir',
'get_dirs_in_dir',
'update_config_from_env'
]
"""Helper functions for configuration files.
"""
import os
import logging
log = logging.getLogger(__name__)
def update_config_from_env(config):
""" Update configuration fields in config from environment variables.
The environment variable names are expected to be of the form, that the
section name and the variable name are seperated by a dubble underscore,
e.g.
SECTION_NAME__VARIABLE_NAME
"""
for key, val in os.environ.items():
if '__' in key:
section, section_key = key.lower().split('__')
try:
config[section.capitalize()][section_key] = val
except KeyError:
log.error('No section {} or value {} found.'.format(section.capitalize(), section_key))
return config
import hashlib
from .file_functions import read_in_chunks
def md5sum(file_object):
m = hashlib.md5()
for data in read_in_chunks(file_object):
m.update(data)
return m.hexdigest().lower()
hurry.filesize >= 0.9
\ No newline at end of file
......@@ -6,8 +6,11 @@ setup(
version=__version__,
packages=find_packages(),
install_requires=[
'hurry.filesize >= 0.9'
'hurry.filesize'
],
description="file operation helper functions",
license="MIT License"
author="Fraunhofer FKIE",
author_email="peter.weidenbach@fkie.fraunhofer.de",
url="http://www.fkie.fraunhofer.de",
license="GPL-3.0"
)
import unittest
import os
from tempfile import TemporaryDirectory
import unittest
from common_helper_files import get_binary_from_file,\
write_binary_to_file, delete_file, get_safe_name,\
get_files_in_dir, get_string_list_from_file,\
from common_helper_files import get_binary_from_file, \
write_binary_to_file, delete_file, get_safe_name, \
get_files_in_dir, get_string_list_from_file, \
get_dirs_in_dir, get_directory_for_filename
from common_helper_files.fail_safe_file_operations import _get_counted_file_path
......
'''
Created on Dec 5, 2016
@author: weidenba
'''
import unittest
from common_helper_files.file_functions import human_readable_file_size
from common_helper_files import human_readable_file_size
class Test_file_functions(unittest.TestCase):
......
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