Completed
Push — master ( 4f59bf...f4be26 )
by Authorize.Net
8s
created

helper.getproperty()   F

Complexity

Conditions 10

Size

Total Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
c 4
b 0
f 0
dl 0
loc 28
rs 3.1304
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
from ConfigParser import SafeConfigParser
8
from ConfigParser import NoSectionError
9
import os
10
import sys
11
#from __future__ import print_function
12
13
class helper(): 
14
    __parser = "null"
15
    __propertyfilename = "null"
16
    __initialized = False
17
    
18
    @staticmethod
19
    def getparser():
20
        return helper.__parser
21
    
22
    @staticmethod
23
    def getpropertyfile():
24
        return helper.__propertyfilename
25
26
    @staticmethod
27
    def setpropertyfile(propertyfilename):
28
        if (propertyfilename == 'null' or os.path.isfile(propertyfilename) == False):
29
            helper.__propertyfilename = 'null' 
30
        else:     
31
            helper.__propertyfilename = propertyfilename
32
        return
33
34
    @staticmethod
35
    def __classinitialized():
36
        return helper.__initialized
37
    
38
    @staticmethod
39
    def getproperty(propertyname):
40
        stringvalue = "null"
41
42
        if ('null' != helper.getpropertyfile()):
43
            if (False == helper.__classinitialized()):
44
                if ('null' == helper.getparser()):
45
                    try:
46
                        helper.__parser = SafeConfigParser({"http":"","https":"","ftp":""})
47
                    except:
48
                        print ("Parser could not be initialized")
49
50
                if ('null' != helper.getparser()):
51
                    try:
52
                        helper.getparser().read(helper.__propertyfilename)
53
                        helper.__initialized = True
54
                    except:
55
                        print ("Unable to load the property file")
56
57
        if (True == helper.__classinitialized()):
58
            try:
59
                stringvalue = helper.getparser().get("properties", propertyname)
60
            except:
61
                sys.stderr.write("%s not found" %propertyname )
62
                
63
        if ( "null" == stringvalue):
64
            stringvalue = os.getenv(propertyname)               
65
        return stringvalue