MCPcopy Index your code
hub / github.com/Bitmessage/PyBitmessage / apiInit

Function apiInit

src/bitmessagecli.py:78–156  ·  view source on GitHub ↗
(apiEnabled)

Source from the content-addressed store, hash-verified

76 print ' You will now need to configure the ' + str(keysName) + ' file.\n'
77
78def apiInit(apiEnabled):
79 global usrPrompt
80 BMConfigParser().read(keysPath)
81
82
83
84 if (apiEnabled == False): #API information there but the api is disabled.
85 uInput = userInput("The API is not enabled. Would you like to do that now, (Y)es or (N)o?").lower()
86
87 if uInput == "y": #
88 BMConfigParser().set('bitmessagesettings','apienabled','true') #Sets apienabled to true in keys.dat
89 with open(keysPath, 'wb') as configfile:
90 BMConfigParser().write(configfile)
91
92 print 'Done'
93 restartBmNotify()
94 return True
95
96 elif uInput == "n":
97 print ' \n************************************************************'
98 print ' Daemon will not work when the API is disabled. '
99 print ' Please refer to the Bitmessage Wiki on how to setup the API.'
100 print ' ************************************************************\n'
101 usrPrompt = 1
102 main()
103
104 else:
105 print '\n Invalid Entry\n'
106 usrPrompt = 1
107 main()
108 elif (apiEnabled == True): #API correctly setup
109 #Everything is as it should be
110 return True
111
112 else: #API information was not present.
113 print '\n ' + str(keysPath) + ' not properly configured!\n'
114 uInput = userInput("Would you like to do this now, (Y)es or (N)o?").lower()
115
116 if uInput == "y": #User said yes, initalize the api by writing these values to the keys.dat file
117 print ' '
118
119 apiUsr = userInput("API Username")
120 apiPwd = userInput("API Password")
121 #apiInterface = userInput("API Interface. (127.0.0.1)")
122 apiPort = userInput("API Port")
123 apiEnabled = userInput("API Enabled? (True) or (False)").lower()
124 daemon = userInput("Daemon mode Enabled? (True) or (False)").lower()
125
126 if (daemon != 'true' and daemon != 'false'):
127 print '\n Invalid Entry for Daemon.\n'
128 uInput = 1
129 main()
130
131 print ' -----------------------------------\n'
132
133 BMConfigParser().set('bitmessagesettings', 'port', '8444') #sets the bitmessage port to stop the warning about the api not properly being setup. This is in the event that the keys.dat is in a different directory or is created locally to connect to a machine remotely.
134 BMConfigParser().set('bitmessagesettings','apienabled','true')
135 BMConfigParser().set('bitmessagesettings', 'apiport', apiPort)

Callers 1

apiDataFunction · 0.85

Calls 7

BMConfigParserClass · 0.90
userInputFunction · 0.85
restartBmNotifyFunction · 0.85
readMethod · 0.80
setMethod · 0.80
mainFunction · 0.70
writeMethod · 0.45

Tested by

no test coverage detected