list_emails.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. # nm.debian.org list-of-email reports to be used for generating aliases
  2. #
  3. # Copyright (C) 2013 Enrico Zini <enrico@debian.org>
  4. #
  5. # This program is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU Affero General Public License as
  7. # published by the Free Software Foundation, either version 3 of the
  8. # License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU Affero General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU Affero General Public License
  16. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. from django.core.management.base import BaseCommand, CommandError
  18. from django.core.mail import send_mail
  19. import django.db
  20. from django.conf import settings
  21. from django.db import connection, transaction
  22. from django.contrib.sites.models import Site
  23. from django.db.models import Count, Min, Max
  24. import optparse
  25. import sys
  26. import datetime
  27. import logging
  28. import json
  29. import os
  30. import os.path
  31. import gzip
  32. import re
  33. import time
  34. import codecs
  35. from cStringIO import StringIO
  36. from backend import models as bmodels
  37. from backend import const
  38. from backend import utils
  39. log = logging.getLogger(__name__)
  40. class Reports(object):
  41. def list_ctte(self):
  42. """
  43. List members of NM committee
  44. """
  45. from django.db.models import Q
  46. for am in bmodels.AM.objects.filter(Q(is_am_ctte=True) | Q(is_fd=True) | Q(is_dam=True)):
  47. yield am.person.email
  48. def list_fd(self):
  49. """
  50. List members of Front Desk
  51. """
  52. from django.db.models import Q
  53. for am in bmodels.AM.objects.filter(Q(is_fd=True) | Q(is_dam=True)):
  54. yield am.person.email
  55. def list_dam(self):
  56. """
  57. List Debian Account Managers
  58. """
  59. for am in bmodels.AM.objects.filter(is_dam=True):
  60. yield am.person.email
  61. def list_am(self):
  62. """
  63. List active application managers
  64. """
  65. from django.db.models import Q
  66. for am in bmodels.AM.objects.filter(Q(is_am=True) | Q(is_fd=True) | Q(is_dam=True)):
  67. yield am.person.email
  68. class Command(BaseCommand):
  69. help = 'List email addresses. Run with --list to get a list of valid groups of people. More than one group can be queried at the same time.'
  70. option_list = BaseCommand.option_list + (
  71. optparse.make_option("--quiet", action="store_true", default=None, help="Disable progress reporting"),
  72. optparse.make_option("--list", action="store_true", default=None, help="List available groups"),
  73. optparse.make_option("--procmail", action="store_true", default=None, help="List as a procmail forward file"),
  74. )
  75. def handle(self, *args, **opts):
  76. FORMAT = "%(asctime)-15s %(levelname)s %(message)s"
  77. if opts["quiet"]:
  78. logging.basicConfig(level=logging.WARNING, stream=sys.stderr, format=FORMAT)
  79. else:
  80. logging.basicConfig(level=logging.INFO, stream=sys.stderr, format=FORMAT)
  81. reports = Reports()
  82. # List available reports if requested
  83. if opts["list"]:
  84. import inspect
  85. for name, m in inspect.getmembers(reports, predicate=inspect.ismethod):
  86. if not name.startswith("list_"): continue
  87. print name[5:], "-", m.__doc__.strip()
  88. return
  89. # Run all reports, merge their results
  90. result = set()
  91. for arg in args:
  92. method = getattr(reports, "list_" + arg, None)
  93. if method is None:
  94. print >>sys.stderr, "Report '%s' not found" % arg
  95. continue
  96. result.update(method())
  97. # Sort and print what we got
  98. if opts["procmail"]:
  99. print "# Automatically generated - do not edit"
  100. for email in sorted(result):
  101. print ":0c"
  102. print "!", email
  103. else:
  104. for email in sorted(result):
  105. print email