configfile.py

changeset 146
c17b82b1f573
parent 132
a22c50f52a23
equal deleted inserted replaced
145:588aff83bb87 146:c17b82b1f573
24 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 ''' 27 '''
28 28
29 from __future__ import print_function
29 import json, sys 30 import json, sys
30 IsInitialized = False 31 IsInitialized = False
31 Config = None 32 Config = None
32 ConfigFileName = "" 33 ConfigFileName = ""
33 34
93 return 94 return
94 95
95 with open (ConfigFileName, 'w') as fp: 96 with open (ConfigFileName, 'w') as fp:
96 json.dump (self.obj, fp, sort_keys = True, indent = 1) 97 json.dump (self.obj, fp, sort_keys = True, indent = 1)
97 98
98 print "Config saved." 99 print ("""Config saved.""")
99 100
100 def find_developer_by_email (self, commit_email): 101 def find_developer_by_email (self, commit_email):
101 for developer, emails in self.get_value ('developer_emails', default={}).iteritems(): 102 for developer, emails in self.get_value ('developer_emails', default={}).items():
102 if commit_email in emails: 103 if commit_email in emails:
103 return developer 104 return developer
104 105
105 return '' 106 return ''
106 107
113 global IsInitialized 114 global IsInitialized
114 global ConfigFileName 115 global ConfigFileName
115 ConfigFileName = filename 116 ConfigFileName = filename
116 117
117 if not IsInitialized: 118 if not IsInitialized:
118 print """Loading configuration...""" 119 print ("""Loading configuration...""")
119 120
120 try: 121 try:
121 with open (filename, 'r') as fp: 122 with open (filename, 'r') as fp:
122 jsondata = json.loads (fp.read()) 123 jsondata = json.loads (fp.read())
123 except IOError as e: 124 except IOError as e:
124 print ("""couldn't open %s: %s""" % (filename, e)) 125 print ("""Couldn't open %s: %s""" % (filename, e))
125 quit() 126 quit()
126 127
127 global Config 128 global Config
128 Config = ConfigNode (jsondata, name=None, parent=None) 129 Config = ConfigNode (jsondata, name=None, parent=None)
129 IsInitialized = True 130 IsInitialized = True

mercurial