Initial commit
This commit is contained in:
commit
c55af204cc
1
clicada/cli/__init__.py
Normal file
1
clicada/cli/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
from clicada.cli.arg import CmdCtrl
|
64
clicada/cli/arg.py
Normal file
64
clicada/cli/arg.py
Normal file
@ -0,0 +1,64 @@
|
||||
# standard imports
|
||||
import os
|
||||
import argparse
|
||||
import logging
|
||||
import importlib
|
||||
|
||||
# external imports
|
||||
import confini
|
||||
|
||||
# local imports
|
||||
import clicada.cli.user as cmd_user
|
||||
|
||||
script_dir = os.path.dirname(os.path.realpath(__file__))
|
||||
data_dir = os.path.join(script_dir, '..', 'data')
|
||||
base_config_dir = os.path.join(data_dir, 'config')
|
||||
|
||||
|
||||
class CmdCtrl:
|
||||
|
||||
__cmd_alias = {
|
||||
'u': 'user',
|
||||
}
|
||||
|
||||
def __init__(self, argv=None, description=None, logger=None, *args, **kwargs):
|
||||
self.argparser = argparse.ArgumentParser(description=description, *args, **kwargs)
|
||||
|
||||
self.argparser.add_argument('-c', type=str, help='Configuration override directory path')
|
||||
self.argparser.add_argument('-v', action='store_true', help='Be verbose')
|
||||
self.argparser.add_argument('-vv', action='store_true', help='Be very verbose')
|
||||
|
||||
sub = self.argparser.add_subparsers()
|
||||
sub.dest = 'command'
|
||||
sub_user = sub.add_parser('user', aliases=['u'], help='retrieve transactions for a user')
|
||||
cmd_user.process_args(sub_user)
|
||||
|
||||
self.cmd_args = self.argparser.parse_args(argv)
|
||||
|
||||
if logger == None:
|
||||
logger = logging.getLogger()
|
||||
if self.cmd_args.vv:
|
||||
logger.setLevel(logging.DEBUG)
|
||||
elif self.cmd_args.v:
|
||||
logger.setLevel(logging.INFO)
|
||||
|
||||
self.cmd_string = self.cmd_args.command
|
||||
cmd_string_translate = self.__cmd_alias.get(self.cmd_string)
|
||||
if cmd_string_translate != None:
|
||||
self.cmd_string = cmd_string_translate
|
||||
|
||||
if self.cmd_string == None:
|
||||
raise ValueError('Subcommand missing')
|
||||
|
||||
modname = 'clicada.cli.{}'.format(self.cmd_string)
|
||||
logger.debug('using module {}'.format(modname))
|
||||
self.cmd_mod = importlib.import_module(modname)
|
||||
|
||||
if self.cmd_args.c:
|
||||
self.config = confini.Config(base_config_dir, override_dirs=self.cmd_args.c)
|
||||
else:
|
||||
self.config = confini.Config(base_config_dir)
|
||||
|
||||
self.config.process()
|
||||
|
||||
logger.debug('loaded config:\n{}'.format(self.config))
|
15
clicada/cli/user.py
Normal file
15
clicada/cli/user.py
Normal file
@ -0,0 +1,15 @@
|
||||
def process_args(argparser):
|
||||
argparser.add_argument('-m', '--method', type=str, help='lookup method')
|
||||
argparser.add_argument('identifier', type=str, help='user identifier')
|
||||
|
||||
|
||||
def validate_args(args):
|
||||
pass
|
||||
|
||||
|
||||
def apply_args(config, args):
|
||||
pass
|
||||
|
||||
|
||||
def execute(config, args):
|
||||
pass
|
2
clicada/data/config/config.ini
Normal file
2
clicada/data/config/config.ini
Normal file
@ -0,0 +1,2 @@
|
||||
[meta]
|
||||
lookup_method = phone
|
12
clicada/runnable/view.py
Normal file
12
clicada/runnable/view.py
Normal file
@ -0,0 +1,12 @@
|
||||
# standard imports
|
||||
import sys
|
||||
import logging
|
||||
|
||||
# local imports
|
||||
from clicada.tx import TxGetter
|
||||
from clicada.cli import CmdCtrl
|
||||
|
||||
logging.basicConfig(level=logging.WARNING)
|
||||
logg = logging.getLogger()
|
||||
|
||||
ctrl = CmdCtrl(argv=sys.argv[1:], logger=logg)
|
17
clicada/tx.py
Normal file
17
clicada/tx.py
Normal file
@ -0,0 +1,17 @@
|
||||
# standard imports
|
||||
import urllib.request
|
||||
import urllib.parse
|
||||
|
||||
|
||||
class TxGetter:
|
||||
|
||||
|
||||
def __init__(self, cache_url, limit=0):
|
||||
self.cache_url = cache_url
|
||||
self.limit = limit
|
||||
|
||||
if limit == 0:
|
||||
url = urllib.parse.urljoin(self.cache_url, 'defaultlimit')
|
||||
r = urllib.request.urlopen(url)
|
||||
self.limit = r.read()
|
||||
logg.debug('set limit {} from {}'.format(self.limit, self.cache_url))
|
2
requirements.txt
Normal file
2
requirements.txt
Normal file
@ -0,0 +1,2 @@
|
||||
usumbufu~=0.3.2
|
||||
confini~=0.5.1
|
Loading…
Reference in New Issue
Block a user