1 # -*- coding: utf-8 -*- |
1 # -*- coding: utf-8 -*- |
2 # copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
2 # copyright 2003-2016 LOGILAB S.A. (Paris, FRANCE), all rights reserved. |
3 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
3 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr |
4 # |
4 # |
5 # This file is part of CubicWeb. |
5 # This file is part of CubicWeb. |
6 # |
6 # |
7 # CubicWeb is free software: you can redistribute it and/or modify it under the |
7 # CubicWeb is free software: you can redistribute it and/or modify it under the |
192 import re |
191 import re |
193 from smtplib import SMTP |
192 from smtplib import SMTP |
194 import stat |
193 import stat |
195 import sys |
194 import sys |
196 from threading import Lock |
195 from threading import Lock |
197 from warnings import warn, filterwarnings |
196 from warnings import filterwarnings |
198 |
197 |
199 from six import text_type |
198 from six import text_type |
200 |
199 |
201 from logilab.common.decorators import cached, classproperty |
200 from logilab.common.decorators import cached, classproperty |
202 from logilab.common.deprecation import deprecated |
201 from logilab.common.deprecation import deprecated |
218 try: |
217 try: |
219 return [c for c in CONFIGURATIONS if c.name == name][0] |
218 return [c for c in CONFIGURATIONS if c.name == name][0] |
220 except IndexError: |
219 except IndexError: |
221 raise ConfigurationError('no such config %r (check it exists with "cubicweb-ctl list")' % name) |
220 raise ConfigurationError('no such config %r (check it exists with "cubicweb-ctl list")' % name) |
222 |
221 |
|
222 |
223 def possible_configurations(directory): |
223 def possible_configurations(directory): |
224 """return a list of installed configurations in a directory |
224 """return a list of installed configurations in a directory |
225 according to \*-ctl files |
225 according to \*-ctl files |
226 """ |
226 """ |
227 return [name for name in ('repository', 'all-in-one') |
227 return [name for name in ('repository', 'all-in-one') |
228 if exists(join(directory, '%s.conf' % name))] |
228 if exists(join(directory, '%s.conf' % name))] |
|
229 |
229 |
230 |
230 def guess_configuration(directory): |
231 def guess_configuration(directory): |
231 """try to guess the configuration to use for a directory. If multiple |
232 """try to guess the configuration to use for a directory. If multiple |
232 configurations are found, ConfigurationError is raised |
233 configurations are found, ConfigurationError is raised |
233 """ |
234 """ |
234 modes = possible_configurations(directory) |
235 modes = possible_configurations(directory) |
235 if len(modes) != 1: |
236 if len(modes) != 1: |
236 raise ConfigurationError('unable to guess configuration from %r %s' |
237 raise ConfigurationError('unable to guess configuration from %r %s' |
237 % (directory, modes)) |
238 % (directory, modes)) |
238 return modes[0] |
239 return modes[0] |
|
240 |
239 |
241 |
240 def _find_prefix(start_path=None): |
242 def _find_prefix(start_path=None): |
241 """Return the prefix path of CubicWeb installation. |
243 """Return the prefix path of CubicWeb installation. |
242 |
244 |
243 Walk parent directories of `start_path` looking for one containing a |
245 Walk parent directories of `start_path` looking for one containing a |