57 def create_dir(directory): |
57 def create_dir(directory): |
58 """create a directory if it doesn't exist yet""" |
58 """create a directory if it doesn't exist yet""" |
59 try: |
59 try: |
60 makedirs(directory) |
60 makedirs(directory) |
61 print '-> created directory %s' % directory |
61 print '-> created directory %s' % directory |
62 except OSError, ex: |
62 except OSError as ex: |
63 import errno |
63 import errno |
64 if ex.errno != errno.EEXIST: |
64 if ex.errno != errno.EEXIST: |
65 raise |
65 raise |
66 print '-> no need to create existing directory %s' % directory |
66 print '-> no need to create existing directory %s' % directory |
67 |
67 |
174 except ValueError: |
174 except ValueError: |
175 option = line.strip().lower() |
175 option = line.strip().lower() |
176 if option[0] == '[': |
176 if option[0] == '[': |
177 # start a section |
177 # start a section |
178 section = option[1:-1] |
178 section = option[1:-1] |
179 assert not config.has_key(section), \ |
179 assert section not in config, \ |
180 'Section %s is defined more than once' % section |
180 'Section %s is defined more than once' % section |
181 config[section] = current = {} |
181 config[section] = current = {} |
182 continue |
182 continue |
183 sys.stderr.write('ignoring malformed line\n%r\n' % line) |
183 sys.stderr.write('ignoring malformed line\n%r\n' % line) |
184 continue |
184 continue |
185 option = option.strip().replace(' ', '_') |
185 option = option.strip().replace(' ', '_') |
186 value = value.strip() |
186 value = value.strip() |
187 current[option] = value or None |
187 current[option] = value or None |
188 except IOError, ex: |
188 except IOError as ex: |
189 if raise_if_unreadable: |
189 if raise_if_unreadable: |
190 raise ExecutionError('%s. Are you logged with the correct user ' |
190 raise ExecutionError('%s. Are you logged with the correct user ' |
191 'to use this instance?' % ex) |
191 'to use this instance?' % ex) |
192 else: |
192 else: |
193 warning('missing or non readable configuration file %s (%s)', |
193 warning('missing or non readable configuration file %s (%s)', |