Trees | Indices | Help |
---|
|
1 import sys 2 import datetime 3 import click 4 from coprs import db, app 5 from coprs.logic import coprs_logic 6 from coprs.mail import send_mail, OutdatedChrootMessage 7 8 9 @click.command() 10 @click.option( 11 "--dry-run/--no-dry-run", 12 default=False, 13 help="Do not actually notify the people, but rather print information on stdout" 14 ) 15 @click.option( 16 "--email", "-e", "email_filter", 17 help="Notify only " 18 ) 19 @click.option( 20 "--all/--not-all", 21 default=False, 22 help="Notify all (even the recently notified) relevant people" 23 ) 2730 """ 31 Notify all admins of projects with builds in outdated chroots about upcoming deletion. 32 """ 33 34 if not dry_run: 35 dev_instance_warning(email_filter) 36 37 notifier = DryRunNotifier() if dry_run else Notifier() 38 outdated = coprs_logic.CoprChrootsLogic.filter_outdated(coprs_logic.CoprChrootsLogic.get_multiple()) 39 user_chroots_map = get_user_chroots_map(outdated, email_filter).items() 40 for i, (user, chroots) in enumerate(user_chroots_map, start=1): 41 chroots = filter_chroots([chroot for chroot in chroots], all) 42 if not chroots: 43 continue 44 chroots.sort(key=lambda x: x.copr.full_name) 45 notifier.notify(user, chroots) 46 47 # This command will possibly update a lot of chroots and can be a performance issue when committing 48 # all at once. We are going to commit every x actions to avoid that. 49 if i % 1000 == 0: 50 notifier.commit() 51 52 notifier.commit()5355 user_chroot_map = {} 56 for chroot in chroots: 57 for admin in coprs_logic.CoprPermissionsLogic.get_admins_for_copr(chroot.copr): 58 if email_filter and admin.mail not in email_filter: 59 continue 60 if admin not in user_chroot_map: 61 user_chroot_map[admin] = [] 62 user_chroot_map[admin].append(chroot) 63 return user_chroot_map6466 if all: 67 return chroots 68 69 filtered = [] 70 for chroot in chroots: 71 if not chroot.delete_notify: 72 filtered.append(chroot) 73 continue 74 75 # Skip the chroot if was notified in less than `n` days 76 now = datetime.datetime.now() 77 if (now - chroot.delete_notify).days >= app.config["EOL_CHROOTS_NOTIFICATION_PERIOD"]: 78 filtered.append(chroot) 79 80 return filtered8183 if app.config["ENV"] != "production" and not email_filter: 84 sys.stderr.write("I will not let you send emails to all Copr users from the dev instance!\n") 85 sys.stderr.write("Please use this command with -e myself@foo.bar\n") 86 sys.exit(1)87101 11091 msg = OutdatedChrootMessage(chroots) 92 send_mail([user.mail], msg) 93 94 # If `send_mail` didn't raise any exception, 95 # we consider the email to be sent correctly 96 for chroot in chroots: 97 chroot.delete_notify = datetime.datetime.now()98
Trees | Indices | Help |
---|
Generated by Epydoc 3.0.1 | http://epydoc.sourceforge.net |