projects
/
python_utils.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Adds logging in light stuff, minor changes in config/string.
[python_utils.git]
/
file_utils.py
diff --git
a/file_utils.py
b/file_utils.py
index 525a1afb0e262e93082f91dc8860a932575ed27a..7270e30b1fe1513746aaf986e87269968787e842 100644
(file)
--- a/
file_utils.py
+++ b/
file_utils.py
@@
-50,26
+50,48
@@
def create_path_if_not_exist(path, on_error=None):
def does_file_exist(filename: str) -> bool:
def does_file_exist(filename: str) -> bool:
+ """Returns True if a file exists and is a normal file.
+
+ >>> does_file_exist(__file__)
+ True
+ """
return os.path.exists(filename) and os.path.isfile(filename)
def does_directory_exist(dirname: str) -> bool:
return os.path.exists(filename) and os.path.isfile(filename)
def does_directory_exist(dirname: str) -> bool:
+ """Returns True if a file exists and is a directory.
+
+ >>> does_directory_exist('/tmp')
+ True
+ """
return os.path.exists(dirname) and os.path.isdir(dirname)
def does_path_exist(pathname: str) -> bool:
return os.path.exists(dirname) and os.path.isdir(dirname)
def does_path_exist(pathname: str) -> bool:
+ """Just a more verbose wrapper around os.path.exists."""
return os.path.exists(pathname)
def get_file_size(filename: str) -> int:
return os.path.exists(pathname)
def get_file_size(filename: str) -> int:
+ """Returns the size of a file in bytes."""
return os.path.getsize(filename)
def is_normal_file(filename: str) -> bool:
return os.path.getsize(filename)
def is_normal_file(filename: str) -> bool:
+ """Returns True if filename is a normal file.
+
+ >>> is_normal_file(__file__)
+ True
+ """
return os.path.isfile(filename)
def is_directory(filename: str) -> bool:
return os.path.isfile(filename)
def is_directory(filename: str) -> bool:
+ """Returns True if filename is a directory.
+
+ >>> is_directory('/tmp')
+ True
+ """
return os.path.isdir(filename)
return os.path.isdir(filename)
@@
-274,3
+296,8
@@
class FileWriter(object):
if (ret >> 8) != 0:
raise Exception(f'{cmd} failed, exit value {ret>>8}')
return None
if (ret >> 8) != 0:
raise Exception(f'{cmd} failed, exit value {ret>>8}')
return None
+
+
+if __name__ == '__main__':
+ import doctest
+ doctest.testmod()