Add export, temporary eth plugin inline

This commit is contained in:
nolash 2021-10-09 21:04:11 +02:00
parent 546a4d912a
commit 388c676d11
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
10 changed files with 76 additions and 3 deletions

View File

@ -1 +1 @@
include requirements.txt include requirements.txt cic/data/* cic/schema/*

View File

@ -46,6 +46,12 @@ class Attachment(Data):
os.makedirs(self.attachment_path) os.makedirs(self.attachment_path)
def get(self):
def maphex(v):
return v.hex()
return list(map(maphex, self.digests))
def __str__(self): def __str__(self):
s = '' s = ''
for i in range(len(self.contents)): for i in range(len(self.contents)):

40
cic/cmd/export.py Normal file
View File

@ -0,0 +1,40 @@
# 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
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 execute(config, eargs):
modname = 'cic.ext.{}'.format(eargs.target)
cmd_mod = importlib.import_module(modname)
cp = Proof(path=eargs.directory)
cm = Meta(path=eargs.directory)
ca = Attachment(path=eargs.directory)
cn = Network(eargs.directory)
cp.load()
cm.load()
ca.load()
cn.load()
ref = cn.reference(eargs.target)
logg.debug('found reference {} for target {}'.format(ref, eargs.target))
getattr(cmd_mod, 'new')(ref, ca.get())

View File

@ -7,7 +7,6 @@ from cic import Proof
from cic.meta import Meta from cic.meta import Meta
from cic.attachment import Attachment from cic.attachment import Attachment
from cic.network import Network from cic.network import Network
logg = logging.getLogger(__name__) logg = logging.getLogger(__name__)

View File

@ -7,7 +7,7 @@ from cic.network import Network
def process_args(argparser): def process_args(argparser):
argparser.add_argument('-f', '--file', type=str, help='add file') argparser.add_argument('-f', '--file', type=str, help='add file')
argparser.add_argument('-d', '--directory', type=str, dest='directory', default='.', help='directory') argparser.add_argument('-d', '--directory', type=str, dest='directory', default='.', help='cic data directory')
def validate_args(args): def validate_args(args):

16
cic/ext/eth/__init__.py Normal file
View File

@ -0,0 +1,16 @@
# standard imports
import logging
logg = logging.getLogger(__name__)
class CICEth:
def __init__(self, reference, proofs):
self.reference = reference
self.proofs = proofs
logg.debug('eth strup with reference {} proofs {}'.format(reference, proofs))
def new(reference, proofs):
return CICEth(reference, proofs)

View File

@ -35,6 +35,13 @@ class Network(Data):
f.close() f.close()
def reference(self, k):
v = self.references.get(k)
if v == None:
raise AttributeError('no defined reference for {}'.format(k))
return v
def __str__(self): def __str__(self):
s = '' s = ''
for k in self.references.keys(): for k in self.references.keys():

View File

@ -47,6 +47,7 @@ class Proof(Data):
f.close() f.close()
def __str__(self): def __str__(self):
return """description: {} return """description: {}
""".format(self.description) """.format(self.description)

View File

@ -8,6 +8,7 @@ import importlib
# external imports # external imports
import cic.cmd.init as cmd_init import cic.cmd.init as cmd_init
import cic.cmd.show as cmd_show import cic.cmd.show as cmd_show
import cic.cmd.export as cmd_export
logging.basicConfig(level=logging.WARNING) logging.basicConfig(level=logging.WARNING)
logg = logging.getLogger() logg = logging.getLogger()
@ -26,6 +27,8 @@ sub_init = sub.add_parser('init', help='initialize new cic data directory')
cmd_init.process_args(sub_init) cmd_init.process_args(sub_init)
sub_show = sub.add_parser('show', help='display summary of current state of cic data directory') sub_show = sub.add_parser('show', help='display summary of current state of cic data directory')
cmd_show.process_args(sub_show) cmd_show.process_args(sub_show)
sub_export = sub.add_parser('export', help='export cic data directory state to a specified target')
cmd_export.process_args(sub_export)
args = argparser.parse_args(sys.argv[1:]) args = argparser.parse_args(sys.argv[1:])

View File

@ -28,3 +28,4 @@ include_package_data = True
packages = packages =
cic cic
cic.runnable cic.runnable
cic.ext