Clean up old draft files when submitting a new draft

- Legacy-Id: 3811
This commit is contained in:
Ole Laursen 2012-01-13 16:38:00 +00:00
parent f49701c9d3
commit 923239a5dc
4 changed files with 34 additions and 15 deletions

View file

@ -6,7 +6,7 @@ from django.db.models import Q
import datetime, os, shutil, glob, re, itertools
from ietf.idtracker.models import InternetDraft, IDDates, IDStatus, IDState, DocumentComment, IDAuthor,WGChair
from ietf.idtracker.models import InternetDraft, IDDates, IDStatus, IDState, DocumentComment, IDAuthor, WGChair
from ietf.utils.mail import send_mail, send_mail_subj
from ietf.idrfc.utils import log_state_changed, add_document_comment
from redesign.doc.models import Document, DocEvent, save_document_in_history, State
@ -154,7 +154,7 @@ def send_expire_notice_for_idREDESIGN(doc):
def expire_id(doc):
def move_file(f):
src = os.path.join(settings.IDSUBMIT_REPOSITORY_PATH, f)
src = os.path.join(settings.INTERNET_DRAFT_PATH, f)
dst = os.path.join(settings.INTERNET_DRAFT_ARCHIVE_DIR, f)
if os.path.exists(src):
@ -167,7 +167,7 @@ def expire_id(doc):
new_revision = "%02d" % (int(doc.revision) + 1)
new_file = open(os.path.join(settings.IDSUBMIT_REPOSITORY_PATH, "%s-%s.txt" % (doc.filename, new_revision)), 'w')
new_file = open(os.path.join(settings.INTERNET_DRAFT_PATH, "%s-%s.txt" % (doc.filename, new_revision)), 'w')
txt = render_to_string("idrfc/expire_text.txt",
dict(doc=doc,
authors=[a.person.email() for a in doc.authors.all()],
@ -188,12 +188,9 @@ def expire_id(doc):
add_document_comment(None, doc, "Document is expired by system")
def expire_idREDESIGN(doc):
system = Person.objects.get(name="(System)")
# clean up files
def move_draft_files_to_archive(doc, rev):
def move_file(f):
src = os.path.join(settings.IDSUBMIT_REPOSITORY_PATH, f)
src = os.path.join(settings.INTERNET_DRAFT_PATH, f)
dst = os.path.join(settings.INTERNET_DRAFT_ARCHIVE_DIR, f)
if os.path.exists(src):
@ -201,10 +198,15 @@ def expire_idREDESIGN(doc):
file_types = ['txt', 'txt.p7s', 'ps', 'pdf']
for t in file_types:
move_file("%s-%s.%s" % (doc.name, doc.rev, t))
move_file("%s-%s.%s" % (doc.name, rev, t))
def expire_idREDESIGN(doc):
# clean up files
move_draft_files_to_archive(doc, doc.rev)
# change the state
system = Person.objects.get(name="(System)")
# now change the state
save_document_in_history(doc)
if doc.latest_event(type='started_iesg_process'):
dead_state = State.objects.get(type="draft-iesg", slug="dead")
@ -230,7 +232,7 @@ def clean_up_id_files():
"""Move unidentified and old files out of the Internet Draft directory."""
cut_off = datetime.date.today() - datetime.timedelta(days=InternetDraft.DAYS_TO_EXPIRE)
pattern = os.path.join(settings.IDSUBMIT_REPOSITORY_PATH, "draft-*.*")
pattern = os.path.join(settings.INTERNET_DRAFT_PATH, "draft-*.*")
files = []
filename_re = re.compile('^(.*)-(\d\d)$')
@ -290,7 +292,7 @@ def clean_up_id_filesREDESIGN():
"""Move unidentified and old files out of the Internet Draft directory."""
cut_off = datetime.date.today()
pattern = os.path.join(settings.IDSUBMIT_REPOSITORY_PATH, "draft-*.*")
pattern = os.path.join(settings.INTERNET_DRAFT_PATH, "draft-*.*")
files = []
filename_re = re.compile('^(.*)-(\d\d)$')

View file

@ -831,7 +831,7 @@ class ExpireIDsTestCase(django.test.TestCase):
os.mkdir(os.path.join(self.archive_dir, "deleted_tombstones"))
os.mkdir(os.path.join(self.archive_dir, "expired_without_tombstone"))
settings.IDSUBMIT_REPOSITORY_PATH = self.id_dir
settings.INTERNET_DRAFT_PATH = self.id_dir
settings.INTERNET_DRAFT_ARCHIVE_DIR = self.archive_dir
def tearDown(self):

View file

@ -26,11 +26,16 @@ class SubmitTestCase(django.test.TestCase):
self.repository_dir = os.path.abspath("tmp-submit-repository-dir")
os.mkdir(self.repository_dir)
settings.IDSUBMIT_REPOSITORY_PATH = self.repository_dir
settings.INTERNET_DRAFT_PATH = settings.IDSUBMIT_REPOSITORY_PATH = self.repository_dir
self.archive_dir = os.path.abspath("tmp-submit-archive-dir")
os.mkdir(self.archive_dir)
settings.INTERNET_DRAFT_ARCHIVE_DIR = self.archive_dir
def tearDown(self):
shutil.rmtree(self.staging_dir)
shutil.rmtree(self.repository_dir)
shutil.rmtree(self.archive_dir)
def do_submission(self, name, rev):
# break early in case of missing configuration
@ -163,6 +168,11 @@ class SubmitTestCase(django.test.TestCase):
name = draft.name
rev = "%02d" % (int(draft.rev) + 1)
# write the old draft in a file so we can check it's moved away
old_rev = draft.rev
with open(os.path.join(self.repository_dir, "%s-%s.txt" % (name, old_rev)), 'w') as f:
f.write("a" * 2000)
supply_submitter_url = self.do_submission(name, rev)
# supply submitter info, then we get a confirmation email
@ -202,6 +212,8 @@ class SubmitTestCase(django.test.TestCase):
new_revision = draft.latest_event()
self.assertEquals(new_revision.type, "new_revision")
self.assertEquals(new_revision.by.name, "Test Name")
self.assertTrue(not os.path.exists(os.path.join(self.repository_dir, "%s-%s.txt" % (name, old_rev))))
self.assertTrue(os.path.exists(os.path.join(self.archive_dir, "%s-%s.txt" % (name, old_rev))))
self.assertTrue(not os.path.exists(os.path.join(self.staging_dir, u"%s-%s.txt" % (name, rev))))
self.assertTrue(os.path.exists(os.path.join(self.repository_dir, u"%s-%s.txt" % (name, rev))))
self.assertEquals(draft.type_id, "draft")

View file

@ -100,6 +100,8 @@ def perform_postREDESIGN(request, submission):
draft = Document(name=submission.filename)
draft.intended_std_level = None
prev_rev = draft.rev
draft.type_id = "draft"
draft.time = datetime.datetime.now()
draft.title = submission.id_document_name
@ -144,6 +146,9 @@ def perform_postREDESIGN(request, submission):
e.desc = "New revision available"
e.save()
# clean up old files
from ietf.idrfc.expire import move_draft_files_to_archive
move_draft_files_to_archive(draft, prev_rev)
# automatic state changes
state_change_msg = ""