]> Frank Brehm's Git Trees - pixelpark/admin-tools.git/commitdiff
Checking existence of home dir
authorFrank Brehm <frank.brehm@pixelpark.com>
Mon, 20 Mar 2017 12:23:14 +0000 (13:23 +0100)
committerFrank Brehm <frank.brehm@pixelpark.com>
Mon, 20 Mar 2017 12:23:14 +0000 (13:23 +0100)
pp_lib/mk_home_app.py

index f47ffdfab63acd39441844f5b4b29fd67f213a44..dab2979f0635a7c4c86727d91df3e37d6b45412e 100644 (file)
@@ -17,6 +17,7 @@ import re
 import traceback
 import textwrap
 import copy
+import shutil
 
 # Third party modules
 import six
@@ -38,7 +39,7 @@ from .merge import merge_structure
 
 from .ldap_app import PpLdapAppError, PpLdapApplication
 
-__version__ = '0.3.2'
+__version__ = '0.3.3'
 LOG = logging.getLogger(__name__)
 
 
@@ -233,6 +234,21 @@ class PpMkHomeApp(PpLdapApplication):
             home = entry['homeDirectory'][0]
             LOG.debug("Checking home directory {!r} ...".format(home))
 
+            chroot_dir = os.path.join(
+                self.chroot_homedir, os.path.relpath(home, os.sep))
+            if self.verbose > 1:
+                LOG.debug("Checking existence of {!r} ...".format(chroot_dir))
+
+            if os.path.exists(chroot_dir):
+                if os.path.isdir(chroot_dir):
+                    if self.verbose > 2:
+                        LOG.debug("Directory {!r} is already existing.".format(chroot_dir))
+                else:
+                    LOG.error("Directory {!r} exists, but is NOT a directory.".format(chroot_dir))
+                continue
+
+            LOG.info("Creating home directory {!r} ....".format(chroot_dir))
+
             if i >= 5:
                 break