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)
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)
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)
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
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