- Timestamp:
- 05/04/12 16:14:01 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sara_cmt/sara_cmt/settings.py
r14158 r14161 1 1 2 import os, sys, ConfigParser, site2 import os, os.path, sys, ConfigParser, site, string, time 3 3 4 4 from socket import gethostbyname_ex 5 5 6 # Path's customizable through virtualenv 7 sample_configfile = '%s/etc/cmt/cmt.conf.sample' % site.sys.prefix 6 8 configfile = '%s/etc/cmt/cmt.conf' % site.sys.prefix 9 10 def count_configlines( filename ): 11 12 line_count = 0 13 cfg_fp = open( filename ) 14 15 for line in cfg_fp.readlines(): 16 17 line = line.strip() 18 19 if len( line ) == 0: 20 continue 21 22 # RB: ConfigParser considers lines starting with # or ; as comments 23 if line[0] == '#' or line[0] == ';': 24 continue 25 26 line_count += 1 27 28 cfg_fp.close() 29 30 return line_count 31 32 if not os.path.exists( configfile ): 33 34 print 'Unable to find confilefile: %s' %configfile 35 36 if os.path.exists( sample_configfile ): 37 38 print 'Please modify the sample config file: %s to reflect your settings' %sample_configfile 39 print 'and then rename it to: %s' %configfile 40 41 else: 42 43 print 'Also no sample config file was found: %s' %sample_configfile 44 print 'Something is terribly wrong here ;)' 45 46 print '' 47 print 'Fatal: Giving up and exiting now..' 48 49 sys.exit(1) 50 51 # We are still here: both configfile AND sample_configfile found 52 if exists( sample_configfile ): 53 54 # Is the sample configfile newer? 55 if os.path.getmtime( sample_configfile ) > os.path.getmtime( configfile ): 56 57 # Well this is weird, but not fatal 58 print 'Warning: sample config file(%s) is newer than original config(%s)' %(configfile, sample_configfile) 59 60 # Does the sample config file contain more options? 61 if count_configlines( sample_configfile ) > count_configlines( configfile ): 62 63 print 'Warning: sample config file contains MORE OPTIONS than original config!' 64 print '' 65 print 'This happens for example if you upgraded CMT and the new release incorporates new configuration options!' 66 print '' 67 print 'Please update your original config(%s) to incorporate the new config options from sample config(%s)' %( configfile, sample_configfile ) 68 print '' 69 70 else: 71 # Config is good but mtime is older, weird.. Just print hint 72 print 'Hint: Remove sample config file(%s) to get rid of this warning..' %sample_configfile 73 74 # Give them some time to think about warnings and generally annoy them just enough to fix it 75 time.sleep(2) 76 77 # Moving right along; print empty line for cosmetic reasons 78 print '' 7 79 8 80 config = ConfigParser.RawConfigParser() … … 10 82 11 83 try: 12 DATABASE_USER 13 DATABASE_PASSWORD 14 DATABASE_HOST 15 DATABASE_ENGINE 16 DATABASE_NAME 84 DATABASE_USER = config.get('database', 'USER') 85 DATABASE_PASSWORD = config.get('database', 'PASSWORD') 86 DATABASE_HOST = config.get('database', 'HOST') 87 DATABASE_ENGINE = config.get('database', 'ENGINE') 88 DATABASE_NAME = config.get('database', 'NAME') 17 89 18 90 except (ConfigParser.NoOptionError, ConfigParser.NoSectionError), details: 19 91 20 92 print 'Config file error: %s' %str(details) 93 print '' 94 print 'Giving up and exiting now..' 21 95 sys.exit(1) 22 96 … … 37 111 try: 38 112 gethostbyname_ex( DATABASE_HOST ) 113 39 114 except socket.gaierror, details: 115 40 116 print 'Unable to resolve database host: %s' %DATABASE_HOST 41 print 'Exiting.' 117 print '' 118 print 'Giving up and exiting now..' 42 119 sys.exit(1) 43 120
Note: See TracChangeset
for help on using the changeset viewer.