__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
# =============================================================================
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 = {}
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
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)
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
-#!/usr/bin/env python3
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+from __future__ import print_function
# Standard modules
import sys
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