|
1
2
3
4
|
#-*- coding:utf-8 -*-
import datetime
import os
|
|
5
|
import tarfile
|
|
6
7
8
9
|
from django.core.management.base import BaseCommand
from dictionary.models import Lemma, Frame_Opinion_Value, \
|
|
10
|
get_ready_statuses
|
|
11
|
from dictionary.teixml import createteixml, write_phrase_types_expansions_in_TEI
|
|
12
13
14
|
from settings import WALENTY_PATH
class Command(BaseCommand):
|
|
15
16
|
args = '<dict dict ...>'
help = 'Get Walenty in TEI format.'
|
|
17
18
|
def handle(self, *args, **options):
|
|
19
20
|
try:
now = datetime.datetime.now().strftime('%Y%m%d')
|
|
21
22
23
24
25
26
27
28
|
vocab_names = list(args)
vocab_names.sort()
if vocab_names:
filename_base = '%s_%s_%s' % ('walenty', '+'.join(vocab_names), now)
else:
filename_base = '%s_%s' % ('walenty', now)
|
|
29
30
31
|
base_path = os.path.join(WALENTY_PATH, filename_base)
outpath = base_path + '.xml'
ready_statuses = get_ready_statuses()
|
|
32
33
34
35
36
37
|
lemmas = Lemma.objects.filter(old=False)
if vocab_names:
lemmas = lemmas.filter(vocabulary__name__in=vocab_names)
ready_lemmas = lemmas.filter(status__in=ready_statuses).order_by('entry_obj__name')
|
|
38
39
40
|
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')
|
|
41
42
43
44
45
|
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)
|
|
46
47
|
os.chdir(WALENTY_PATH)
archive.add(os.path.basename(outpath))
|
|
48
|
archive.add(os.path.basename(phrase_types_expand_path))
|
|
49
50
51
|
finally:
archive.close()
os.remove(outpath)
|
|
52
|
os.remove(phrase_types_expand_path)
|