Completed
Push — master ( ea37f3...9aacac )
by Thomas
11:37
created

exabgp.environment.getconf()   A

Complexity

Conditions 3

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 7
nop 1
dl 0
loc 14
rs 10
c 0
b 0
f 0
1
import os
2
3
# this is where the environment should be taken from
4
# it makes sure the environment is setup before it is imported
5
import exabgp.environment.setup
6
7
from exabgp.environment.environment import Env
8
9
from exabgp.environment.base import APPLICATION
10
from exabgp.environment.base import ENVFILE
11
from exabgp.environment.base import ROOT
12
from exabgp.environment.base import ETC
13
14
# As soon as we import anything, a COPY is made in the local
15
# namespace, it mean that we can not import the GlobalHashTable
16
# directly but must ask for a copy to be made each time
17
# at the time of import, so using a function get around it
18
from exabgp.environment.hashtable import GlobalHashTable as __
19
20
21
def getenv():
22
    return __()
23
24
25
def getconf(name):
26
    # some users are using symlinks for atomic change of the configuration file
27
    # using mv may however be better practice :p
28
    # so we must not follow symlink when looking for the file
29
30
    if name.startswith('etc/exabgp'):
31
        normalised = os.path.join(ETC, name[11:])
32
    else:
33
        normalised = os.path.normpath(name)
34
35
    if os.path.isfile(os.path.realpath(normalised)):
36
        return normalised
37
38
    return ''
39