summaryrefslogtreecommitdiffstats
path: root/base/server/python/pki/server
diff options
context:
space:
mode:
authorEndi S. Dewata <edewata@redhat.com>2016-12-20 17:59:18 +0100
committerEndi S. Dewata <edewata@redhat.com>2016-12-21 03:04:34 +0100
commit9822676b7f00cc7e78d42c50c2506a289ed9c1c6 (patch)
tree0334a13706461c47fb6c4f39c46810ede4fd29cf /base/server/python/pki/server
parent843cbeed6ddab8f1883abce47a8c45e0fa14fc5a (diff)
downloadpki-9822676b7f00cc7e78d42c50c2506a289ed9c1c6.tar.gz
pki-9822676b7f00cc7e78d42c50c2506a289ed9c1c6.tar.xz
pki-9822676b7f00cc7e78d42c50c2506a289ed9c1c6.zip
Refactored pki_copytree().
The pki_copytree() has been moved from pkihelper.py into pki/util.py such that it can be reused in non-deployment scenarios.
Diffstat (limited to 'base/server/python/pki/server')
-rw-r--r--base/server/python/pki/server/deployment/pkihelper.py80
1 files changed, 2 insertions, 78 deletions
diff --git a/base/server/python/pki/server/deployment/pkihelper.py b/base/server/python/pki/server/deployment/pkihelper.py
index 7ca6519c9..1a09f4964 100644
--- a/base/server/python/pki/server/deployment/pkihelper.py
+++ b/base/server/python/pki/server/deployment/pkihelper.py
@@ -28,11 +28,6 @@ import fileinput
import re
import requests.exceptions
import shutil
-from shutil import Error
-try:
- from shutil import WindowsError # pylint: disable=E0611
-except ImportError:
- WindowsError = None
import subprocess
import time
from datetime import datetime
@@ -52,6 +47,7 @@ from . import pkimessages as log
from .pkiparser import PKIConfigParser
import pki.client
import pki.system
+import pki.util
# special care for SELinux
import selinux
@@ -66,78 +62,6 @@ if selinux.is_selinux_enabled():
raise
-# PKI Deployment Helper Functions
-def pki_copytree(src, dst, symlinks=False, ignore=None):
- """Recursively copy a directory tree using copy2().
-
- PATCH: This code was copied from 'shutil.py' and patched to
- allow 'The destination directory to already exist.'
-
- If exception(s) occur, an Error is raised with a list of reasons.
-
- If the optional symlinks flag is true, symbolic links in the
- source tree result in symbolic links in the destination tree; if
- it is false, the contents of the files pointed to by symbolic
- links are copied.
-
- The optional ignore argument is a callable. If given, it
- is called with the `src` parameter, which is the directory
- being visited by pki_copytree(), and `names` which is the list of
- `src` contents, as returned by os.listdir():
-
- callable(src, names) -> ignored_names
-
- Since pki_copytree() is called recursively, the callable will be
- called once for each directory that is copied. It returns a
- list of names relative to the `src` directory that should
- not be copied.
-
- *** Consider this example code rather than the ultimate tool.
-
- """
- names = os.listdir(src)
- if ignore is not None:
- ignored_names = ignore(src, names)
- else:
- ignored_names = set()
-
- # PATCH: ONLY execute 'os.makedirs(dst)' if the top-level
- # destination directory does NOT exist!
- if not os.path.exists(dst):
- os.makedirs(dst)
- errors = []
- for name in names:
- if name in ignored_names:
- continue
- srcname = os.path.join(src, name)
- dstname = os.path.join(dst, name)
- try:
- if symlinks and os.path.islink(srcname):
- linkto = os.readlink(srcname)
- os.symlink(linkto, dstname)
- elif os.path.isdir(srcname):
- pki_copytree(srcname, dstname, symlinks, ignore)
- else:
- # Will raise a SpecialFileError for unsupported file types
- shutil.copy2(srcname, dstname)
- # catch the Error from the recursive pki_copytree so that we can
- # continue with other files
- except Error as err:
- errors.extend(err.args[0])
- except EnvironmentError as why:
- errors.append((srcname, dstname, str(why)))
- try:
- shutil.copystat(src, dst)
- except OSError as why:
- if WindowsError is not None and isinstance(why, WindowsError):
- # Copying file access times may fail on Windows
- pass
- else:
- errors.extend((src, dst, str(why)))
- if errors:
- raise Error(errors)
-
-
class Identity:
"""PKI Deployment Identity Class"""
@@ -1481,7 +1405,7 @@ class Directory:
# implementation's unchecked call to 'os.makedirs(dst)'.
# Consequently, a 'patched' local copy of this routine has
# been included in this file with the appropriate fix.
- pki_copytree(old_name, new_name, ignore=ignore_cb)
+ pki.util.copytree(old_name, new_name, ignore=ignore_cb)
else:
# cp -p <old_name> <new_name>
config.pki_log.info(log.PKIHELPER_CP_P_2,