예제 #1
0
def main():
    import loggery
    import kachery as ka

    # loggery.set_config('default_readwrite')
    loggery.set_config('local')
    container = 'default'
    # container = None
    force_run = False

    result = addem.execute(x=4,
                           y=5,
                           _container=container,
                           _force_run=force_run)
    print(result.retval)

    hash_url = ka.store_text('some sample text')
    num_chars = count_chars.execute(fname=hash_url,
                                    _container=container,
                                    _force_run=force_run)
    print(num_chars.retval)

    r = append_files.execute(path1=ka.store_text('test1:'),
                             path2=ka.store_text('test2'),
                             path_out=hither.File(),
                             _container=container,
                             _force_run=force_run)
    print(ka.load_text(r.outputs.path_out._path))
    num_chars = count_chars.execute(fname=r.outputs.path_out,
                                    _container=container,
                                    _force_run=force_run)
    print(num_chars.retval)
예제 #2
0
 async def sha1_handler(request):
     sha1 = str(request.rel_url).split('/')[2]
     uri = 'sha1://' + sha1
     txt = ka.load_text(uri)
     if txt is not None:
         return web.Response(text=txt)
     else:
         raise Exception(f'Not found: {uri}')
예제 #3
0
    def javascript_state_changed(self, prev_state, state):
        path = state.get('path', None)
        self._set_status('running', 'Loading markdown file {}'.format(path))
        txt = ka.load_text(path)
        if not txt:
            self._set_error('Unable to load text from file: {}'.format(path))
            return

        self._set_state(content=txt, status='finished', status_message='')
예제 #4
0
def load_text(uri: str,
              p2p: bool = True,
              from_node: Union[str, None] = None,
              from_channel: Union[str, None] = None):
    local_path = load_file(uri,
                           p2p=p2p,
                           from_node=from_node,
                           from_channel=from_channel)
    if local_path is None:
        return None
    return ka.load_text(uri)
예제 #5
0
def _deserialize_result(obj):
    import kachery as ka
    result = Result()

    result.runtime_info = obj['runtime_info']
    result.runtime_info['stdout'] = ka.load_text(result.runtime_info['stdout'])
    result.runtime_info['stderr'] = ka.load_text(result.runtime_info['stderr'])
    if result.runtime_info['stdout'] is None:
        return None
    if result.runtime_info['stderr'] is None:
        return None

    output_files = obj['output_files']
    for oname, path in output_files.items():
        path2 = ka.load_file(path)
        if path2 is None:
            return None
        setattr(result.outputs, oname, File(path2))
        result._output_names.append(oname)

    result.retval = obj['retval']
    result.hash_object = obj['hash_object']
    return result
예제 #6
0
def test_remote():
    ka.set_config(to='default_readwrite', fr='default_readwrite')

    for alg in ['sha1', 'md5']:
        ka.set_config(algorithm=alg)
        for pass0 in range(1, 3):
            if pass0 == 1:
                ka.set_config(from_remote_only=True, to_remote_only=True)
            elif pass0 == 2:
                ka.set_config(from_remote_only=False, to_remote_only=False)
            _test_store_text('abctest2')
            _test_store_object(dict(a=1, b=2, c=[1, 2, 3, 4]))
            _test_store_npy(np.ones((12, 14)))

    a = ka.load_text('sha1://906faceaf874dd64e81de0048f36f4bab0f1f171')
    print(a)
예제 #7
0
파일: Explore.py 프로젝트: rly/kachery
 def on_message(self, msg):
     ka.set_config(fr='default_readonly', to='')
     # process custom messages from JavaScript here
     # In .js file, use this.pythonInterface.sendMessage({...})
     if msg['name'] == 'loadText':
         try:
             text = ka.load_text(msg['path'])
         except:
             self._send_message(
                 dict(name='loadedText',
                      path=msg['path'],
                      text=None,
                      error=
                      'Problem loading. Perhaps this is not a text file.'))
             return
         self._send_message(
             dict(name='loadedText', path=msg['path'], text=text))
예제 #8
0
파일: Explore.py 프로젝트: rly/kachery
    def javascript_state_changed(self, prev_state, state):
        ka.set_config(fr='default_readonly', to='')

        self._set_status('running', 'Running Explore')

        self._set_state(dir_content=None, file_content=None)

        print('running', state)
        if state.get('path'):
            try:
                dir_content = ka.read_dir(state['path'])
                file_content = None
            except:
                dir_content = None
                file_content = ka.load_text(state['path'])
            self._set_state(dir_content=dir_content, file_content=file_content)

        self._set_status('finished', 'Finished Explore ' + state['path'])
def main():
    thisdir = os.path.dirname(os.path.realpath(__file__))
    studysets_obj_path = ka.load_text(thisdir + '/../../recordings/studysets')
    with ka.config(fr='default_readonly'):
        studysets_obj = ka.load_object(path=studysets_obj_path)
    # studysets_obj['StudySets']
    new_study_sets = []
    for ss in studysets_obj['StudySets']:
        if ss['name'] != 'PAIRED_ENGLISH':
            new_study_sets.append(ss)
    studyset_obj_path = thisdir + '/../../recordings/PAIRED_ENGLISH/PAIRED_ENGLISH.json'
    studyset_obj = ka.load_object(studyset_obj_path)
    assert studyset_obj is not None, f'Missing file: {studyset_obj_path}'
    new_study_sets.append(studyset_obj)
    studysets_obj['StudySets'] = new_study_sets
    with ka.config(fr='default_readwrite'):
        studysets_obj_path = ka.store_object(studysets_obj,
                                             basename='studysets.json')
    with open(thisdir + '/../../recordings/studysets', 'w') as f:
        f.write(studysets_obj_path)
예제 #10
0
 def get(self):
     sha1 = self.request.path.split('/')[-1]
     txt = ka.load_text(f'sha1://{sha1}')
     if txt is None:
         raise Exception('Unable to load file.')
     self.finish(txt)
예제 #11
0
def _test_store_text(val: str):
    x = ka.store_text(val)
    assert x
    val2 = ka.load_text(x)
    assert val == val2