From: W. Trevor King Date: Thu, 24 Jan 2013 22:24:49 +0000 (-0500) Subject: mutt_ldap.py: Don't load the config file if were being imported as a library X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=8866b2b21769f25aa942ca3cca23f32d7775131c;p=mutt-ldap.git mutt_ldap.py: Don't load the config file if were being imported as a library --- diff --git a/mutt_ldap.py b/mutt_ldap.py index dab031c..64e4da4 100755 --- a/mutt_ldap.py +++ b/mutt_ldap.py @@ -65,8 +65,6 @@ CONFIG.set('system', 'output-encoding', '') # match .muttrc's $charset # HACK: Python 2.x support, see http://bugs.python.org/issue2128 CONFIG.set('system', 'argv-encoding', '') -CONFIG.read(_os_path.expanduser('~/.mutt-ldap.rc')) - class LDAPConnection (object): """Wrap an LDAP connection supporting the 'with' statement @@ -270,6 +268,8 @@ if __name__ == '__main__': import locale as _locale import sys as _sys + read_configfiles = CONFIG.read(_os_path.expanduser('~/.mutt-ldap.rc')) + default_encoding = _locale.getpreferredencoding(do_setlocale=True) for key in ['output-encoding', 'argv-encoding']: CONFIG.set( @@ -284,6 +284,8 @@ if __name__ == '__main__': argv_encoding = CONFIG.get('system', 'argv-encoding') _sys.argv = [unicode(arg, argv_encoding) for arg in _sys.argv] + LOG.info(u'loaded configuration from {0}'.format(read_configfiles)) + if len(_sys.argv) < 2: _sys.stderr.write( u'{0}: no search string given\n'.format(_sys.argv[0]))