From 388c676d116348839af5a601866efa9eb5ce1d32 Mon Sep 17 00:00:00 2001 From: nolash Date: Sat, 9 Oct 2021 21:04:11 +0200 Subject: [PATCH] Add export, temporary eth plugin inline --- MANIFEST.in | 2 +- cic/attachment.py | 6 ++++++ cic/cmd/export.py | 40 ++++++++++++++++++++++++++++++++++++++++ cic/cmd/init.py | 1 - cic/cmd/show.py | 2 +- cic/ext/eth/__init__.py | 16 ++++++++++++++++ cic/network.py | 7 +++++++ cic/proof.py | 1 + cic/runnable/cic_cmd.py | 3 +++ setup.cfg | 1 + 10 files changed, 76 insertions(+), 3 deletions(-) create mode 100644 cic/cmd/export.py create mode 100644 cic/ext/eth/__init__.py diff --git a/MANIFEST.in b/MANIFEST.in index f9bd145..02f1588 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1 +1 @@ -include requirements.txt +include requirements.txt cic/data/* cic/schema/* diff --git a/cic/attachment.py b/cic/attachment.py index 01b32e8..2dfeb54 100644 --- a/cic/attachment.py +++ b/cic/attachment.py @@ -46,6 +46,12 @@ class Attachment(Data): os.makedirs(self.attachment_path) + def get(self): + def maphex(v): + return v.hex() + return list(map(maphex, self.digests)) + + def __str__(self): s = '' for i in range(len(self.contents)): diff --git a/cic/cmd/export.py b/cic/cmd/export.py new file mode 100644 index 0000000..be7ba2c --- /dev/null +++ b/cic/cmd/export.py @@ -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()) diff --git a/cic/cmd/init.py b/cic/cmd/init.py index 9302e63..3a7a63d 100644 --- a/cic/cmd/init.py +++ b/cic/cmd/init.py @@ -7,7 +7,6 @@ from cic import Proof from cic.meta import Meta from cic.attachment import Attachment from cic.network import Network - logg = logging.getLogger(__name__) diff --git a/cic/cmd/show.py b/cic/cmd/show.py index d19f327..50117f8 100644 --- a/cic/cmd/show.py +++ b/cic/cmd/show.py @@ -7,7 +7,7 @@ from cic.network import Network def process_args(argparser): 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): diff --git a/cic/ext/eth/__init__.py b/cic/ext/eth/__init__.py new file mode 100644 index 0000000..3c56d02 --- /dev/null +++ b/cic/ext/eth/__init__.py @@ -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) diff --git a/cic/network.py b/cic/network.py index 2be7794..19675ea 100644 --- a/cic/network.py +++ b/cic/network.py @@ -35,6 +35,13 @@ class Network(Data): 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): s = '' for k in self.references.keys(): diff --git a/cic/proof.py b/cic/proof.py index 2650af8..d9229a6 100644 --- a/cic/proof.py +++ b/cic/proof.py @@ -47,6 +47,7 @@ class Proof(Data): f.close() + def __str__(self): return """description: {} """.format(self.description) diff --git a/cic/runnable/cic_cmd.py b/cic/runnable/cic_cmd.py index b7697ce..4a9a1d0 100644 --- a/cic/runnable/cic_cmd.py +++ b/cic/runnable/cic_cmd.py @@ -8,6 +8,7 @@ import importlib # external imports import cic.cmd.init as cmd_init import cic.cmd.show as cmd_show +import cic.cmd.export as cmd_export logging.basicConfig(level=logging.WARNING) 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) sub_show = sub.add_parser('show', help='display summary of current state of cic data directory') 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:]) diff --git a/setup.cfg b/setup.cfg index 74cf6cc..0db7d79 100644 --- a/setup.cfg +++ b/setup.cfg @@ -28,3 +28,4 @@ include_package_data = True packages = cic cic.runnable + cic.ext