move module cli entrypoints to __main__.py files
This commit is contained in:
parent
0fd993d180
commit
5731016ca5
8 changed files with 97 additions and 70 deletions
scribe
setup.py
|
@ -1 +1 @@
|
||||||
from .network import LBCTestNet, LBCRegTest, LBCMainNet
|
from scribe.blockchain.network import LBCTestNet, LBCRegTest, LBCMainNet
|
||||||
|
|
27
scribe/blockchain/__main__.py
Normal file
27
scribe/blockchain/__main__.py
Normal 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()
|
|
@ -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')
|
|
|
@ -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):
|
class StagedClaimtrieItem(typing.NamedTuple):
|
||||||
"""
|
"""
|
||||||
Represents a claim TXO, used internally by the block processor
|
Represents a claim TXO, used internally by the block processor
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
from .search import SearchIndex
|
from scribe.elasticsearch.search import SearchIndex
|
||||||
from .notifier_protocol import ElasticNotifierClientProtocol
|
from scribe.elasticsearch.notifier_protocol import ElasticNotifierClientProtocol
|
29
scribe/elasticsearch/__main__.py
Normal file
29
scribe/elasticsearch/__main__.py
Normal 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
29
scribe/hub/__main__.py
Normal 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()
|
6
setup.py
6
setup.py
|
@ -23,9 +23,9 @@ setup(
|
||||||
zip_safe=False,
|
zip_safe=False,
|
||||||
entry_points={
|
entry_points={
|
||||||
'console_scripts': [
|
'console_scripts': [
|
||||||
'scribe=scribe.cli:run_writer_forever',
|
'scribe=scribe.blockchain.__main__:main',
|
||||||
'scribe-hub=scribe.cli:run_server_forever',
|
'scribe-hub=scribe.hub.__main__:main',
|
||||||
'scribe-elastic-sync=scribe.cli:run_es_sync_forever',
|
'scribe-elastic-sync=scribe.elasticsearch.__main__:main',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
install_requires=[
|
install_requires=[
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue