create_TEI_walenty.py
1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#-*- coding:utf-8 -*-
import datetime
import os
import tarfile
from django.core.management.base import BaseCommand
from dictionary.models import Lemma, Frame_Opinion_Value, \
get_ready_statuses
from dictionary.teixml import createteixml, write_phrase_types_expansions_in_TEI
from settings import WALENTY_PATH
class Command(BaseCommand):
args = 'none'
def handle(self, *args, **options):
try:
now = datetime.datetime.now().strftime('%Y%m%d')
filename_base = '%s_%s' % ('walenty', now)
base_path = os.path.join(WALENTY_PATH, filename_base)
outpath = base_path + '.xml'
ready_statuses = get_ready_statuses()
lemmas = Lemma.objects.filter(old=False).order_by('entry_obj__name')
ready_lemmas = lemmas.filter(status__in=ready_statuses)
frame_opinion_values = Frame_Opinion_Value.objects.all()
createteixml(outpath, ready_lemmas, frame_opinion_values)
archive = tarfile.open(base_path + '-TEI.tar.gz', 'w:gz')
phrase_types_expand_path = os.path.join(WALENTY_PATH,
'%s_%s.xml' % ('phrase_types_expand', now))
write_phrase_types_expansions_in_TEI(phrase_types_expand_path)
os.chdir(WALENTY_PATH)
archive.add(os.path.basename(outpath))
archive.add(os.path.basename(phrase_types_expand_path))
finally:
archive.close()
os.remove(outpath)
os.remove(phrase_types_expand_path)