def remove(self, repo_ids, **kwargs): """Remove entries from the maintenance report. Remove entries means the removing corresponding repositories from maintenance mode. Args: repo_ids (list[str]): A list of repository ids. Entries match repository ids will be removed from the maintenance report. owner (str) (optional): Who unset the maintenance mode. Returns: :class:`~pubtools.pulplib.MaintenanceReport` A copy of this maintenance report with removed repositories. """ owner = kwargs.get("owner") or self._OWNER repo_ids = set(repo_ids) # convert to set, make checking faster new_entries = [] for entry in self.entries: if entry.repo_id not in repo_ids: new_entries.append(entry) return attr.evolve(self, last_updated_by=owner, entries=new_entries)
def add(self, repo_ids, **kwargs): """Add entries to maintenance report and update the timestamp. Every entry added to the report represents a repository in maintenance mode. Args: repo_ids (list[str]): A list of repository ids. New entries with these repository ids will be added to the maintenance report. Note: it's users' responsibility to make sure the repository exists in the Pulp server, this method doesn't check for the existence of repositories. message (str) (optional): Reason why put the repo to maintenance. owner (str) (optional): Who set the maintenance mode. Returns: :class:`~pubtools.pulplib.MaintenanceReport` A copy of this maintenance report with added repositories. """ message = kwargs.get("message") or "Maintenance mode is enabled" owner = kwargs.get("owner") or self._OWNER to_add = [] for repo in repo_ids: to_add.append( MaintenanceEntry( repo_id=repo, owner=owner, message=message, started=datetime.datetime.utcnow(), )) entries = list(self.entries) entries.extend(to_add) # filter out duplicated entries. Filtering is in reverse order, which # means existed entries will be replaced by newer ones with same repo_id filtered_entries = [] entry_ids = set() for entry in reversed(entries): if entry.repo_id not in entry_ids: filtered_entries.append(entry) entry_ids.add(entry.repo_id) return attr.evolve( self, entries=filtered_entries, last_updated_by=owner, last_updated=datetime.datetime.utcnow(), )
def _map(self, fn): return attr.evolve(self, value=fn(self._value))
def _map(self, fn): return attr.evolve(self, values=[fn(x) for x in self._values])