def __init__(self, path_prefix, lock=False): self.password_file = \ CfgFile(os.path.join(path_prefix, "etc/passwd"), ":", {"username" : (1, None), "password" : (2, "x"), "uid" : (3, None), "gid" : (4, None), "gcos-field" : (5, "& User"), "home-dir" : (6, "/"), "login-shell": (7, "") }, "username", comment_match="[-+]") days = datetime.timedelta(seconds=time.time()).days self.shadow_file = \ CfgFile(os.path.join(path_prefix, "etc/shadow"), ":", {"username" : (1, None), "password" : (2, "*LK*"), "lastchg" : (3, days), "min" : (4, ""), "max" : (5, ""), "warn" : (6, ""), "inactive" : (7, ""), "expire" : (8, ""), "flag" : (9, "") }, "username", comment_match="[-+]") self.path_prefix = path_prefix self.lockfile = lockfile.LockFile( os.path.join(self.path_prefix, "etc/.pwd.lock")) if lock: self.lock() self.readfile() self.password_file.default_values["uid"] = self.getnextuid()
def __init__(self, index_dir, get_manifest_func, get_manifest_path_func, progtrack=None, excludes=EmptyI, log=None, sort_file_max_size=SORT_FILE_MAX_SIZE): self._num_keys = 0 self._num_manifests = 0 self._num_entries = 0 self.get_manifest_func = get_manifest_func self.get_manifest_path_func = get_manifest_path_func self.excludes = excludes self.__log = log self.sort_file_max_size = sort_file_max_size if self.sort_file_max_size <= 0: raise search_errors.IndexingException( _("sort_file_max_size must be greater than 0")) # This structure was used to gather all index files into one # location. If a new index structure is needed, the files can # be added (or removed) from here. Providing a list or # dictionary allows an easy approach to opening or closing all # index files. self._data_dict = { "fast_add": ss.IndexStoreSet(ss.FAST_ADD), "fast_remove": ss.IndexStoreSet(ss.FAST_REMOVE), "manf": ss.IndexStoreListDict(ss.MANIFEST_LIST, build_function=self.__build_fmri, decode_function=self.__decode_fmri), "full_fmri": ss.IndexStoreSet(ss.FULL_FMRI_FILE), "main_dict": ss.IndexStoreMainDict(ss.MAIN_FILE), "token_byte_offset": ss.IndexStoreDictMutable(ss.BYTE_OFFSET_FILE) } self._data_fast_add = self._data_dict["fast_add"] self._data_fast_remove = self._data_dict["fast_remove"] self._data_manf = self._data_dict["manf"] self._data_full_fmri = self._data_dict["full_fmri"] self._data_main_dict = self._data_dict["main_dict"] self._data_token_offset = self._data_dict["token_byte_offset"] # This is added to the dictionary after the others because it # needs one of the other mappings as an input. self._data_dict["fmri_offsets"] = \ ss.InvertedDict(ss.FMRI_OFFSETS_FILE, self._data_manf) self._data_fmri_offsets = self._data_dict["fmri_offsets"] self._index_dir = index_dir self._tmp_dir = os.path.join(self._index_dir, "TMP") self.__lockfile = lockfile.LockFile(os.path.join( self._index_dir, "lock"), set_lockstr=lockfile.generic_lock_set_str, get_lockstr=lockfile.generic_lock_get_str, failure_exc=search_errors.IndexLockedException) self._indexed_manifests = 0 self.server_repo = True self.empty_index = False self.file_version_number = None if progtrack is None: self._progtrack = progress.NullProgressTracker() else: self._progtrack = progtrack self._file_timeout_secs = FILE_OPEN_TIMEOUT_SECS self._sort_fh = None self._sort_file_num = 0 self._sort_file_bytes = 0 # The action type and key indexes, which are necessary for # efficient searches by type or key, store their file handles in # dictionaries. File handles for actions are in at_fh, while # filehandles for keys are kept in st_fh. self.at_fh = {} self.st_fh = {} self.old_out_token = None