Arthur de Jong

Open Source / Free Software developer

summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArthur de Jong <arthur@arthurdejong.org>2011-12-28 23:44:33 +0100
committerArthur de Jong <arthur@arthurdejong.org>2011-12-28 23:44:33 +0100
commit3d99c1858d014e2cadc8fc4ed72c5697e47becb8 (patch)
treef2069ce1f8ac210ea217c00f66cfc1485c67c8d4
parentf3b540ab73daa8ac88002e1f6f32101eff85e3fd (diff)
move the state variables (from command line) from the configuration to the main module
git-svn-id: http://arthurdejong.org/svn/nss-pam-ldapd/nss-pam-ldapd@1580 ef36b2f9-881f-0410-afb5-c4e39611909c
-rw-r--r--pynslcd/cfg.py10
-rwxr-xr-xpynslcd/pynslcd.py31
2 files changed, 23 insertions, 18 deletions
diff --git a/pynslcd/cfg.py b/pynslcd/cfg.py
index acdac39..8677679 100644
--- a/pynslcd/cfg.py
+++ b/pynslcd/cfg.py
@@ -20,17 +20,9 @@
import ldap
-# these values are defined here
-
-# the name of the program
-program_name = 'pynslcd'
-# the debugging level
-debug = 0
-# whether the --check option was passed
-check = False
+
# the number of threads to start
threads = 5
-
# the user id nslcd should be run as
uid = None
# the group id nslcd should be run as
diff --git a/pynslcd/pynslcd.py b/pynslcd/pynslcd.py
index c7d2cea..2e7998e 100755
--- a/pynslcd/pynslcd.py
+++ b/pynslcd/pynslcd.py
@@ -37,6 +37,16 @@ import common
from tio import TIOStream
+# the name of the program
+program_name = 'pynslcd'
+
+# flag to indicate whether we are in debugging mode
+debugging = 0
+
+# flag to indicate user requested the --check option
+checkonly = False
+
+
# configure logging
class MyFormatter(logging.Formatter):
def format(self, record):
@@ -81,22 +91,25 @@ def display_usage(fp):
" --version output version information and exit\n"
"\n"
"Report bugs to <%(PACKAGE_BUGREPORT)s>.\n"
- % {'program_name': cfg.program_name,
+ % {'program_name': program_name,
'PACKAGE_BUGREPORT': config.PACKAGE_BUGREPORT, })
def parse_cmdline():
"""Parse command-line arguments."""
import getopt
- cfg.program_name = sys.argv[0] or 'pynslcd'
+ global program_name
+ program_name = sys.argv[0] or program_name
try:
optlist, args = getopt.gnu_getopt(sys.argv[1:],
'cdhV', ('check', 'debug', 'help', 'version', ))
for flag, arg in optlist:
if flag in ('-c', '--check'):
- cfg.check = True
+ global checkonly
+ checkonly = True
elif flag in ('-d', '--debug'):
- cfg.debug += 1
+ global debugging
+ debugging += 1
elif flag in ('-h', '--help'):
display_usage(sys.stdout)
sys.exit(0)
@@ -108,7 +121,7 @@ def parse_cmdline():
except getopt.GetoptError, reason:
sys.stderr.write("%(program_name)s: %(reason)s\n"
"Try '%(program_name)s --help' for more information.\n"
- % {'program_name': cfg.program_name,
+ % {'program_name': program_name,
'reason': reason, })
sys.exit(1)
@@ -222,7 +235,7 @@ if __name__ == '__main__':
# disable ldap lookups of host names to avoid lookup loop
disable_nss_ldap()
# set log level
- if cfg.debug:
+ if debugging:
logging.getLogger().setLevel(logging.DEBUG)
# FIXME: implement
#if myldap_set_debuglevel(cfg.debug) != LDAP_SUCCESS:
@@ -234,7 +247,7 @@ if __name__ == '__main__':
# see if someone already locked the pidfile
pidfile = mypidfile.MyPIDLockFile(config.NSLCD_PIDFILE)
# see if --check option was given
- if cfg.check:
+ if checkonly:
if pidfile.is_locked():
logging.debug('pidfile (%s) is locked', config.NSLCD_PIDFILE)
sys.exit(0)
@@ -246,7 +259,7 @@ if __name__ == '__main__':
logging.error('daemon may already be active, cannot acquire lock (%s)', config.NSLCD_PIDFILE)
sys.exit(1)
# daemonize
- if cfg.debug:
+ if debugging:
daemon = pidfile
else:
daemon = daemon.DaemonContext(
@@ -259,7 +272,7 @@ if __name__ == '__main__':
# start daemon
with daemon:
# start normal logging
- if not cfg.debug:
+ if not debugging:
log_startlogging()
logging.info('version %s starting', config.VERSION)
# create socket