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 }
class CatalogInterface(_Interface): """This class presents an interface to server catalog objects that clients may use. """ # Constants used to reference specific values that info can return. INFO_FOUND = 0 INFO_MISSING = 1 INFO_ILLEGALS = 3 def fmris(self): """A generator function that produces FMRIs as it iterates over the contents of the server's catalog.""" try: c = self._depot.repo.catalog except srepo.RepositoryMirrorError: return iter(()) return self._depot.repo.catalog.fmris() def get_entry_all_variants(self, pfmri): """A generator function that yields tuples of the format (var_name, variants); where var_name is the name of the variant and variants is a list of the variants for that name.""" try: c = self._depot.repo.catalog except srepo.RepositoryMirrorError: return iter(((), {})) return self._depot.repo.catalog.get_entry_all_variants(pfmri) def get_matching_pattern_fmris(self, patterns): """Returns a tuple of a sorted list of PkgFmri objects, newest versions first, for packages matching those found in the 'patterns' list, and a dict of unmatched patterns indexed by match criteria. """ try: c = self._depot.repo.catalog except srepo.RepositoryMirrorError: return tuple(), {} return pkg.catalog.extract_matching_fmris(c.fmris(), patterns=patterns) def get_matching_version_fmris(self, versions): """Returns a tuple of a sorted list of PkgFmri objects, newest versions first, for packages matching those found in the 'versions' list, and a dict of unmatched versions indexed by match criteria. 'versions' should be a list of strings of the format: release,build_release-branch:datetime ...with a value of '*' provided for any component to be ignored. '*' or '?' may be used within each component value and will act as wildcard characters ('*' for one or more characters, '?' for a single character). """ try: c = self._depot.repo.catalog except srepo.RepositoryMirrorError: return tuple(), {} return pkg.catalog.extract_matching_fmris(c.fmris(), versions=versions) 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) repo_cat = self._depot.repo.catalog # 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() pub = pkg.fmri.strip_pub_pfx(pub) 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 = 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() mfst.set_fmri(None, f) try: mpath = os.path.join( self._depot.repo.manifest_root, f.get_dir_path()) except pkg.fmri.FmriError, e: notfound.append(f) continue if not os.path.exists(mpath): notfound.append(f) continue mfst.set_content(file(mpath).read()) if PackageInfo.LICENSES in info_needed: licenses = self.__licenses(mfst) if PackageInfo.SIZE in info_needed: size = 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, pfmri=str(f), licenses=licenses, links=links, hardlinks=hardlinks, files=files, dirs=dirs, dependencies=dependencies, description=description))