From 626b1c9a03a5eebd6a37819abe0803a966641313 Mon Sep 17 00:00:00 2001 From: nolash Date: Fri, 23 Apr 2021 22:51:51 +0200 Subject: [PATCH] Add omitted files --- apps/cic-eth/cic_eth/admin/token.py | 19 ++++++++ apps/cic-eth/cic_eth/runnable/info.py | 65 +++++++++++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 apps/cic-eth/cic_eth/admin/token.py create mode 100644 apps/cic-eth/cic_eth/runnable/info.py diff --git a/apps/cic-eth/cic_eth/admin/token.py b/apps/cic-eth/cic_eth/admin/token.py new file mode 100644 index 00000000..ffb17568 --- /dev/null +++ b/apps/cic-eth/cic_eth/admin/token.py @@ -0,0 +1,19 @@ +# standard imports +import logging + +# external imports +import celery + +# local imports +from cic_eth.task import BaseTask + +celery_app = celery.current_app +logg = logging.getLogger() + + +@celery_app.task(bind=True, base=BaseTask) +def default_token(self): + return { + 'symbol': self.default_token_symbol, + 'address': self.default_token_address, + } diff --git a/apps/cic-eth/cic_eth/runnable/info.py b/apps/cic-eth/cic_eth/runnable/info.py new file mode 100644 index 00000000..59bfb759 --- /dev/null +++ b/apps/cic-eth/cic_eth/runnable/info.py @@ -0,0 +1,65 @@ +#!python3 + +# SPDX-License-Identifier: GPL-3.0-or-later + +# standard imports +import logging +import argparse +import os + +# external imports +import confini +import celery + +# local imports +from cic_eth.api import Api + +logging.basicConfig(level=logging.WARNING) +logg = logging.getLogger() + +default_format = 'terminal' +default_config_dir = os.environ.get('CONFINI_DIR', '/usr/local/etc/cic') + + +argparser = argparse.ArgumentParser() +argparser.add_argument('-i', '--chain-spec', dest='i', type=str, help='chain spec') +argparser.add_argument('-c', type=str, default=default_config_dir, help='config root to use') +argparser.add_argument('-q', type=str, default='cic-eth', help='celery queue to submit transaction tasks to') +argparser.add_argument('--env-prefix', default=os.environ.get('CONFINI_ENV_PREFIX'), dest='env_prefix', type=str, help='environment prefix for variables to overwrite configuration') +argparser.add_argument('-v', action='store_true', help='Be verbose') +argparser.add_argument('-vv', help='be more verbose', action='store_true') +args = argparser.parse_args() + +if args.v == True: + logging.getLogger().setLevel(logging.INFO) +elif args.vv == True: + logging.getLogger().setLevel(logging.DEBUG) + +config_dir = os.path.join(args.c) +os.makedirs(config_dir, 0o777, True) +config = confini.Config(config_dir, args.env_prefix) +config.process() +args_override = { + 'CIC_CHAIN_SPEC': getattr(args, 'i'), + } +config.dict_override(args_override, 'cli args') +config.censor('PASSWORD', 'DATABASE') +config.censor('PASSWORD', 'SSL') +logg.debug('config loaded from {}:\n{}'.format(config_dir, config)) + + +celery_app = celery.Celery(broker=config.get('CELERY_BROKER_URL'), backend=config.get('CELERY_RESULT_URL')) + +queue = args.q + +api = Api(config.get('CIC_CHAIN_SPEC'), queue=queue) + +def main(): + t = api.default_token() + token_info = t.get() + print('Default token symbol: {}'.format(token_info['symbol'])) + print('Default token address: {}'.format(token_info['address'])) + + +if __name__ == '__main__': + main()