equal
deleted
inserted
replaced
1 # copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
1 # copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
3 # |
3 # |
4 # This file is part of CubicWeb. |
4 # This file is part of CubicWeb. |
5 # |
5 # |
6 # CubicWeb is free software: you can redistribute it and/or modify it under the |
6 # CubicWeb is free software: you can redistribute it and/or modify it under the |
34 |
34 |
35 from logilab.common.clcommands import Command as BaseCommand |
35 from logilab.common.clcommands import Command as BaseCommand |
36 from logilab.common.compat import any |
36 from logilab.common.compat import any |
37 from logilab.common.shellutils import ASK |
37 from logilab.common.shellutils import ASK |
38 |
38 |
39 from cubicweb import warning |
39 from cubicweb import warning # pylint: disable=E0611 |
40 from cubicweb import ConfigurationError, ExecutionError |
40 from cubicweb import ConfigurationError, ExecutionError |
41 |
41 |
42 def underline_title(title, car='-'): |
42 def underline_title(title, car='-'): |
43 return title+'\n'+(car*len(title)) |
43 return title+'\n'+(car*len(title)) |
44 |
44 |
157 log('set permissions to 0600 for %s', filepath) |
157 log('set permissions to 0600 for %s', filepath) |
158 else: |
158 else: |
159 print '-> set permissions to 0600 for %s' % filepath |
159 print '-> set permissions to 0600 for %s' % filepath |
160 chmod(filepath, 0600) |
160 chmod(filepath, 0600) |
161 |
161 |
162 def read_config(config_file): |
162 def read_config(config_file, raise_if_unreadable=False): |
163 """read the instance configuration from a file and return it as a |
163 """read some simple configuration from `config_file` and return it as a |
164 dictionnary |
164 dictionary. If `raise_if_unreadable` is false (the default), an empty |
165 |
165 dictionary will be returned if the file is inexistant or unreadable, else |
166 :type config_file: str |
166 :exc:`ExecutionError` will be raised. |
167 :param config_file: path to the configuration file |
|
168 |
|
169 :rtype: dict |
|
170 :return: a dictionary with specified values associated to option names |
|
171 """ |
167 """ |
172 from logilab.common.fileutils import lines |
168 from logilab.common.fileutils import lines |
173 config = current = {} |
169 config = current = {} |
174 try: |
170 try: |
175 for line in lines(config_file, comments='#'): |
171 for line in lines(config_file, comments='#'): |
188 continue |
184 continue |
189 option = option.strip().replace(' ', '_') |
185 option = option.strip().replace(' ', '_') |
190 value = value.strip() |
186 value = value.strip() |
191 current[option] = value or None |
187 current[option] = value or None |
192 except IOError, ex: |
188 except IOError, ex: |
193 warning('missing or non readable configuration file %s (%s)', |
189 if raise_if_unreadable: |
194 config_file, ex) |
190 raise ExecutionError('%s. Are you logged with the correct user ' |
|
191 'to use this instance?' % ex) |
|
192 else: |
|
193 warning('missing or non readable configuration file %s (%s)', |
|
194 config_file, ex) |
195 return config |
195 return config |
196 |
196 |
197 |
197 |
198 _HDLRS = {} |
198 _HDLRS = {} |
199 |
199 |