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

helper   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getparser() 0 3 1
F getproperty() 0 28 10
A getpropertyfile() 0 3 1
A __classinitialized() 0 3 1
A setpropertyfile() 0 7 3
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