def installed_repository_iterator(galaxy_context, namespace_match_filter=None, repository_match_filter=None): '''For each repository in galaxy_context.content_path, yield matching repositories''' namespace_match_filter = namespace_match_filter or matchers.MatchAll() repository_match_filter = repository_match_filter or matchers.MatchAll() installed_namespace_db = installed_namespaces_db.InstalledNamespaceDatabase( galaxy_context) # TODO: iterate/filter per namespace, then per repository, then per collection/role/etc for namespace in installed_namespace_db.select( namespace_match_filter=namespace_match_filter): log.debug('Looking for repos in namespace "%s"', namespace.namespace) # TODO: filter potential repository_paths based on repository_match_filer before we # try to listdir() instead of after repository_paths = get_repository_paths(namespace.path) for repository_path in repository_paths: # TODO: if we need to distinquish repo from collection or role, we could do it here repository_ = repository.load_from_dir( galaxy_context.content_path, namespace=namespace.namespace, name=repository_path, installed=True) # log.debug('candidate installed repo (pre filter): %s', repository_) if repository_match_filter(repository_): log.debug('Found repository "%s" in namespace "%s"', repository_path, namespace.namespace) yield repository_
def installed_content_item_iterator(galaxy_context, namespace_match_filter=None, repository_spec_match_filter=None, content_item_match_filter=None, content_item_type=None): # match_all works for all types namespace_match_filter = namespace_match_filter or matchers.MatchAll() repository_spec_match_filter = repository_spec_match_filter or matchers.MatchAll( ) content_item_match_filter = content_item_match_filter or matchers.MatchAll( ) content_item_type = content_item_type or 'roles' installed_repo_db = installed_repository_db.InstalledRepositoryDatabase( galaxy_context) # for namespace_full_path in namespace_paths_iterator: for installed_repository in installed_repo_db.select( namespace_match_filter=namespace_match_filter, repository_spec_match_filter=repository_spec_match_filter): log.debug('Found repository "%s" at %s', installed_repository.repository_spec.label, installed_repository.path) installed_repository_full_path = installed_repository.path if not repository_spec_match_filter(installed_repository): log.debug('The repository_match_filter %s failed to match for %s', repository_spec_match_filter, installed_repository) continue all_content_iterator = all_content_item_types_iterator( installed_repository) log.debug('Looking for %s in repository at %s', content_item_type, installed_repository_full_path) for installed_content_item in all_content_iterator: log.debug('installed_content_item: %s', installed_content_item) if not content_item_match_filter(installed_content_item): log.debug('%s was not matched by content_match_filter: %s', installed_content_item, content_item_match_filter) continue # this is sort of the 'join' of installed_repository and installed_content content_info = { 'path': installed_content_item.path, 'content_data': installed_content_item, 'installed_repository': installed_repository, 'version': installed_content_item.version, } yield content_info
def select(self, repository_match_filter=None, content_match_filter=None): # ie, default to select * more or less repository_match_filter = repository_match_filter or matchers.MatchAll() content_match_filter = content_match_filter or matchers.MatchAll() roles_content_iterator = installed_content_iterator(self.installed_context, content_type='roles', repository_match_filter=repository_match_filter, content_match_filter=content_match_filter) for matched_content in roles_content_iterator: yield matched_content
def select(self, namespace_match_filter=None, repository_match_filter=None): # ie, default to select * more or less repository_match_filter = repository_match_filter or matchers.MatchAll( ) namespace_match_filter = namespace_match_filter or matchers.MatchAll() installed_repositories = installed_repository_iterator( self.installed_context, namespace_match_filter=namespace_match_filter, repository_match_filter=repository_match_filter) for matched_repository in installed_repositories: yield matched_repository
def _list(galaxy_context, repository_match_filter=None, display_callback=None): repository_match_filter = repository_match_filter or matchers.MatchAll() # We search for installed repos to list, and then display all the content in those installed repos icdb = installed_content_db.InstalledContentDatabase(galaxy_context) repo_list = [] for content_info in icdb.select( repository_match_filter=repository_match_filter): content_dict = content_info.copy() repo = content_dict.pop('installed_repository') # revisit this output format once we get some feedback content_dict.update({ 'type': content_dict['content_data'].content_type, 'name': content_dict['content_data'].name, # 'installed_repo_namespace': repo.namespace, # 'installed_repo_name': repo.name, # 'installed_repo_path': repo.path, # 'installed_repo_id': repo.content_spec.label, 'installed_repo': repo, }) display_callback( "repo={installed_repo.content_spec.label}, type={type}, name={name}, version={version}" .format(**content_dict)) repo_list.append(content_dict) return repo_list
def select(self, namespace_match_filter=None): namespace_match_filter = namespace_match_filter or matchers.MatchAll() installed_namespaces = installed_namespace_iterator( self.installed_context, match_filter=namespace_match_filter) for matched_namespace in installed_namespaces: yield matched_namespace
def installed_repository_iterator(galaxy_context, namespace_match_filter=None, repository_match_filter=None): namespace_match_filter = namespace_match_filter or matchers.MatchAll() repository_match_filter = repository_match_filter or matchers.MatchAll() content_path = galaxy_context.content_path installed_namespace_db = installed_namespaces_db.InstalledNamespaceDatabase( galaxy_context) # repository_paths = get_repository_paths(content_path) # log.debug('repository_paths for content_path=%s: %s', content_path, repository_paths) for namespace in installed_namespace_db.select( namespace_match_filter=namespace_match_filter): # log.debug('namespace: %s', namespace) log.debug('Looking for repos in namespace "%s"', namespace.namespace) repository_paths = get_repository_paths(namespace.path) for repository_path in repository_paths: # use the default 'local' style content_spec_parse and name resolver # spec_data = content_spec_parse.spec_data_from_string(repository_path) repository_full_path = os.path.join(content_path, namespace.namespace, repository_path) # log.debug('repo_fll_path: %s', repository_full_path) content_spec = ContentSpec(namespace=namespace.namespace, name=repository_path) content_repository = ContentRepository(content_spec=content_spec, path=repository_full_path) # log.debug('content_repo: %s', content_repository) # log.debug('match: %s(%s) %s', repository_match_filter, content_repository, repository_match_filter(content_repository)) if repository_match_filter(content_repository): log.debug('Found repo "%s" in namespace "%s"', repository_path, namespace.namespace) yield content_repository
def select(self, namespace_match_filter=None, repository_match_filter=None, repository_spec=None): # ie, default to select * more or less repository_match_filter = repository_match_filter or matchers.MatchAll( ) namespace_match_filter = namespace_match_filter or matchers.MatchAll() if repository_spec: # We are being specific and looking for the repo identified by repository_spec installed_repositories = repository_spec_iterator( self.installed_context, repository_spec) else: installed_repositories = installed_repository_iterator( self.installed_context, namespace_match_filter=namespace_match_filter, repository_match_filter=repository_match_filter) for matched_installed_repository in installed_repositories: yield matched_installed_repository
def select(self, namespace_match_filter=None, repository_spec_match_filter=None, requirement_spec_match_filter=None): # ie, default to select * more or less namespace_match_filter = namespace_match_filter or matchers.MatchAll() repository_spec_match_filter = repository_spec_match_filter or matchers.MatchAll( ) requirement_spec_match_filter = requirement_spec_match_filter or matchers.MatchAll( ) # log.debug('repository_spec_match_filter: %s', repository_spec_match_filter) installed_repositories = installed_repository_iterator( self.installed_context, namespace_match_filter=namespace_match_filter, repository_spec_match_filter=repository_spec_match_filter, requirement_spec_match_filter=requirement_spec_match_filter) for matched_installed_repository in installed_repositories: yield matched_installed_repository
def execute_list(self): """ List roles installed on the local file system. """ galaxy_context = self._get_galaxy_context(self.options, self.config) match_filter = matchers.MatchAll() if self.args: match_filter = matchers.MatchNamespacesOrLabels(self.args) return list_action.list(galaxy_context, repository_match_filter=match_filter, display_callback=self.display)
def installed_namespace_iterator(galaxy_context, match_filter=None): namespace_match_filter = match_filter or matchers.MatchAll() content_path = galaxy_context.content_path namespace_paths = get_namespace_paths(content_path) log.debug('Looking for namespaces in %s', content_path) for namespace_path in namespace_paths: namespace_full_path = os.path.join(content_path, namespace_path) collection_namespace = GalaxyNamespace(namespace=namespace_path, path=namespace_full_path) if namespace_match_filter(collection_namespace): log.debug('Found namespace "%s"', collection_namespace.namespace) yield collection_namespace
def execute_list(self): """ List collections installed on the local file system. """ galaxy_context = self._get_galaxy_context(self.options, self.config) match_filter = matchers.MatchAll() list_content = self.options.list_content if self.args: match_filter = matchers.MatchNamespacesOrLabels(self.args) return list_action.list_action(galaxy_context, repository_spec_match_filter=match_filter, list_content=list_content, lockfile_format=self.options.list_lockfile_format, lockfile_freeze=self.options.list_lockfile_freeze, fully_qualified=self.options.list_fully_qualified, display_callback=self.display)
def _list(galaxy_context, repository_spec_match_filter=None, list_content=False, display_callback=None): log.debug('list_content: %s', list_content) all_repository_match = repository_spec_match_filter or matchers.MatchAll() # We search for installed repos to list, and then display all the content in those installed repos icidb = installed_content_item_db.InstalledContentItemDatabase( galaxy_context) irdb = installed_repository_db.InstalledRepositoryDatabase(galaxy_context) # accumulate for api return repo_list = [] for installed_repository in irdb.select( repository_spec_match_filter=all_repository_match): log.debug('installed_repo: %s', installed_repository) content_items = collections.defaultdict(list) # Find all the content items for this particular repo repository_match = matchers.MatchRepositorySpec( [installed_repository.repository_spec]) for content_info in icidb.select( repository_spec_match_filter=repository_match): content_dict = content_info.copy() content_item_type = content_dict['content_data'].content_item_type # revisit this output format once we get some feedback content_dict.update({ 'type': content_item_type, 'name': content_dict['content_data'].name, # 'installed_repo_namespace': repo.namespace, # 'installed_repo_name': repo.name, # 'installed_repo_path': repo.path, # 'installed_repo_id': repo.repository_spec.label, 'installed_repository': installed_repository, }) content_items[content_item_type].append(content_dict) # content_item_list.append(content_dict) repo_dict = { 'content_items': content_items, 'installed_repository': installed_repository } repo_list.append(repo_dict) for repo_item in repo_list: repo_msg = "repo={installed_repository.repository_spec.label}, type=repository, version={installed_repository.repository_spec.version}" display_callback(repo_msg.format(**repo_item)) if not list_content: continue for content_item_type_key, content_items_data in repo_item[ 'content_items'].items(): content_msg = "repo={installed_repository.repository_spec.label}, type={type}, name={name}, " + \ "version={installed_repository.repository_spec.version}" # content_msg = " type={type}, name={name}, " + \ # "version={installed_repository.repository_spec.version}" # type_msg = " {content_item_type}:" # display_callback(type_msg.format(content_item_type=content_item_type_key)) log.debug('content_item: %s', content_items_data) log.debug('content_item_type_key: %s', content_item_type_key) for content_item_data in content_items_data: display_callback(content_msg.format(**content_item_data)) # display_callback(msg.format(**content_dict)) return repo_list
def _list(galaxy_context, repository_spec_match_filter=None, list_content=False, output_format=None, display_callback=None): output_format = output_format or OutputFormat.HUMAN log.debug('list_content: %s', list_content) all_repository_match = repository_spec_match_filter or matchers.MatchAll() # We search for installed repos to list, and then display all the content in those installed repos icidb = installed_content_item_db.InstalledContentItemDatabase( galaxy_context) irdb = installed_repository_db.InstalledRepositoryDatabase(galaxy_context) # accumulate for api return repo_list = [] for installed_repository in irdb.select( repository_spec_match_filter=all_repository_match): log.debug('installed_repo: %s', installed_repository) content_items = collections.defaultdict(list) # Find all the content items for this particular repo repository_match = matchers.MatchRepositorySpec( [installed_repository.repository_spec]) for content_info in icidb.select( repository_spec_match_filter=repository_match): content_dict = content_info.copy() content_item_type = content_dict['content_data'].content_item_type # revisit this output format once we get some feedback content_dict.update({ 'type': content_item_type, 'name': content_dict['content_data'].name, 'is_plugin': content_dict['content_data'].is_plugin, # 'installed_repo_namespace': repo.namespace, # 'installed_repo_name': repo.name, # 'installed_repo_path': repo.path, # 'installed_repo_id': repo.repository_spec.label, 'installed_repository': installed_repository, }) content_items[content_item_type].append(content_dict) # content_item_list.append(content_dict) repo_dict = { 'content_items': content_items, 'installed_repository': installed_repository } repo_list.append(repo_dict) if output_format == OutputFormat.LOCKFILE: output = format_as_lockfile(repo_list, lockfile_freeze=False) display_callback(output) elif output_format == OutputFormat.LOCKFILE_FREEZE: output = format_as_lockfile(repo_list, lockfile_freeze=True) display_callback(output) elif output_format == OutputFormat.FULLY_QUALIFIED: display_fully_qualified(repo_list, list_content, display_callback) else: display_for_human(repo_list, list_content, display_callback) return repo_list
def installed_content_iterator(galaxy_context, namespace_match_filter=None, repository_match_filter=None, content_match_filter=None, content_type=None): # match_all works for all types namespace_match_filter = namespace_match_filter or matchers.MatchAll() repository_match_filter = repository_match_filter or matchers.MatchAll() content_match_filter = content_match_filter or matchers.MatchAll() content_type = content_type or 'roles' installed_repo_db = installed_repository_db.InstalledRepositoryDatabase(galaxy_context) # for namespace_full_path in namespace_paths_iterator: for installed_repository in installed_repo_db.select(namespace_match_filter=namespace_match_filter, repository_match_filter=repository_match_filter): log.debug('Found repo "%s" at %s', installed_repository.content_spec.label, installed_repository.path) installed_repository_full_path = installed_repository.path if not repository_match_filter(installed_repository): log.debug('The repo_match_filter %s failed to match for %s', repository_match_filter, installed_repository) continue # since we will need a different iterator for each specific type of content, consult # a map of content_type->iterator_method however there is only a 'roles' iterator for now installed_repository_content_iterator_method = \ installed_repository_content_iterator_map.get(content_type) if installed_repository_content_iterator_method is None: continue installed_repository_content_iterator = installed_repository_content_iterator_method(installed_repository_full_path) log.debug('Looking for %s in repo at %s', content_type, installed_repository_full_path) for installed_content_full_path in installed_repository_content_iterator: repo_namespace = installed_repository.content_spec.namespace path_file = os.path.basename(installed_content_full_path) gr = InstalledContent(galaxy_context, path_file, namespace=repo_namespace, path=installed_content_full_path) log.debug('Found %s "%s" at %s', gr.content_type, gr.name, installed_content_full_path) log.debug('gr.metadata: %s', gr.metadata) version = None # TODO: should probably sep the generator for getting the InstalledContent objects from the generator that # creates the content_info returns instead of intertwining them if gr.metadata or gr.install_info: version = gr.install_info.version or "(unknown version)" if not content_match_filter(gr): log.debug('%s was not matched by content_match_filter: %s', gr, content_match_filter) continue # this is sort of the 'join' of installed_repository and installed_content content_info = {'path': path_file, 'content_data': gr, 'installed_repository': installed_repository, 'version': version, } yield content_info