catalog.py revision 34
23N/A#!/usr/bin/python
23N/A#
23N/A# CDDL HEADER START
23N/A#
23N/A# The contents of this file are subject to the terms of the
23N/A# Common Development and Distribution License (the "License").
23N/A# You may not use this file except in compliance with the License.
23N/A#
23N/A# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
23N/A# or http://www.opensolaris.org/os/licensing.
23N/A# See the License for the specific language governing permissions
23N/A# and limitations under the License.
23N/A#
23N/A# When distributing Covered Code, include this CDDL HEADER in each
23N/A# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
23N/A# If applicable, add the following below this CDDL HEADER, with the
23N/A# fields enclosed by brackets "[]" replaced with your own identifying
23N/A# information: Portions Copyright [yyyy] [name of copyright owner]
23N/A#
23N/A# CDDL HEADER END
23N/A#
23N/A# Copyright 2007 Sun Microsystems, Inc. All rights reserved.
23N/A# Use is subject to license terms.
23N/A
23N/Aimport os
23N/Aimport re
23N/Aimport sha
23N/Aimport shutil
23N/Aimport time
23N/Aimport urllib
23N/A
23N/Aimport pkg.fmri as fmri
23N/A
34N/Aclass Catalog(object):
34N/A """A Catalog is the representation of the package FMRIs available to
34N/A this client or repository. Both purposes utilize the same storage
34N/A format.
24N/A
26N/A The serialized structure of the repository is an unordered list of
26N/A available package versions, followed by an unordered list of
26N/A incorporation relationships between packages. This latter section
26N/A allows the graph to be topologically sorted by the client.
26N/A
26N/A V fmri
26N/A V fmri
26N/A ...
26N/A I fmri fmri
26N/A I fmri fmri
26N/A ...
26N/A
30N/A XXX It would be nice to include available tags and package sizes,
30N/A although this could also be calculated from the set of manifests.
26N/A """
23N/A
23N/A def __init__(self):
34N/A self.authority = None
34N/A self.catalog_root = ""
34N/A
26N/A self.pkgs = []
24N/A self.relns = {}
23N/A return
23N/A
34N/A def set_authority(self, authority):
34N/A self.authority = authority
34N/A
34N/A def set_catalog_root(self, croot):
34N/A self.catalog_root = croot
34N/A
34N/A def load(self):
34N/A # open file
34N/A # get lines
34N/A # each V line is an fmri
34N/A # split into a package and a version
34N/A # add package to pkgs
34N/A # add version to pkg
34N/A # stop at end of file
34N/A return
34N/A
26N/A def add_pkg(self, pkg):
26N/A if not pkg in self.pkgs:
26N/A self.pkgs.append(pkg)
26N/A
26N/A # for each version in the package,
26N/A # for each incorporation in the version,
26N/A # add to the version's list of incorporations
26N/A
24N/A return
24N/A
34N/A def add_package_fmri(self, pkg_fmri):
34N/A return
34N/A
34N/A def delete_package_fmri(self, pkg_fmri):
34N/A return
34N/A
30N/A def matching_pkgs(self, pfmri, constraint):
30N/A # iterate through pkgs, looking for an fmri match
30N/A for pkg in self.pkgs:
30N/A if pkg.fmri.is_similar(pfmri):
30N/A return pkg.matching_versions(pfmri, constraint)
30N/A
30N/A raise KeyError, "%s not found in catalog" % pfmri
30N/A
24N/A def __str__(self):
24N/A s = ""
26N/A for p in self.pkgs:
26N/A s = s + p.get_catalog()
24N/A for r in self.relns:
26N/A s = s + "I %s\n" % r
24N/A return s
24N/A
34N/A def difference(self, catalog):
34N/A """Return a pair of lists, the first list being those package
34N/A FMRIs present in the current object but not in the presented
34N/A catalog, the second being those present in the presented catalog
34N/A but not in the current catalog."""
34N/A return