summaryrefslogtreecommitdiffstats
path: root/ipapython
diff options
context:
space:
mode:
authorChristian Heimes <cheimes@redhat.com>2017-10-20 11:10:20 +0200
committerStanislav Laznicka <slaznick@redhat.com>2017-10-20 12:27:19 +0200
commitb29db07c3b3d8937f53684fdbba985fec525d69d (patch)
treedde1a80e83816e4d4e98597905d407fa24135f05 /ipapython
parentfad88b358b6bd40b96ea7db11c2d7ed148225d06 (diff)
downloadfreeipa-b29db07c3b3d8937f53684fdbba985fec525d69d.tar.gz
freeipa-b29db07c3b3d8937f53684fdbba985fec525d69d.tar.xz
freeipa-b29db07c3b3d8937f53684fdbba985fec525d69d.zip
Use os.path.isfile() and isdir()
Replace custom file_exists() and dir_exists() functions with proper functions from Python's stdlib. The change also gets rid of pylint's invalid bad-python3-import error, https://github.com/PyCQA/pylint/issues/1565 Signed-off-by: Christian Heimes <cheimes@redhat.com> Reviewed-By: Stanislav Laznicka <slaznick@redhat.com>
Diffstat (limited to 'ipapython')
-rw-r--r--ipapython/ipautil.py20
1 files changed, 2 insertions, 18 deletions
diff --git a/ipapython/ipautil.py b/ipapython/ipautil.py
index c5c5e9e21..71ed4a174 100644
--- a/ipapython/ipautil.py
+++ b/ipapython/ipautil.py
@@ -29,7 +29,6 @@ import math
import os
import sys
import copy
-import stat
import shutil
import socket
import re
@@ -543,31 +542,16 @@ def nolog_replace(string, nolog):
return string
-def file_exists(filename):
- try:
- mode = os.stat(filename)[stat.ST_MODE]
- return bool(stat.S_ISREG(mode))
- except Exception:
- return False
-
-def dir_exists(filename):
- try:
- mode = os.stat(filename)[stat.ST_MODE]
- return bool(stat.S_ISDIR(mode))
- except Exception:
- return False
-
-
def install_file(fname, dest):
# SELinux: use copy to keep the right context
- if file_exists(dest):
+ if os.path.isfile(dest):
os.rename(dest, dest + ".orig")
shutil.copy(fname, dest)
os.remove(fname)
def backup_file(fname):
- if file_exists(fname):
+ if os.path.isfile(fname):
os.rename(fname, fname + ".orig")