diff --git a/protcur/protcur/cli.py b/protcur/protcur/cli.py index 94b5cd6..90c3be3 100755 --- a/protcur/protcur/cli.py +++ b/protcur/protcur/cli.py @@ -1,7 +1,8 @@ #!/usr/bin/env python3.7 """ protcur cli Usage: - protcur export [options] + protcur export [options] + protcur convert [options] Options: -d --debug @@ -21,6 +22,12 @@ class Options(clif.Options): """ wheeeeee """ + @property + def path(self): + p = self._args[''] + op = self._args[''] + return Path(p if p else op) + @property def __output_type(self): return [self._args['--output-type']] @@ -51,13 +58,21 @@ def _output(self): 'need': 'parentneed',}[type_] return getattr(protc, output_name)() - def export(self): - from pyontutils.config import auth - from hyputils.hypothesis import group_to_memfile, Memoizer + def _from_cache(self, cache_file, group_id=None): + from hyputils.hypothesis import Memoizer, AnnoReader + + if group_id is None: # FIXME bad way to detect convert vs export + import json + with open(cache_file, 'rt') as f: + j = json.load(f) + + group_id = j[0][0]['group'] + j = None # should trigger gc + + get_annos = AnnoReader(memoization_file=cache_file, group=group_id) + else: + get_annos = Memoizer(memoization_file=cache_file, group=group_id) - group_id = auth.dynamic_config.secrets('hypothesis', 'group', self.options.group_name) - cache_file = group_to_memfile(group_id + 'protcur-cli') # note, caching is not memoization (duh) - get_annos = Memoizer(memoization_file=cache_file, group=group_id) annos = get_annos() [protc(a, annos) for a in annos] @@ -65,6 +80,18 @@ def export(self): with open(path, 'wt') as f: f.write(self._output()) + def export(self): + from pyontutils.config import auth + from hyputils.hypothesis import group_to_memfile + + group_id = auth.dynamic_config.secrets('hypothesis', 'group', self.options.group_name) + cache_file = group_to_memfile(group_id + 'protcur-cli') # note, caching is not memoization (duh) + self._from_cache(cache_file, group_id) + + def convert(self): + cache_file = self.options.path_input + self._from_cache(cache_file) + def main(): from docopt import docopt, parse_defaults