a ì)g$ã@s’dZddlmZmZmZeZddlZej rRddl m Z ddl m Z ddlmZmZddl mZmZddlmZdd lmZeƒZGd d „d ƒZdS) z8A facade for interfacing with multiple Galaxy instances.é)Úabsolute_importÚdivisionÚprint_functionN)ÚCollectionVersionMetadata)ÚConcreteArtifactsManager)Ú CandidateÚ Requirement)Ú GalaxyAPIÚ GalaxyError)Úto_text)ÚDisplayc@sVeZdZdZddd„Zedd„ƒZdd„Zd d „Zd d „Z d d„Z dd„Z dd„Z dS)ÚMultiGalaxyAPIProxyzMultiGalaxyAPIProxy._assert_that_offline_mode_is_not_requestedc csä|jr gSd}d}t|jtƒr&|jfn|j}|D]ž}z| |j|j¡}Wnltyp}z|}WYd}~q0d}~0t y´}z.t   dj |j |jt|ƒd�¡|}WYd}~q0d}~00d}|D]} || fVq¾q0|sà|durà|‚dS)zšHelper for get_collection_versions. Yield api, version pairs for all APIs, and reraise the last error if no valid API was found. FNúzSkipping Galaxy server {server!s}. Got an unexpected error when getting available versions of collection {fqcn!s}: {err!s}©ZserverÚfqcnÚerrT)rÚ isinstanceÚsrcr rÚget_collection_versionsÚ namespaceÚnamer Ú ExceptionÚdisplayÚwarningÚformatÚ api_serverrr ) rÚ requirementZ found_apiZ last_errorÚapi_lookup_orderÚapiZversionsÚapi_errÚ unknown_errÚversionrrrÚ_get_collection_versions.s6 ÿ ýúÿ  z,MultiGalaxyAPIProxy._get_collection_versionscCsL|jr|j |¡|jfhSt|jtƒr.|jfn|j}tdd„| |¡DƒƒS)z8Get a set of unique versions for FQCN on Galaxy servers.css|]\}}||fVqdSrr)Ú.0r*r-rrrÚ ksÿz>MultiGalaxyAPIProxy.get_collection_versions..) Úis_concrete_artifactrZget_direct_collection_versionrrr rÚsetr.)rr(r)rrrr Zs ÿýÿ ÿ ýÿþz+MultiGalaxyAPIProxy.get_collection_versionsc Csâ| ¡t|jtƒr|jfn|j}|D]²}z| |j|j|j¡}Wnlt yj}z|}WYd}~q&d}~0t y®}z.|}t   dj |j|jt|ƒd�¡WYd}~q&d}~00|j ||j|j|j|j|j¡|Sq&|‚dS)z2Retrieve collection metadata of a given candidate.Nrr)rrrr rÚget_collection_version_metadatar!r"Úverr r#r$r%r&r'rr rZsave_collection_sourceZ download_urlZartifact_sha256ÚtokenZsignatures_urlZ signatures)rÚcollection_candidater)r*Zversion_metadatar+Úlast_errr,rrrr3rsB ÿ ýýúÿ ú z3MultiGalaxyAPIProxy.get_collection_version_metadatacCs|jr|j |¡S| |¡jS)z6Retrieve collection dependencies of a given candidate.)r1rZ"get_direct_collection_dependenciesr3Z dependencies)rr6rrrÚget_collection_dependencies¤sÿüÿÿz/MultiGalaxyAPIProxy.get_collection_dependenciesc CsÐ| ¡|j}|j}|j}d}t|jtƒr2|jfn|j}|D]†}z| |||¡WSt y|}z|}WYd}~qs