def info(self, fmri_strings, info_needed, excludes=misc.EmptyI): """Gathers information about fmris. fmri_strings is a list of fmri_names for which information is desired. It returns a dictionary of lists. The keys for the dictionary are the constants specified in the class definition. The values are lists of PackageInfo objects or strings.""" bad_opts = info_needed - PackageInfo.ALL_OPTIONS if bad_opts: raise api_errors.UnrecognizedOptionsToInfo(bad_opts) fmris = [] notfound = [] illegals = [] for pattern in fmri_strings: try: pfmri = None pfmri = self.get_matching_pattern_fmris(pattern) except pkg.fmri.IllegalFmri, e: illegals.append(pattern) continue else: fmris.extend(pfmri[0]) if not pfmri: notfound.append(pattern)
def info(self, fmri_strings, info_needed, excludes=misc.EmptyI): """Gathers information about fmris. fmri_strings is a list of fmri_names for which information is desired. It returns a dictionary of lists. The keys for the dictionary are the constants specified in the class definition. The values are lists of PackageInfo objects or strings.""" bad_opts = info_needed - PackageInfo.ALL_OPTIONS if bad_opts: raise api_errors.UnrecognizedOptionsToInfo(bad_opts) fmris = [] notfound = [] illegals = [] for pattern in fmri_strings: try: pfmri = None pfmri = self.get_matching_pattern_fmris(pattern) except pkg.fmri.IllegalFmri as e: illegals.append(pattern) continue else: fmris.extend(pfmri[0]) if not pfmri: notfound.append(pattern) repo_cat = self._depot.repo.get_catalog(self._pub) # Set of options that can use catalog data. cat_opts = frozenset([PackageInfo.SUMMARY, PackageInfo.CATEGORIES, PackageInfo.DESCRIPTION, PackageInfo.DEPENDENCIES]) # Set of options that require manifest retrieval. act_opts = PackageInfo.ACTION_OPTIONS - \ frozenset([PackageInfo.DEPENDENCIES]) pis = [] for f in fmris: pub = name = version = release = None build_release = branch = packaging_date = None if PackageInfo.IDENTITY in info_needed: pub, name, version = f.tuple() release = version.release build_release = version.build_release branch = version.branch packaging_date = \ version.get_timestamp().strftime("%c") states = None links = hardlinks = files = dirs = dependencies = None summary = csize = size = licenses = cat_info = \ description = None if cat_opts & info_needed: summary, description, cat_info, dependencies = \ _get_pkg_cat_data(repo_cat, info_needed, excludes=excludes, pfmri=f) if cat_info is not None: cat_info = [ PackageCategory(scheme, cat) for scheme, cat in cat_info ] if (frozenset([PackageInfo.SIZE, PackageInfo.LICENSES]) | act_opts) & info_needed: mfst = manifest.Manifest(f) try: mpath = self._depot.repo.manifest(f) except srepo.RepositoryError as e: notfound.append(f) continue if not os.path.exists(mpath): notfound.append(f) continue mfst.set_content(pathname=mpath) if PackageInfo.LICENSES in info_needed: licenses = self.__licenses(mfst) if PackageInfo.SIZE in info_needed: size, csize = mfst.get_size( excludes=excludes) if act_opts & info_needed: if PackageInfo.LINKS in info_needed: links = list( mfst.gen_key_attribute_value_by_type( "link", excludes)) if PackageInfo.HARDLINKS in info_needed: hardlinks = list( mfst.gen_key_attribute_value_by_type( "hardlink", excludes)) if PackageInfo.FILES in info_needed: files = list( mfst.gen_key_attribute_value_by_type( "file", excludes)) if PackageInfo.DIRS in info_needed: dirs = list( mfst.gen_key_attribute_value_by_type( "dir", excludes)) pis.append(PackageInfo(pkg_stem=name, summary=summary, category_info_list=cat_info, states=states, publisher=pub, version=release, build_release=build_release, branch=branch, packaging_date=packaging_date, size=size, csize=csize, pfmri=f, licenses=licenses, links=links, hardlinks=hardlinks, files=files, dirs=dirs, dependencies=dependencies, description=description)) return { self.INFO_FOUND: pis, self.INFO_MISSING: notfound, self.INFO_ILLEGALS: illegals }