Skip to content

Commit ca3f00f

Browse files
committed
Rename methods for creating missing directory names
1 parent 2127a52 commit ca3f00f

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

lib_common/src/d1_common/util.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,18 @@ def abs_path(rel_path):
6565
)
6666

6767

68-
def ensure_dir_exists(dir_path):
68+
def create_missing_directories(dir_path):
6969
try:
7070
os.makedirs(dir_path)
7171
except OSError as e:
7272
if e.errno != errno.EEXIST:
7373
raise
7474

7575

76+
def create_missing_directories_for_file(file_path):
77+
create_missing_directories(os.path.dirname(file_path))
78+
79+
7680
def get_content_type(content_type):
7781
m = email.message.Message()
7882
m['Content-Type'] = content_type
@@ -139,8 +143,11 @@ def count(self, event_str, inc_int=1):
139143
self._event_dict.setdefault(event_str, 0)
140144
self._event_dict[event_str] += inc_int
141145

142-
def log_and_count(self, event_str, inc_int=1):
143-
logging.info(event_str)
146+
def log_and_count(self, event_str, log_str=None, inc_int=1):
147+
"""{event_str} is both a key for the count and part of the log message.
148+
{log_str} is a message with details that may change for each call
149+
"""
150+
logging.info(event_str + ('. ' + log_str if log_str else ''))
144151
self.count(event_str, inc_int)
145152

146153
def dump_to_log(self):

test_utilities/src/d1_test/sample.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ def start_tidy():
5252
logging.info('Moving files to tidy dir')
5353
sample_dir_path = os.path.join(d1_common.util.abs_path('test_docs'))
5454
tidy_dir_path = os.path.join(d1_common.util.abs_path('test_docs_tidy'))
55-
d1_common.util.ensure_dir_exists(sample_dir_path)
56-
d1_common.util.ensure_dir_exists(tidy_dir_path)
55+
d1_common.util.create_missing_directories(sample_dir_path)
56+
d1_common.util.create_missing_directories(tidy_dir_path)
5757
i = 0
5858
for i, item_name in enumerate(os.listdir(sample_dir_path)):
5959
sample_path = os.path.join(sample_dir_path, item_name)

0 commit comments

Comments
 (0)