def fs_render(fs_metadata, json=None, **kwargs): """render node based on json option passed renders to file, stdout or deletes json at root Parameters ---------- fs_metadata: dict Metadata json to be rendered json: str ('file', 'display', 'delete') Render to file, stdout or delete json """ metadata_file = metadata_locator(fs_metadata, **kwargs) if json == 'file': # create metadata_root directory if it doesn't exist metadata_dir = dirname(metadata_file) if not exists(metadata_dir): makedirs(metadata_dir) # write directory metadata to json with open(metadata_file, 'w') as f: js.dump(fs_metadata, f) # else if json flag set to delete, remove .dir.json of current directory elif json == 'delete' and exists(metadata_file): remove(metadata_file) # else dump json to stdout elif json == 'display': safe_print(js.dumps(fs_metadata) + '\n')
def fs_render(fs_metadata, json=None, **kwargs): """render node based on json option passed renders to file, stdout or deletes json at root Parameters ---------- fs_metadata: dict Metadata json to be rendered json: str ('file', 'display', 'delete') Render to file, stdout or delete json """ metadata_file = metadata_locator(fs_metadata, **kwargs) if json == 'file': # create metadata_root directory if it doesn't exist metadata_dir = dirname(metadata_file) if not exists(metadata_dir): makedirs(metadata_dir) # write directory metadata to json with open(metadata_file, 'w') as f: js.dump(fs_metadata, f) # else if json flag set to delete, remove .dir.json of current directory elif json == 'delete' and exists(metadata_file): remove(metadata_file) # else dump json to stdout elif json == 'display': safe_print(js.dumps(fs_metadata) + '\n')
def test_safe_print(): """Just to test that we are getting two attempts to print""" called = [0] def _print(s): assert_equal(s, "bua") called[0] += 1 if called[0] == 1: raise UnicodeEncodeError('crap', u"", 0, 1, 'whatever') with patch.object(builtins, 'print', _print): safe_print("bua") assert_equal(called[0], 2)