add remove_file() and remove_directory() helpers

these functions call os.unlink() or os.rmdir()
while catching and suppressing potential OSErrors
This commit is contained in:
Mike Fährmann
2020-01-17 23:51:07 +01:00
parent b2d542ad40
commit 760b9b4db4
3 changed files with 24 additions and 21 deletions

View File

@@ -121,6 +121,20 @@ def expand_path(path):
return os.path.expandvars(os.path.expanduser(path))
def remove_file(path):
try:
os.unlink(path)
except OSError:
pass
def remove_directory(path):
try:
os.rmdir(path)
except OSError:
pass
def code_to_language(code, default=None):
"""Map an ISO 639-1 language code to its actual name"""
return CODES.get((code or "").lower(), default)