Fixed nomcom email pipe command to read from stdin if no file given, and give better error messages.
- Legacy-Id: 5992
This commit is contained in:
parent
c6b688e0af
commit
8b6f122314
|
@ -14,7 +14,10 @@ class EncryptedTextField(models.TextField):
|
|||
if add:
|
||||
comments = smart_str(getattr(instance, 'comments'))
|
||||
nomcom = getattr(instance, 'nomcom')
|
||||
cert_file = nomcom.public_key.path
|
||||
try:
|
||||
cert_file = nomcom.public_key.path
|
||||
except ValueError as e:
|
||||
raise ValueError("Trying to read the NomCom public key: " + str(e))
|
||||
|
||||
code, out, error = pipe("%s smime -encrypt -in /dev/stdin %s" % (settings.OPENSSL_COMMAND,
|
||||
cert_file), comments)
|
||||
|
|
|
@ -1,17 +1,20 @@
|
|||
import sys
|
||||
from optparse import make_option
|
||||
import syslog
|
||||
|
||||
from django.core.management.base import BaseCommand, CommandError
|
||||
|
||||
from ietf.utils.log import log
|
||||
from ietf.nomcom.models import NomCom
|
||||
from ietf.nomcom.utils import create_feedback_email
|
||||
from ietf.nomcom.fields import EncryptedException
|
||||
|
||||
import debug
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = (u"Registry feedback from email. Usage: feeback_email --nomcom-year <nomcom-year> --email-file <email-file>")
|
||||
help = (u"Receive email feedback, encrypt and save it.")
|
||||
option_list = BaseCommand.option_list + (
|
||||
make_option('--nomcom-year', dest='year', help='NomCom year'),
|
||||
make_option('--email-file', dest='email', help='Feedback email'),)
|
||||
make_option('--email-file', dest='email', help='Feedback email filename (default: stdin)'),)
|
||||
|
||||
def handle(self, *args, **options):
|
||||
email = options.get('email', None)
|
||||
|
@ -21,10 +24,10 @@ class Command(BaseCommand):
|
|||
help_message = 'Usage: feeback_email --nomcom-year <nomcom-year> --email-file <email-file>'
|
||||
|
||||
if not year:
|
||||
raise CommandError(help_message)
|
||||
raise CommandError("Missing nomcom-year\n\n"+help_message)
|
||||
|
||||
if not email:
|
||||
raise CommandError(help_message)
|
||||
msg = sys.stdin.read()
|
||||
else:
|
||||
msg = open(email, "r").read()
|
||||
|
||||
|
@ -34,5 +37,8 @@ class Command(BaseCommand):
|
|||
except NomCom.DoesNotExist:
|
||||
raise CommandError("NomCom %s does not exist or it isn't active" % year)
|
||||
|
||||
feedback = create_feedback_email(nomcom, msg)
|
||||
syslog.syslog(u"Read feedback email by %s" % feedback.author)
|
||||
try:
|
||||
feedback = create_feedback_email(nomcom, msg)
|
||||
log(u"Read feedback email by %s" % feedback.author)
|
||||
except (EncryptedException, ValueError) as e:
|
||||
raise CommandError(e)
|
||||
|
|
|
@ -22,7 +22,7 @@ from ietf.person.models import Email, Person
|
|||
from ietf.utils.pipe import pipe
|
||||
from ietf.utils import unaccent
|
||||
from ietf.utils.mail import send_mail_text, send_mail
|
||||
|
||||
from ietf.utils.log import log
|
||||
|
||||
MAIN_NOMCOM_TEMPLATE_PATH = '/nomcom/defaults/'
|
||||
QUESTIONNAIRE_TEMPLATE = 'position/questionnaire.txt'
|
||||
|
|
Loading…
Reference in a new issue