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-depend
common_helper_files
Commits
f8792d09
Commit
f8792d09
authored
Jul 24, 2017
by
Peter Weidenbach
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
get_dir_of_file_function added
parent
5c99beab
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
3 deletions
+32
-3
__init__.py
common_helper_files/__init__.py
+4
-2
fail_safe_file_operations.py
common_helper_files/fail_safe_file_operations.py
+16
-0
test_fail_safe_file_operations.py
tests/test_fail_safe_file_operations.py
+12
-1
No files found.
common_helper_files/__init__.py
View file @
f8792d09
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
,
create_symlink
,
get_dir_of_file
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
.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
,
create_symlink
__version__
=
'0.1.8'
__version__
=
'0.1.9'
__all__
=
[
'get_directory_for_filename'
,
...
...
@@ -18,4 +19,5 @@ __all__ = [
'create_symlink'
,
'get_files_in_dir'
,
'get_dirs_in_dir'
,
'get_dir_of_file'
]
common_helper_files/fail_safe_file_operations.py
View file @
f8792d09
...
...
@@ -183,3 +183,19 @@ def get_dirs_in_dir(directory_path):
except
Exception
as
e
:
logging
.
error
(
"Could not get directories: {} {}"
.
format
(
sys
.
exc_info
()[
0
]
.
__name__
,
e
))
return
result
def
get_dir_of_file
(
file_path
):
"""
Returns absolute path of the directory including file
:param file_path: Paht of the file
:type: paht-like object
:return: string
"""
try
:
return
os
.
path
.
dirname
(
os
.
path
.
abspath
(
file_path
))
except
Exception
as
e
:
logging
.
error
(
"Could not get directory path: {} {}"
.
format
(
sys
.
exc_info
()[
0
]
.
__name__
,
e
))
return
"/"
tests/test_fail_safe_file_operations.py
View file @
f8792d09
...
...
@@ -6,7 +6,7 @@ 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
,
\
create_symlink
create_symlink
,
get_dir_of_file
from
common_helper_files.fail_safe_file_operations
import
_get_counted_file_path
...
...
@@ -107,6 +107,17 @@ class Test_FailSafeFileOperations(unittest.TestCase):
result
=
get_dirs_in_dir
(
"/none_existing/dir"
)
self
.
assertEqual
(
result
,
[],
"error result should be an empty list"
)
def
test_get_dir_of_file_relative_path
(
self
):
relative_path_result
=
get_dir_of_file
(
"test/some_file"
)
expected_result
=
os
.
path
.
join
(
os
.
getcwd
(),
"test"
)
self
.
assertEqual
(
relative_path_result
,
expected_result
)
def
test_get_dir_of_file_absolute_path
(
self
):
test_file_path
=
os
.
path
.
join
(
self
.
tmp_dir
.
name
,
'test_file'
)
write_binary_to_file
(
'test'
,
test_file_path
)
absolute_file_path_result
=
get_dir_of_file
(
test_file_path
)
self
.
assertEqual
(
absolute_file_path_result
,
self
.
tmp_dir
.
name
)
if
__name__
==
"__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