helper   A
last analyzed

Complexity

Total Complexity 16

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 16
dl 0
loc 53
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getparser() 0 3 1
A getpropertyfile() 0 3 1
A __classinitialized() 0 3 1
A setpropertyfile() 0 7 3
F getproperty() 0 28 10
1
'''
2
Created on Nov 4, 2015
3
4
@author: krgupta
5
'''
6
7
try:
8
    from ConfigParser import SafeConfigParser
9
    from ConfigParser import NoSectionError
10
except ImportError:
11
    from configparser import SafeConfigParser
12
    from configparser import NoSectionError
13
14
import os
15
import sys
16
import logging
17
#from __future__ import print_function
18
19
logger = logging.getLogger(__name__)
20
21
class helper(): 
22
    __parser = "null"
23
    __propertyfilename = "null"
24
    __initialized = False
25
    
26
    @staticmethod
27
    def getparser():
28
        return helper.__parser
29
    
30
    @staticmethod
31
    def getpropertyfile():
32
        return helper.__propertyfilename
33
34
    @staticmethod
35
    def setpropertyfile(propertyfilename):
36
        if (propertyfilename == 'null' or os.path.isfile(propertyfilename) == False):
37
            helper.__propertyfilename = 'null' 
38
        else:     
39
            helper.__propertyfilename = propertyfilename
40
        return
41
42
    @staticmethod
43
    def __classinitialized():
44
        return helper.__initialized
45
    
46
    @staticmethod
47
    def getproperty(propertyname):
48
        stringvalue = "null"
49
50
        if ('null' != helper.getpropertyfile()):
51
            if (False == helper.__classinitialized()):
52
                if ('null' == helper.getparser()):
53
                    try:
54
                        helper.__parser = SafeConfigParser({"http":"","https":"","ftp":""})
55
                    except:
56
                        logger.debug("Parser could not be initialized")
57
58
                if ('null' != helper.getparser()):
59
                    try:
60
                        helper.getparser().read(helper.__propertyfilename)
61
                        helper.__initialized = True
62
                    except:
63
                        logger.debug("Unable to load the property file")
64
65
        if (True == helper.__classinitialized()):
66
            try:
67
                stringvalue = helper.getparser().get("properties", propertyname)
68
            except:
69
                logger.debug("'%s' not found\n" %propertyname )
70
                
71
        if ( "null" == stringvalue):
72
            stringvalue = os.getenv(propertyname)               
73
        return stringvalue