]> Frank Brehm's Git Trees - pixelpark/admin-tools.git/commitdiff
Trying some changes because of Python2
authorFrank Brehm <frank.brehm@pixelpark.com>
Fri, 30 Jun 2017 14:39:13 +0000 (16:39 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Fri, 30 Jun 2017 14:39:13 +0000 (16:39 +0200)
pp_lib/quota_check.py
quota-check

index 84172577a4a591b1447a0bd8f54b2fc0d99e3b29..402ddd8eeb1ab05c02fb82b837c3a6d833a40248 100644 (file)
@@ -44,7 +44,24 @@ from .cfg_app import PpCfgAppError, PpConfigApplication
 
 __version__ = '0.5.4'
 LOG = logging.getLogger(__name__)
-UTC = datetime.timezone.utc
+ZERO = datetime.timedelta(0)
+
+# A Utc class.
+
+class Utc(datetime.tzinfo):
+    """Utc"""
+
+    def utcoffset(self, dt):
+        return ZERO
+
+    def tzname(self, dt):
+        return "UTC"
+
+    def dst(self, dt):
+        return ZERO
+
+UTC = Utc()
+# UTC = datetime.timezone.utc
 
 
 # =============================================================================
@@ -379,6 +396,7 @@ class PpQuotaCheckApp(PpConfigApplication):
         LOG.info("Writing status data from {!r} ...".format(self.statusfile))
 
         if self.verbose > 2:
+            # LOG.debug("Status to write:\n{!r}".format(self.status_data))
             LOG.debug("Status to write:\n{}".format(pp(self.status_data)))
 
         open_args = {}
@@ -389,9 +407,13 @@ class PpQuotaCheckApp(PpConfigApplication):
         if not os.path.exists(self.status_dir):
             LOG.info("Creating {!r} ...".format(self.status_dir))
             mode = stat.S_IRWXU | stat.S_IRGRP | stat.S_IWGRP | stat.S_IROTH | stat.S_IXOTH
-            os.makedirs(self.status_dir, mode, exist_ok=True)
+            try:
+                os.makedirs(self.status_dir, mode)
+            except os.error as e:
+                LOG.error("Could not create {!r}: {}".format(self.status_dir, e))
+                sys.exit(9)
         elif not os.path.isdir(self.status_dir):
-            msg = "Status directory {!r} exists, but is ot a directory.".format(self.status_dir)
+            msg = "Status directory {!r} exists, but is not a directory.".format(self.status_dir)
             LOG.error(msg)
             return
 
@@ -468,6 +490,25 @@ class PpQuotaCheckApp(PpConfigApplication):
 
         LOG.info("Checking utilization of home directories ...")
 
+        # Senseless opening of all user home directories to activate automounter
+        for user_name in self.passwd_data:
+            entry = self.passwd_data[user_name]
+            pwd_home_dir = entry.pw_dir
+            if not pwd_home_dir:
+                continue
+            if not pwd_home_dir.startswith(self.home_root_abs):
+                if self.verbose > 2:
+                    LOG.debug("Home dir {!r} is not below {!r}.".format(pwd_home_dir, self.home_root_abs))
+                continue
+            abs_home_dir = os.path.join(self.chroot_homedir, os.path.relpath(pwd_home_dir, os.sep))
+            LOG.debug("Trying to open {!r} ...".format(abs_home_dir))
+            try:
+                os.listdir(abs_home_dir)
+                if self.verbose > 2:
+                    LOG.debug("Found home directory {!r} ...".format(abs_home_dir))
+            except OSError as e:
+                LOG.warn("Directory {!r} does not exists.".format(abs_home_dir))
+
         glob_pattern = os.path.join(self.home_root_real, '*')
         all_home_entries = glob.glob(glob_pattern)
 
@@ -492,6 +533,9 @@ class PpQuotaCheckApp(PpConfigApplication):
         i = 0
 
         for path in all_home_entries:
+
+            LOG.debug("Searching for {!r} ...".format(path))
+
             if not os.path.isdir(path):
                 continue
             number_dirs += 1
index c168f0ae1c8132cb99f00900e9977f02a8c033a3..af4613042cb39c00af2602765465eb4cfdc23d1c 100755 (executable)
@@ -1,4 +1,7 @@
-#!/usr/bin/env python3
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+from __future__ import print_function
 
 # Standard modules
 import sys
@@ -26,7 +29,13 @@ __copyright__ = '(C) 2017 by Frank Brehm, Pixelpark GmbH, Berlin'
 
 appname = os.path.basename(sys.argv[0])
 
-locale.setlocale(locale.LC_ALL, 'de_DE.utf8')
+for loc in ('de_DE.utf8', 'en_US.UTF-8'):
+    try:
+        locale.setlocale(locale.LC_ALL, loc)
+        break
+    except locale.Error as e:
+        sys.stderr.write("Locale %r not supported: %s\n" % (loc, e))
+        continue
 
 app = PpQuotaCheckApp(appname=appname)
 app.initialized = True