helper.getproperty()   F
last analyzed

Complexity

Conditions 10

Size

Total Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 28
rs 3.1304
c 0
b 0
f 0
cc 10

How to fix   Complexity   

Complexity

Complex classes like helper.getproperty() often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

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