util
index
e:\projects\soft_tools\smart_hasher\repo\smart_hasher\smart_hasher\util.py

 
Modules
       
math
msvcrt
os
time

 
Classes
       
builtins.Exception(builtins.BaseException)
AppUsageError

 
class AppUsageError(builtins.Exception)
    This exception is raised when error occurs due to the incorrect usage of the application by user
 
Ref: https://docs.python.org/3/library/exceptions.html
Ref: https://stackoverflow.com/questions/1319615/proper-way-to-declare-custom-exceptions-in-modern-python
 
 
Method resolution order:
AppUsageError
builtins.Exception
builtins.BaseException
builtins.object

Data descriptors defined here:
__weakref__
list of weak references to the object (if defined)

Methods inherited from builtins.Exception:
__init__(self, /, *args, **kwargs)
Initialize self.  See help(type(self)) for accurate signature.

Static methods inherited from builtins.Exception:
__new__(*args, **kwargs) from builtins.type
Create and return a new object.  See help(type) for accurate signature.

Methods inherited from builtins.BaseException:
__delattr__(self, name, /)
Implement delattr(self, name).
__getattribute__(self, name, /)
Return getattr(self, name).
__reduce__(...)
Helper for pickle.
__repr__(self, /)
Return repr(self).
__setattr__(self, name, value, /)
Implement setattr(self, name, value).
__setstate__(...)
__str__(self, /)
Return str(self).
with_traceback(...)
Exception.with_traceback(tb) --
set self.__traceback__ to tb and return self.

Data descriptors inherited from builtins.BaseException:
__cause__
exception cause
__context__
exception context
__dict__
__suppress_context__
__traceback__
args

 
Functions
       
convert_size_to_display(size_bytes: float) -> str
This function convert size in bytes to human readable presentation.
 
Ref: "Better way to convert file sizes in Python" https://stackoverflow.com/a/14822210/13441
drive_normcase(path)
Norm case for drive letter.
Note this is not the same as `normcase()` for path.
format_seconds(seconds: float) -> str
seconds = int(diff.total_seconds());
is_program_interrupted_by_user()
Ref: https://stackoverflow.com/questions/24072790/detect-key-press-in-python
pause(pause_duration=30)
Pause with support of interruption by user
 
pause_duration - duration of pause, seconds.
Returns:
    True if pause worked fine
    False if program interruped
 
Ref: https://wiki.python.org/moin/ForLoop
Ref: https://stackoverflow.com/questions/44834493/a-single-python-loop-from-zero-to-n-to-zero
rel_file_path(work_file_name, base_file_name, return_absolute_path=False)
Note, last part after slash in input file names are considered as file name, not a folder
 
if return_absolute_path == False
    then returns file with path for `work_file_name` relative to `base_file_name`.
    In other words this function show how to traverse from one file to other.
    Note, if `work_file_name` and `base_file_name` point to different disks then relative path can't be returned, so absolute path returned.
 
if return_absolute_path == True
    then returns absolute path for `work_file_name`
    if `work_file_name` is relative than it is considered as relative to `base_file_name`,
    and function return absolute path accounting this.
    if `work_file_name` is absolute than it is returned.
 
Ref: https://stackoverflow.com/questions/10149263/extract-a-part-of-the-filepath-a-directory-in-python
Ref: https://stackoverflow.com/a/7288073/13441

 
Data
        size_names = ('B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB')