move module cli entrypoints to __main__.py files

This commit is contained in:
Jack Robison 2022-03-29 16:06:44 -04:00
parent 0fd993d180
commit 5731016ca5
No known key found for this signature in database
GPG key ID: DF25C68FE0239BB2
8 changed files with 97 additions and 70 deletions

View file

@ -1 +1 @@
from .network import LBCTestNet, LBCRegTest, LBCMainNet
from scribe.blockchain.network import LBCTestNet, LBCRegTest, LBCMainNet

View file

@ -0,0 +1,27 @@
import logging
import traceback
import argparse
from scribe.env import Env
from scribe.common import setup_logging
from scribe.blockchain.service import BlockchainProcessorService
def main():
setup_logging()
parser = argparse.ArgumentParser(
prog='scribe'
)
Env.contribute_to_arg_parser(parser)
args = parser.parse_args()
try:
block_processor = BlockchainProcessorService(Env.from_arg_parser(args))
block_processor.run()
except Exception:
traceback.print_exc()
logging.critical('scribe terminated abnormally')
else:
logging.info('scribe terminated normally')
if __name__ == "__main__":
main()

View file

@ -1,64 +0,0 @@
import logging
import traceback
import argparse
from scribe.env import Env
from scribe.blockchain.service import BlockchainProcessorService
from scribe.hub.service import HubServerService
from scribe.elasticsearch.service import ElasticSyncService
def get_arg_parser(name):
parser = argparse.ArgumentParser(
prog=name
)
Env.contribute_to_arg_parser(parser)
return parser
def setup_logging():
logging.basicConfig(level=logging.INFO, format="%(asctime)s %(levelname)-4s %(name)s:%(lineno)d: %(message)s")
logging.getLogger('aiohttp').setLevel(logging.WARNING)
logging.getLogger('elasticsearch').setLevel(logging.WARNING)
def run_writer_forever():
setup_logging()
args = get_arg_parser('scribe').parse_args()
try:
block_processor = BlockchainProcessorService(Env.from_arg_parser(args))
block_processor.run()
except Exception:
traceback.print_exc()
logging.critical('scribe terminated abnormally')
else:
logging.info('scribe terminated normally')
def run_server_forever():
setup_logging()
args = get_arg_parser('scribe-hub').parse_args()
try:
server = HubServerService(Env.from_arg_parser(args))
server.run()
except Exception:
traceback.print_exc()
logging.critical('hub terminated abnormally')
else:
logging.info('hub terminated normally')
def run_es_sync_forever():
setup_logging()
parser = get_arg_parser('scribe-elastic-sync')
parser.add_argument('--reindex', type=bool, default=False)
args = parser.parse_args()
try:
server = ElasticSyncService(Env.from_arg_parser(args))
server.run(args.reindex)
except Exception:
traceback.print_exc()
logging.critical('es sync terminated abnormally')
else:
logging.info('es sync terminated normally')

View file

@ -23,6 +23,12 @@ HISTOGRAM_BUCKETS = (
)
def setup_logging():
logging.basicConfig(level=logging.INFO, format="%(asctime)s %(levelname)-4s %(name)s:%(lineno)d: %(message)s")
logging.getLogger('aiohttp').setLevel(logging.WARNING)
logging.getLogger('elasticsearch').setLevel(logging.WARNING)
class StagedClaimtrieItem(typing.NamedTuple):
"""
Represents a claim TXO, used internally by the block processor

View file

@ -1,2 +1,2 @@
from .search import SearchIndex
from .notifier_protocol import ElasticNotifierClientProtocol
from scribe.elasticsearch.search import SearchIndex
from scribe.elasticsearch.notifier_protocol import ElasticNotifierClientProtocol

View file

@ -0,0 +1,29 @@
import logging
import traceback
import argparse
from scribe.env import Env
from scribe.common import setup_logging
from scribe.elasticsearch.service import ElasticSyncService
def main():
setup_logging()
parser = argparse.ArgumentParser(
prog='scribe-elastic-sync'
)
Env.contribute_to_arg_parser(parser)
parser.add_argument('--reindex', type=bool, default=False)
args = parser.parse_args()
try:
server = ElasticSyncService(Env.from_arg_parser(args))
server.run(args.reindex)
except Exception:
traceback.print_exc()
logging.critical('es sync terminated abnormally')
else:
logging.info('es sync terminated normally')
if __name__ == "__main__":
main()

29
scribe/hub/__main__.py Normal file
View file

@ -0,0 +1,29 @@
import logging
import traceback
import argparse
from scribe.env import Env
from scribe.common import setup_logging
from scribe.hub.service import HubServerService
def main():
setup_logging()
parser = argparse.ArgumentParser(
prog='scribe-hub'
)
Env.contribute_to_arg_parser(parser)
args = parser.parse_args()
try:
server = HubServerService(Env.from_arg_parser(args))
server.run()
except Exception:
traceback.print_exc()
logging.critical('hub terminated abnormally')
else:
logging.info('hub terminated normally')
if __name__ == "__main__":
main()

View file

@ -23,9 +23,9 @@ setup(
zip_safe=False,
entry_points={
'console_scripts': [
'scribe=scribe.cli:run_writer_forever',
'scribe-hub=scribe.cli:run_server_forever',
'scribe-elastic-sync=scribe.cli:run_es_sync_forever',
'scribe=scribe.blockchain.__main__:main',
'scribe-hub=scribe.hub.__main__:main',
'scribe-elastic-sync=scribe.elasticsearch.__main__:main',
],
},
install_requires=[