106 lines
3.4 KiB
Python
Executable file
106 lines
3.4 KiB
Python
Executable file
#!/usr/bin/env python
|
|
|
|
import os
|
|
import sys
|
|
|
|
version = "0.10"
|
|
program = os.path.basename(sys.argv[0])
|
|
progdir = os.path.dirname(sys.argv[0])
|
|
|
|
# boilerplate
|
|
basedir = os.path.abspath(os.path.join(os.path.dirname(__file__), "../.."))
|
|
sys.path = [ basedir ] + sys.path
|
|
os.environ["DJANGO_SETTINGS_MODULE"] = "ietf.settings"
|
|
|
|
virtualenv_activation = os.path.join(basedir, "env", "bin", "activate_this.py")
|
|
if os.path.exists(virtualenv_activation):
|
|
execfile(virtualenv_activation, dict(__file__=virtualenv_activation))
|
|
|
|
# ----------------------------------------------------------------------
|
|
def note(string):
|
|
sys.stdout.write("%s\n" % (string))
|
|
|
|
# ----------------------------------------------------------------------
|
|
def warn(string):
|
|
sys.stderr.write(" * %s\n" % (string))
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
import re
|
|
from datetime import datetime as Datetime
|
|
import time
|
|
import warnings
|
|
warnings.filterwarnings('ignore', message='the sets module is deprecated', append=True)
|
|
|
|
import django
|
|
django.setup()
|
|
|
|
from django.conf import settings
|
|
|
|
from ietf.utils.path import path as Path
|
|
|
|
from ietf.submit.models import Submission
|
|
from ietf.doc.models import Document
|
|
|
|
|
|
|
|
args = sys.argv[1:]
|
|
if len(args) < 3:
|
|
warn("Expected '$ %s DRAFTNAME USER.LOG POSTFIX.LOG', but found no arguments -- exiting" % program)
|
|
sys.exit(1)
|
|
|
|
draft = args[0]
|
|
if re.search("\.txt$", draft):
|
|
draft = draft[:-4]
|
|
if re.search("-\d\d$", draft):
|
|
draft = draft[:-3]
|
|
|
|
if len(args) == 1:
|
|
logfiles = [ arg[1] ]
|
|
else:
|
|
logfiles = args[1:]
|
|
|
|
from_email = settings.IDSUBMIT_FROM_EMAIL
|
|
if "<" in from_email:
|
|
from_email = from_email.split("<")[1].split(">")[0]
|
|
|
|
submission = Submission.objects.filter(name=draft).latest('submission_date')
|
|
document = Document.objects.get(name=draft)
|
|
emails = [ author.address for author in document.authors.all() ]
|
|
|
|
timestrings = []
|
|
for file in [ Path(settings.INTERNET_DRAFT_PATH) / ("%s-%s.txt"%(draft, submission.rev)),
|
|
Path(settings.IDSUBMIT_STAGING_PATH) / ("%s-%s.txt"%(draft, submission.rev)) ]:
|
|
if os.path.exists(file):
|
|
upload_time = time.localtime(file.mtime)
|
|
ts = time.strftime("%b %d %H:%M", upload_time)
|
|
timestrings += [ ts ]
|
|
timestrings += [ ts[:-1] + chr(((ord(ts[-1])-ord('0')+1)%10)+ord('0')) ]
|
|
print "Looking for mail log lines timestamped %s, also checking %s ..." % (timestrings[0], timestrings[1])
|
|
|
|
for log in logfiles:
|
|
print "\n Checking %s ...\n" % log
|
|
if log.endswith('.gz'):
|
|
import gzip
|
|
logfile = gzip.open(log)
|
|
else:
|
|
logfile = open(log)
|
|
queue_ids = []
|
|
for line in logfile:
|
|
if from_email in line and "Confirmation for Auto-Post of I-D "+draft in line:
|
|
ts = line[:12]
|
|
timestrings += [ ts ]
|
|
print "Found a mention of %s, adding timestamp %s: \n %s" % (draft, ts, line)
|
|
for ts in timestrings:
|
|
if line.startswith(ts):
|
|
if from_email in line:
|
|
for to_email in emails:
|
|
if to_email in line:
|
|
sys.stdout.write(line)
|
|
if "queued_as:" in line:
|
|
queue_ids += [ line.split("queued_as:")[1].split(",")[0] ]
|
|
elif queue_ids:
|
|
for qi in queue_ids:
|
|
if qi in line:
|
|
sys.stdout.write(line)
|