MCPcopy Create free account
hub / github.com/alibaba/BladeDISC / ensure_empty_dir

Function ensure_empty_dir

scripts/python/common_setup.py:153–171  ·  view source on GitHub ↗

Make sure the given directory exists and is empty. This function will create an empty directory if the directory doesn't exits, or it will clean all content under the directory. Hidden files and sub direcotries will be deleted if clear_hidden is True.

(dir, clear_hidden=True)

Source from the content-addressed store, hash-verified

151
152
153def ensure_empty_dir(dir, clear_hidden=True):
154 """
155 Make sure the given directory exists and is empty.
156 This function will create an empty directory if the directory doesn't exits,
157 or it will clean all content under the directory. Hidden files and sub
158 direcotries will be deleted if clear_hidden is True.
159 """
160 if not os.path.exists(dir):
161 logger.info("make dir: " + dir)
162 os.makedirs(dir)
163 return
164 logger.info("clear dir: {}, clear hidden files: {}".format(dir, clear_hidden))
165 for filename in os.listdir(dir):
166 if clear_hidden or not filename.startswith("."):
167 file_path = os.path.join(dir, filename)
168 if os.path.isfile(file_path) or os.path.islink(file_path):
169 os.unlink(file_path)
170 else:
171 shutil.rmtree(file_path, ignore_errors=True)
172
173
174def which(cmd):

Callers 1

config_mkldnnFunction · 0.70

Calls 2

existsMethod · 0.80
formatMethod · 0.45

Tested by

no test coverage detected