Simplified bool args

pull/45/head
kompotkot 2021-08-03 12:17:08 +03:00
rodzic 45455a6ac2
commit 68d5c3755a
1 zmienionych plików z 26 dodań i 17 usunięć

Wyświetl plik

@ -2,7 +2,6 @@
Moonstream crawlers CLI.
"""
import argparse
from distutils.util import strtobool
from enum import Enum
import json
import sys
@ -84,7 +83,7 @@ def ethcrawler_blocks_sync_handler(args: argparse.Namespace) -> None:
starting_block: int = args.start
while True:
bottom_block_number, top_block_number = get_latest_blocks(
bool(strtobool(args.transactions))
bool(args.transactions)
)
bottom_block_number = max(bottom_block_number + 1, starting_block)
if bottom_block_number >= top_block_number:
@ -102,7 +101,7 @@ def ethcrawler_blocks_sync_handler(args: argparse.Namespace) -> None:
# TODO(kompotkot): Set num_processes argument based on number of blocks to synchronize.
crawl_blocks_executor(
block_numbers_list=blocks_numbers_list,
with_transactions=bool(strtobool(args.transactions)),
with_transactions=bool(args.transactions),
num_processes=args.jobs,
)
print(f"Synchronized blocks from {bottom_block_number} to {top_block_number}")
@ -118,7 +117,7 @@ def ethcrawler_blocks_add_handler(args: argparse.Namespace) -> None:
print(f"Adding blocks {blocks_numbers_list[-1]}-{blocks_numbers_list[0]}")
crawl_blocks_executor(
block_numbers_list=blocks_numbers_list,
with_transactions=bool(strtobool(args.transactions)),
with_transactions=bool(args.transactions),
)
print(f"Required {time.time() - startTime} with {MOONSTREAM_CRAWL_WORKERS} workers")
@ -142,18 +141,18 @@ def ethcrawler_blocks_missing_handler(args: argparse.Namespace) -> None:
time.sleep(5)
if (len(missing_blocks_numbers_total)) > 0:
if bool(strtobool(args.lazy)):
if bool(args.lazy):
print("Executed lazy block crawler")
crawl_blocks(
missing_blocks_numbers_total,
with_transactions=bool(strtobool(args.transactions)),
verbose=True,
with_transactions=bool(args.transactions),
verbose=bool(args.verbose),
)
else:
crawl_blocks_executor(
missing_blocks_numbers_total,
with_transactions=bool(strtobool(args.transactions)),
verbose=True,
with_transactions=bool(args.transactions),
verbose=bool(args.verbose),
)
print(
f"Required {time.time() - startTime} with {MOONSTREAM_CRAWL_WORKERS} workers "
@ -209,8 +208,9 @@ def main() -> None:
parser_ethcrawler_blocks_sync.add_argument(
"-t",
"--transactions",
choices=["True", "False"],
default="True",
action="store_const",
const=1,
default=1,
help="Add or not block transactions",
)
parser_ethcrawler_blocks_sync.add_argument(
@ -250,8 +250,9 @@ def main() -> None:
parser_ethcrawler_blocks_add.add_argument(
"-t",
"--transactions",
choices=["True", "False"],
default="True",
action="store_const",
const=1,
default=1,
help="Add or not block transactions",
)
parser_ethcrawler_blocks_add.set_defaults(func=ethcrawler_blocks_add_handler)
@ -268,17 +269,25 @@ def main() -> None:
parser_ethcrawler_blocks_missing.add_argument(
"-t",
"--transactions",
choices=["True", "False"],
default="True",
action="store_const",
const=1,
default=1,
help="Add or not block transactions",
)
parser_ethcrawler_blocks_missing.add_argument(
"-l",
"--lazy",
choices=["True", "False"],
default="False",
action="store_const",
const=1,
help="Lazy block adding one by one",
)
parser_ethcrawler_blocks_missing.add_argument(
"-v",
"--verbose",
action="store_const",
const=1,
help="Print additional information",
)
parser_ethcrawler_blocks_missing.set_defaults(
func=ethcrawler_blocks_missing_handler
)