cic-cli/cic/cmd/export.py

63 lines
1.7 KiB
Python

# standard imports
import logging
import importlib
# local imports
from cic import Proof
from cic.meta import Meta
from cic.attachment import Attachment
from cic.network import Network
from cic.token import Token
logg = logging.getLogger(__name__)
def process_args(argparser):
argparser.add_argument('-d', '--directory', type=str, dest='directory', default='.', help='directory')
argparser.add_argument('-y', '--signer', type=str, dest='signer', help='target-specific signer to use for export')
argparser.add_argument('target', type=str, help='target network type')
def validate_args(args):
pass
def init_writers_from_config(config):
w = {
'meta': None,
'attachment': None,
'proof': None,
}
for v in w.keys():
k = 'CIC_CORE_{}_WRITER'.format(v.upper())
(d, c) = config.get(k).rsplit('.', maxsplit=1)
m = importlib.import_module(d)
o = getattr(m, c)
w[v] = o
return w
def execute(config, eargs):
modname = 'cic.ext.{}'.format(eargs.target)
cmd_mod = importlib.import_module(modname)
writers = init_writers_from_config(config)
ct = Token(path=eargs.directory)
cm = Meta(path=eargs.directory, writer=writers['meta'])
ca = Attachment(path=eargs.directory, writer=writers['attachment'])
cp = Proof(path=eargs.directory, attachments=ca, writer=writers['proof'])
cn = Network(path=eargs.directory)
ct.load()
cp.load()
cm.load()
ca.load()
cn.load()
ref = cn.resource(eargs.target)
chain_spec = cn.chain_spec(eargs.target)
logg.debug('found reference {} for target {}'.format(ref, eargs.target))
getattr(cmd_mod, 'new')(chain_spec, ref, cp, signer_hint=eargs.signer)