mirror of
https://github.com/aljazceru/python-teos.git
synced 2025-12-17 22:24:23 +01:00
Code clean up
Deletes debug/logging pair. Defines logging and bitcoin_cli as system-wide variables
This commit is contained in:
@@ -1,36 +1,25 @@
|
||||
import logging
|
||||
from sys import argv
|
||||
from getopt import getopt
|
||||
from threading import Thread
|
||||
from pisa import logging
|
||||
from pisa.api import start_api
|
||||
from pisa.tools import can_connect_to_bitcoind, in_correct_network
|
||||
from pisa.utils.authproxy import AuthServiceProxy
|
||||
from pisa.conf import BTC_RPC_USER, BTC_RPC_PASSWD, BTC_RPC_HOST, BTC_RPC_PORT, BTC_NETWORK, SERVER_LOG_FILE
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
debug = False
|
||||
opts, _ = getopt(argv[1:], 'd', ['debug'])
|
||||
for opt, arg in opts:
|
||||
if opt in ['-d', '--debug']:
|
||||
debug = True
|
||||
# FIXME: Leaving this here for future option/arguments
|
||||
pass
|
||||
|
||||
# Configure logging
|
||||
logging.basicConfig(format='%(asctime)s %(message)s', level=logging.INFO, handlers=[
|
||||
logging.FileHandler(SERVER_LOG_FILE),
|
||||
logging.StreamHandler()
|
||||
])
|
||||
if can_connect_to_bitcoind():
|
||||
if in_correct_network():
|
||||
# Fire the api
|
||||
start_api()
|
||||
|
||||
bitcoin_cli = AuthServiceProxy("http://%s:%s@%s:%d" % (BTC_RPC_USER, BTC_RPC_PASSWD, BTC_RPC_HOST,
|
||||
BTC_RPC_PORT))
|
||||
|
||||
if can_connect_to_bitcoind(bitcoin_cli):
|
||||
if in_correct_network(bitcoin_cli, BTC_NETWORK):
|
||||
# ToDo: This may not have to be a thead. The main thread only creates this and terminates.
|
||||
api_thread = Thread(target=start_api, args=[debug, logging])
|
||||
api_thread.start()
|
||||
else:
|
||||
logging.error("[Pisad] bitcoind is running on a different network, check conf.py and bitcoin.conf. "
|
||||
"Shutting down")
|
||||
|
||||
else:
|
||||
logging.error("[Pisad] can't connect to bitcoind. Shutting down")
|
||||
|
||||
Reference in New Issue
Block a user