Skip to content

Commit

Permalink
protcur cli add convert command to transform json cache directly
Browse files Browse the repository at this point in the history
  • Loading branch information
tgbugs committed Oct 2, 2020
1 parent 4fb3e25 commit ed357e2
Showing 1 changed file with 34 additions and 7 deletions.
41 changes: 34 additions & 7 deletions protcur/protcur/cli.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/env python3.7
""" protcur cli
Usage:
protcur export [options] <group-name> <path>
protcur export [options] <group-name> <path>
protcur convert [options] <path-input> <path-output>
Options:
-d --debug
Expand All @@ -21,6 +22,12 @@
class Options(clif.Options):
""" wheeeeee """

@property
def path(self):
p = self._args['<path>']
op = self._args['<path-output>']
return Path(p if p else op)

@property
def __output_type(self):
return [self._args['--output-type']]
Expand Down Expand Up @@ -51,20 +58,40 @@ 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]

path = Path(self.options.path)
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
Expand Down

0 comments on commit ed357e2

Please sign in to comment.