python modules as user configuration files

Rob Hooft rob at hooft.net
Fri Apr 6 04:37:54 EDT 2001


I use the following:

-------------------------------------------------------------------
#
__version__ = '$Id: config.py,v 1.139 2001/04/06 08:04:01 hooft Exp $'
#
# Configurable GUI parameters (like colors)
#
i_am_a_developer=0
background='red'
[...100 variables omitted...]
xwindows=11

# System-level and User-level changes.
_gl=globals().keys()
import os
for _filename in ["/usr/local/lib/nonius-config.py",
		  os.environ["HOME"]+"/.nonius-config",
		  "nonius-config"]:
    if os.path.exists(_filename):
	_filestatus=os.stat(_filename)
	_filemode=_filestatus[0]
	_fileuid=_filestatus[4]
	if (_fileuid==os.getuid() or _fileuid==0):
	    if _filemode&002==0:
		execfile(_filename)
	    else:
		print "WARNING: Skipped '%s': writeable by others."%_filename
	else:
	    print "WARNING: Skipped '%s': owned by someone else."%_filename
	del _filemode,_fileuid,_filestatus
del os,_filename
# Test for obsoleted and/or unknown variables.
for _key in globals().keys():
    if _key in _gl or _key[0]=='_':
        pass
    elif _key=='userpc':
        print "WARNING: Configuration variable 'userpc' obsolete"
        print "         please change your configuration files accordingly"
    else:
        print "WARNING: Configuration variable %s not known. Misspelled?"%_key
del _gl

if __name__=="__main__":
    k=globals().keys()
    k.sort()
    for name in k:
        if name[0]!='_':
            print name,"=",repr(globals()[name])
---------------------------------------------------
-- 
=====   rob at hooft.net          http://www.hooft.net/people/rob/  =====
=====   R&D, Nonius BV, Delft  http://www.nonius.nl/             =====
===== PGPid 0xFA19277D ========================== Use Linux! =========



More information about the Python-list mailing list