Statistics
| Branch: | Tag: | Revision:

root / snf-common / synnefo / settings / __init__.py @ d509e6da

History | View | Annotate | Download (3.2 kB)

1 efcd7a43 Kostas Papadimitriou
# Copyright 2011 GRNET S.A. All rights reserved.
2 efcd7a43 Kostas Papadimitriou
#
3 efcd7a43 Kostas Papadimitriou
# Redistribution and use in source and binary forms, with or
4 efcd7a43 Kostas Papadimitriou
# without modification, are permitted provided that the following
5 efcd7a43 Kostas Papadimitriou
# conditions are met:
6 efcd7a43 Kostas Papadimitriou
#
7 efcd7a43 Kostas Papadimitriou
#   1. Redistributions of source code must retain the above
8 efcd7a43 Kostas Papadimitriou
#      copyright notice, this list of conditions and the following
9 efcd7a43 Kostas Papadimitriou
#      disclaimer.
10 efcd7a43 Kostas Papadimitriou
#
11 efcd7a43 Kostas Papadimitriou
#   2. Redistributions in binary form must reproduce the above
12 efcd7a43 Kostas Papadimitriou
#      copyright notice, this list of conditions and the following
13 efcd7a43 Kostas Papadimitriou
#      disclaimer in the documentation and/or other materials
14 efcd7a43 Kostas Papadimitriou
#      provided with the distribution.
15 efcd7a43 Kostas Papadimitriou
#
16 efcd7a43 Kostas Papadimitriou
# THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS
17 efcd7a43 Kostas Papadimitriou
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 efcd7a43 Kostas Papadimitriou
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 efcd7a43 Kostas Papadimitriou
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR
20 efcd7a43 Kostas Papadimitriou
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 efcd7a43 Kostas Papadimitriou
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 efcd7a43 Kostas Papadimitriou
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23 efcd7a43 Kostas Papadimitriou
# USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
24 efcd7a43 Kostas Papadimitriou
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 efcd7a43 Kostas Papadimitriou
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
26 efcd7a43 Kostas Papadimitriou
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 efcd7a43 Kostas Papadimitriou
# POSSIBILITY OF SUCH DAMAGE.
28 efcd7a43 Kostas Papadimitriou
#
29 efcd7a43 Kostas Papadimitriou
# The views and conclusions contained in the software and
30 efcd7a43 Kostas Papadimitriou
# documentation are those of the authors and should not be
31 efcd7a43 Kostas Papadimitriou
# interpreted as representing official policies, either expressed
32 efcd7a43 Kostas Papadimitriou
# or implied, of GRNET S.A.
33 efcd7a43 Kostas Papadimitriou
34 d2ff89df Kostas Papadimitriou
import os
35 34d1013b Vangelis Koukis
import sys
36 efcd7a43 Kostas Papadimitriou
37 7fb619a0 Kostas Papadimitriou
from synnefo.util.entry_points import extend_settings
38 45832bda Kostas Papadimitriou
39 6740cd3a Kostas Papadimitriou
# set synnefo package __file__ to fix django related bug
40 3015903d Kostas Papadimitriou
import synnefo
41 6740cd3a Kostas Papadimitriou
synnefo.__file__ = os.path.join(synnefo.__path__[0], '__init__.py')
42 6740cd3a Kostas Papadimitriou
43 7fb619a0 Kostas Papadimitriou
# import default settings
44 7fb619a0 Kostas Papadimitriou
from synnefo.settings.default import *
45 7fb619a0 Kostas Papadimitriou
46 7fb619a0 Kostas Papadimitriou
# autodetect default settings provided by synnefo applications
47 2ce0636e Kostas Papadimitriou
extend_settings(__name__, 'synnefo')
48 efcd7a43 Kostas Papadimitriou
49 7fb619a0 Kostas Papadimitriou
# extend default settings with settings provided within *.conf user files
50 7fb619a0 Kostas Papadimitriou
# located in directory specified in the SYNNEFO_SETTINGS_DIR
51 c24ca4e8 Vangelis Koukis
# environment variable
52 7fb619a0 Kostas Papadimitriou
SYNNEFO_SETTINGS_DIR = os.environ.get('SYNNEFO_SETTINGS_DIR', "/etc/synnefo/")
53 34d1013b Vangelis Koukis
if os.path.exists(SYNNEFO_SETTINGS_DIR):
54 c24ca4e8 Vangelis Koukis
    try:
55 c24ca4e8 Vangelis Koukis
        entries = [os.path.join(SYNNEFO_SETTINGS_DIR, x) for x in
56 c24ca4e8 Vangelis Koukis
                   os.listdir(SYNNEFO_SETTINGS_DIR)]
57 c24ca4e8 Vangelis Koukis
        conffiles = [f for f in entries if os.path.isfile(f) and
58 c24ca4e8 Vangelis Koukis
                     f.endswith(".conf")]
59 c24ca4e8 Vangelis Koukis
    except Exception as e:
60 d509e6da Stratos Psomadakis
        print >> sys.stderr, "Failed to list *.conf files under %s" % \
61 d509e6da Stratos Psomadakis
                             SYNNEFO_SETTINGS_DIR
62 c24ca4e8 Vangelis Koukis
        raise SystemExit(1)
63 d2ff89df Kostas Papadimitriou
    conffiles.sort()
64 d2ff89df Kostas Papadimitriou
    for f in conffiles:
65 34d1013b Vangelis Koukis
        try:
66 34d1013b Vangelis Koukis
            execfile(os.path.abspath(f))
67 34d1013b Vangelis Koukis
        except Exception as e:
68 d509e6da Stratos Psomadakis
            print >> sys.stderr, "Failed to read settings file: %s [%r]" % \
69 d509e6da Stratos Psomadakis
                                 (os.path.abspath(f), e)
70 c24ca4e8 Vangelis Koukis
            raise SystemExit(1)
71 d509e6da Stratos Psomadakis
72 d509e6da Stratos Psomadakis
73 d509e6da Stratos Psomadakis
from os import environ
74 d509e6da Stratos Psomadakis
# The tracing code is enabled by an environmental variable and not a synnefo
75 d509e6da Stratos Psomadakis
# setting, on purpose, so that you can easily control whether it'll get loaded
76 d509e6da Stratos Psomadakis
# or not, based on context (eg enable it for gunicorn but not for eventd).
77 d509e6da Stratos Psomadakis
if environ.get('SYNNEFO_TRACE'):
78 d509e6da Stratos Psomadakis
    from synnefo.lib import trace
79 d509e6da Stratos Psomadakis
    trace.set_signal_trap()