<s> """<STR_LIT>""" <EOL> __docformat__ = '<STR_LIT>' <EOL> from os import curdir <EOL> from os . path import exists , join as opj <EOL> from . base import Interface <EOL> from . . support . param import Parameter <EOL> from . . support . constraints import EnsureStr , EnsureChoice <EOL> from . . support . collectionrepo import CollectionRepo <EOL> from datalad . support . collection_backends import CollectionRepoBackend <EOL> from . . support . collection import MetaCollection , Collection <EOL> from . . support . metadatahandler import CustomImporter , URIRef , Literal , DLNS , EMP , RDF , PAV , PROV , FOAF , DCTERMS <EOL> from . . cmdline . helpers import get_repo_instance <EOL> from . . log import lgr <EOL> from datalad . cmdline . helpers import get_datalad_master <EOL> from six . moves . urllib . parse import urlparse <EOL> _OUTPUTS = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> class SearchCollection ( Interface ) : <EOL> """<STR_LIT>""" <EOL> _params_ = dict ( <EOL> output = Parameter ( <EOL> choices = _OUTPUTS , <EOL> doc = """<STR_LIT>""" , <EOL> constraints = EnsureChoice ( * _OUTPUTS ) <EOL> ) , <EOL> search = Parameter ( <EOL> args = ( '<STR_LIT>' , ) , <EOL> doc = "<STR_LIT>" , <EOL> constraints = EnsureStr ( ) ) <EOL> ) <EOL> def __call__ ( self , search , output = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> local_master = get_datalad_master ( ) <EOL> metacollection = MetaCollection ( <EOL> [ CollectionRepoBackend ( local_master , remote + "<STR_LIT>" ) <EOL> for remote in local_master . git_get_remotes ( ) ] ) <EOL> for collection in metacollection : <EOL> metacollection [ collection ] . update_metadata ( ) <EOL> metacollection . conjunctive_graph . bind ( '<STR_LIT>' , DLNS ) <EOL> query_string = """<STR_LIT>""" % search <EOL> results = metacollection . query ( query_string , update = False ) <EOL> rows = [ row . asdict ( ) for row in results ] <EOL> collections = list ( ) <EOL> locations = list ( ) <EOL> for row in rows : <EOL> collections . append ( str ( row [ '<STR_LIT:g>' ] ) ) <EOL> parsed_uri = urlparse ( row [ '<STR_LIT:r>' ] ) <EOL> if parsed_uri . scheme == '<STR_LIT:file>' : <EOL> locations . append ( parsed_uri . path ) <EOL> else : <EOL> locations . append ( str ( row [ '<STR_LIT:r>' ] ) ) <EOL> printed_collections = set ( ) <EOL> if collections : <EOL> if not self . cmdline : <EOL> return [ CollectionRepoBackend ( local_master , col + "<STR_LIT>" ) <EOL> for col in collections ] <EOL> else : <EOL> for c , l in zip ( collections , locations ) : <EOL> if output in { '<STR_LIT>' , '<STR_LIT>' } and c in printed_collections : <EOL> continue <EOL> printed_collections . add ( c ) <EOL> if output == '<STR_LIT>' : <EOL> out = c <EOL> elif output == '<STR_LIT>' : <EOL> out = l <EOL> elif output == '<STR_LIT>' : <EOL> raise NotImplementedError ( ) <EOL> print ( out ) <EOL> else : <EOL> return [ ] </s>
