Ejemplo n.º 1
0
    def __set_perms(self):
        """Sets permissions on catalog files if not read_only and if the
                current user can do so; raises CatalogPermissionsException if
                the permissions are wrong and cannot be corrected."""

        apath = os.path.normpath(os.path.join(self.catalog_root, "attrs"))
        cpath = os.path.normpath(os.path.join(self.catalog_root, "catalog"))

        # Force file_mode, so that unprivileged users can read these.
        bad_modes = []
        for fpath in (apath, cpath):
            try:
                if self.read_only:
                    try:
                        portable.assert_mode(fpath, self.file_mode)
                    except AssertionError, ae:
                        bad_modes.append((fpath, "%o" % self.file_mode, "%o" % ae.mode))
                else:
                    os.chmod(fpath, self.file_mode)
Ejemplo n.º 2
0
        def __set_perms(self):
                """Sets permissions on catalog files if not read_only and if the
                current user can do so; raises CatalogPermissionsException if
                the permissions are wrong and cannot be corrected."""

                apath = os.path.normpath(os.path.join(self.catalog_root,
                    "attrs"))
                cpath = os.path.normpath(os.path.join(self.catalog_root,
                    "catalog"))

                # Force file_mode, so that unprivileged users can read these.
                bad_modes = []
                for fpath in (apath, cpath):
                        try:
                                if self.read_only:
                                        try:
                                                portable.assert_mode(fpath,
                                                    self.file_mode)
                                        except AssertionError as ae:
                                                bad_modes.append((fpath,
                                                    "{0:o}".format(self.file_mode),
                                                    "{0:o}".format(ae.mode)))
                                else:
                                        os.chmod(fpath, self.file_mode)
                        except EnvironmentError as e:
                                # If the files don't exist yet, move on.
                                if e.errno == errno.ENOENT:
                                        continue

                                # If the mode change failed for another reason,
                                # check to see if we actually needed to change
                                # it, and if so, add it to bad_modes.
                                try:
                                        portable.assert_mode(fpath,
                                            self.file_mode)
                                except AssertionError as ae:
                                        bad_modes.append((fpath,
                                            "{0:o}".format(self.file_mode),
                                            "{0:o}".format(ae.mode)))

                if bad_modes:
                        raise CatalogPermissionsException(bad_modes)
Ejemplo n.º 3
0
    def __set_perms(self):
        """Sets permissions on catalog files if not read_only and if the
                current user can do so; raises CatalogPermissionsException if
                the permissions are wrong and cannot be corrected."""

        apath = os.path.normpath(os.path.join(self.catalog_root, "attrs"))
        cpath = os.path.normpath(os.path.join(self.catalog_root, "catalog"))

        # Force file_mode, so that unprivileged users can read these.
        bad_modes = []
        for fpath in (apath, cpath):
            try:
                if self.read_only:
                    try:
                        portable.assert_mode(fpath, self.file_mode)
                    except AssertionError, ae:
                        bad_modes.append(
                            (fpath, "%o" % self.file_mode, "%o" % ae.mode))
                else:
                    os.chmod(fpath, self.file_mode)
Ejemplo n.º 4
0
                        portable.assert_mode(fpath, self.file_mode)
                    except AssertionError, ae:
                        bad_modes.append(
                            (fpath, "%o" % self.file_mode, "%o" % ae.mode))
                else:
                    os.chmod(fpath, self.file_mode)
            except EnvironmentError, e:
                # If the files don't exist yet, move on.
                if e.errno == errno.ENOENT:
                    continue

                # If the mode change failed for another reason,
                # check to see if we actually needed to change
                # it, and if so, add it to bad_modes.
                try:
                    portable.assert_mode(fpath, self.file_mode)
                except AssertionError, ae:
                    bad_modes.append(
                        (fpath, "%o" % self.file_mode, "%o" % ae.mode))

        if bad_modes:
            raise CatalogPermissionsException(bad_modes)

    def add_fmri(self, pfmri, critical=False):
        """Add a package, named by the fmri, to the catalog.
                Throws an exception if an identical package is already
                present.  Throws an exception if package has no version."""
        if pfmri.version == None:
            raise CatalogException, \
                "Unversioned FMRI not supported: %s" % pfmri
Ejemplo n.º 5
0
                                        except AssertionError, ae:
                                                bad_modes.append((fpath,
                                                    "%o" % self.file_mode,
                                                    "%o" % ae.mode))
                                else:
                                        os.chmod(fpath, self.file_mode)
                        except EnvironmentError, e:
                                # If the files don't exist yet, move on.
                                if e.errno == errno.ENOENT:
                                        continue

                                # If the mode change failed for another reason,
                                # check to see if we actually needed to change
                                # it, and if so, add it to bad_modes.
                                try:
                                        portable.assert_mode(fpath,
                                            self.file_mode)
                                except AssertionError, ae:
                                        bad_modes.append((fpath,
                                            "%o" % self.file_mode,
                                            "%o" % ae.mode))
 
                if bad_modes:
                        raise CatalogPermissionsException(bad_modes)

        def add_fmri(self, pfmri, critical = False):
                """Add a package, named by the fmri, to the catalog.
                Throws an exception if an identical package is already
                present.  Throws an exception if package has no version."""
                if pfmri.version == None:
                        raise CatalogException, \
                            "Unversioned FMRI not supported: %s" % pfmri