def prepare_depchange(self, dep_name, prev_epoch, prev_version, prev_release, curr_epoch, curr_version, curr_release, build_id, distance): prev_dep = get_or_create( self.db, Dependency, name=dep_name, epoch=prev_epoch, version=prev_version, release=prev_release, arch='x86_64', ) curr_dep = get_or_create( self.db, Dependency, name=dep_name, epoch=curr_epoch, version=curr_version, release=curr_release, arch='x86_64', ) self.db.flush() change = AppliedChange( prev_dep_id=prev_dep.id, curr_dep_id=curr_dep.id, distance=distance, build_id=build_id, ) self.db.add(change) self.db.commit() return change
def prepare_depchange(self, dep_name, prev_epoch, prev_version, prev_release, curr_epoch, curr_version, curr_release, build_id, distance): prev_dep = get_or_create( self.db, Dependency, name=dep_name, epoch=prev_epoch, version=prev_version, release=prev_release, arch='x86_64', ) curr_dep = get_or_create( self.db, Dependency, name=dep_name, epoch=curr_epoch, version=curr_version, release=curr_release, arch='x86_64', ) self.db.flush() change = AppliedChange( prev_dep_id=prev_dep.id, curr_dep_id=curr_dep.id, distance=distance, build_id=build_id, ) self.db.add(change) self.db.commit() return change
def set_group_maintainers(session, group, maintainers): """ Sets given group maintaners to given list of names. :param: session koschei session :param: group PackageGroup object :param: maintainers list of maintainer names """ current_users = set( session.db.query(User).join(GroupACL).filter( GroupACL.group_id == group.id).all()) new_users = { get_or_create(session.db, User, name=name) for name in set(maintainers) } session.db.flush() to_add = new_users - current_users if to_add: session.db.execute( insert(GroupACL), [dict(group_id=group.id, user_id=user.id) for user in to_add], ) for user in to_add: session.log_user_action( "Group {} modified: maintainer {} added".format( group.name, user.name)) to_delete = current_users - new_users if to_delete: (session.db.query(GroupACL).filter( GroupACL.group_id == group.id).filter( GroupACL.user_id.in_(user.id for user in to_delete)).delete()) for user in to_delete: session.log_user_action( "Group {} modified: maintainer {} removed".format( group.name, user.name))
def log_user_action(self, message, **kwargs): username = os.environ.get('SUDO_USER', pwd.getpwuid(os.getuid()).pw_name) user = get_or_create(self.db, User, name=username) self.db.add( LogEntry(environment='admin', user=user, message=message, **kwargs)) print(message)
def set_group_maintainers(session, group, maintainers): """ Sets given group maintaners to given list of names. :param: session koschei session :param: group PackageGroup object :param: maintainers list of maintainer names """ current_users = set( session.db.query(User) .join(GroupACL) .filter(GroupACL.group_id == group.id) .all() ) new_users = {get_or_create(session.db, User, name=name) for name in set(maintainers)} session.db.flush() to_add = new_users - current_users if to_add: session.db.execute( insert(GroupACL), [dict(group_id=group.id, user_id=user.id) for user in to_add], ) for user in to_add: session.log_user_action( "Group {} modified: maintainer {} added".format(group.name, user.name) ) to_delete = current_users - new_users if to_delete: ( session.db.query(GroupACL) .filter(GroupACL.group_id == group.id) .filter(GroupACL.user_id.in_(user.id for user in to_delete)) .delete() ) for user in to_delete: session.log_user_action( "Group {} modified: maintainer {} removed".format(group.name, user.name) )
def log_user_action(self, message, **kwargs): username = os.environ.get('SUDO_USER', pwd.getpwuid(os.getuid()).pw_name) user = get_or_create(self.db, User, name=username) self.db.add(LogEntry(environment='admin', user=user, message=message, **kwargs)) print(message)