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
cdec6f04
Commit
cdec6f04
authored
Jul 17, 2017
by
Peter Weidenbach
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
get_dirs_in_dir function added
parent
1be772aa
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
7 deletions
+41
-7
__init__.py
common_helper_files/__init__.py
+4
-3
fail_safe_file_operations.py
common_helper_files/fail_safe_file_operations.py
+20
-0
test_fail_safe_file_operations.py
tests/test_fail_safe_file_operations.py
+17
-4
No files found.
common_helper_files/__init__.py
View file @
cdec6f04
from
.file_functions
import
read_in_chunks
,
get_directory_for_filename
,
create_dir_for_file
,
human_readable_file_size
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
.git_functions
import
get_version_string_from_git
from
.hash_functions
import
md5sum
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
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
from
.config_functions
import
update_config_from_env
__version__
=
'0.1.
6
'
__version__
=
'0.1.
7
'
__all__
=
[
__all__
=
[
'get_directory_for_filename'
,
'get_directory_for_filename'
,
...
@@ -19,5 +19,6 @@ __all__ = [
...
@@ -19,5 +19,6 @@ __all__ = [
'get_safe_name'
,
'get_safe_name'
,
'delete_file'
,
'delete_file'
,
'get_files_in_dir'
,
'get_files_in_dir'
,
'update_config_from_env'
,
'get_dirs_in_dir'
,
'update_config_from_env'
]
]
common_helper_files/fail_safe_file_operations.py
View file @
cdec6f04
...
@@ -143,3 +143,23 @@ def get_files_in_dir(directory_path):
...
@@ -143,3 +143,23 @@ def get_files_in_dir(directory_path):
except
Exception
as
e
:
except
Exception
as
e
:
logging
.
error
(
"Could not get files: {} {}"
.
format
(
sys
.
exc_info
()[
0
]
.
__name__
,
e
))
logging
.
error
(
"Could not get files: {} {}"
.
format
(
sys
.
exc_info
()[
0
]
.
__name__
,
e
))
return
result
return
result
def
get_dirs_in_dir
(
directory_path
):
"""
Returns a list with the absolute paths of all 1st level sub-directories in the directory directory_path.
:param directory_path: directory including sub-directories
:type directory_path: str
:return: list
"""
result
=
[]
try
:
dir_content
=
os
.
listdir
(
directory_path
)
for
item
in
dir_content
:
dir_path
=
os
.
path
.
join
(
directory_path
,
item
)
if
os
.
path
.
isdir
(
dir_path
):
result
.
append
(
dir_path
)
except
Exception
as
e
:
logging
.
error
(
"Could not get directories: {} {}"
.
format
(
sys
.
exc_info
()[
0
]
.
__name__
,
e
))
return
result
tests/test_fail_safe_file_operations.py
View file @
cdec6f04
...
@@ -2,10 +2,11 @@ import unittest
...
@@ -2,10 +2,11 @@ import unittest
import
os
import
os
from
tempfile
import
TemporaryDirectory
from
tempfile
import
TemporaryDirectory
from
common_helper_files.fail_safe_file_operations
import
get_binary_from_file
,
\
from
common_helper_files
import
get_binary_from_file
,
\
write_binary_to_file
,
delete_file
,
get_safe_name
,
_get_counted_file_path
,
\
write_binary_to_file
,
delete_file
,
get_safe_name
,
\
get_files_in_dir
,
get_string_list_from_file
get_files_in_dir
,
get_string_list_from_file
,
\
from
common_helper_files.file_functions
import
get_directory_for_filename
get_dirs_in_dir
,
get_directory_for_filename
from
common_helper_files.fail_safe_file_operations
import
_get_counted_file_path
class
Test_FailSafeFileOperations
(
unittest
.
TestCase
):
class
Test_FailSafeFileOperations
(
unittest
.
TestCase
):
...
@@ -87,5 +88,17 @@ class Test_FailSafeFileOperations(unittest.TestCase):
...
@@ -87,5 +88,17 @@ class Test_FailSafeFileOperations(unittest.TestCase):
result
=
get_files_in_dir
(
"/none_existing/dir"
)
result
=
get_files_in_dir
(
"/none_existing/dir"
)
self
.
assertEqual
(
result
,
[],
"error result should be an empty list"
)
self
.
assertEqual
(
result
,
[],
"error result should be an empty list"
)
def
test_get_dirs
(
self
):
test_dirs
=
[
"dir_1"
,
"dir_2"
,
"dir_1/sub_dir"
]
for
item
in
test_dirs
:
os
.
mkdir
(
os
.
path
.
join
(
self
.
tmp_dir
.
name
,
item
))
result
=
get_dirs_in_dir
(
self
.
tmp_dir
.
name
)
self
.
assertEqual
(
sorted
(
result
),
[
os
.
path
.
join
(
self
.
tmp_dir
.
name
,
"dir_1"
),
os
.
path
.
join
(
self
.
tmp_dir
.
name
,
"dir_2"
)],
"found dirs not correct"
)
def
test_get_dirs_in_dir_error
(
self
):
result
=
get_dirs_in_dir
(
"/none_existing/dir"
)
self
.
assertEqual
(
result
,
[],
"error result should be an empty list"
)
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
unittest
.
main
()
unittest
.
main
()
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