def translate(name, input_namespace, output_namespace, session=None): ''' name = translate(name, input_namespace, output_namespace, session={backend.create_session()}) Translate from one namespace to another. Parameters ---------- name : str input name input_namespace : str namespace to translate from (must be a known namespace) output_namespace : str namespace to translate to (must be a known namespace) session : SQLAlchemy sesion object SQLAlchemy session to use (default: call backend.create_session()) Returns ------- name : str or None result of translation or None if not found. ''' if session is None: session = waldo.backend.create_session() verify_namespace(input_namespace) verify_namespace(output_namespace) trans = session.query(Translation).filter( and_(Translation.input_namespace == input_namespace, Translation.input_name == name, Translation.output_namespace == output_namespace)).first() if trans is None: if input_namespace == output_namespace: return name return None return trans.output_name
def list_all(namespace, session=None): ''' all_ids = list_all(namespace, session={waldo.backend.create_session()}) Parameters ---------- namespace : str input namespacce session : SQLAlchemy sesion object SQLAlchemy session to use (default: call backend.create_session()) Returns ------- alls_ids : list of str ''' if session is None: session = waldo.backend.create_session() verify_namespace(namespace) results = session.query(Translation.input_name).filter(Translation.input_namespace == namespace).all() return [r[0] for r in results if r[0]]