mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2025-06-26 16:00:34 +00:00
Add back corpus export.
This commit is contained in:
@ -24,27 +24,21 @@ corpus_analysis_sessions = {}
|
||||
corpus_analysis_clients = {}
|
||||
|
||||
|
||||
@socketio.on('corpus_create_zip')
|
||||
@socketio.on('export_corpus')
|
||||
@socketio_login_required
|
||||
def corpus_create_zip(corpus_id):
|
||||
def export_corpus(corpus_id):
|
||||
# TODO: This should not be get_or_404 here - Socket.IO != HTTP request
|
||||
corpus = Corpus.query.get_or_404(corpus_id)
|
||||
# delete old corpus archive if it exists/has been build before
|
||||
if corpus.archive_file is not None:
|
||||
if (os.path.isfile(corpus.archive_file)):
|
||||
os.remove(corpus.archive_file)
|
||||
root_dir = os.path.join(current_app.config['DATA_DIR'],
|
||||
str(current_user.id),
|
||||
'corpora')
|
||||
base_dir = os.path.join(root_dir, str(corpus.id))
|
||||
if corpus.archive_file is not None and os.path.isfile(corpus.archive_file):
|
||||
os.remove(corpus.archive_file)
|
||||
zip_name = corpus.title
|
||||
zip_path = os.path.join(root_dir, zip_name)
|
||||
corpus.archive_file = os.path.join(base_dir, zip_name) + '.zip'
|
||||
zip_path = os.path.join(current_user.path, 'corpora', zip_name)
|
||||
corpus.archive_file = os.path.join(corpus.path, zip_name) + '.zip'
|
||||
db.session.commit()
|
||||
shutil.make_archive(zip_path,
|
||||
'zip',
|
||||
base_dir)
|
||||
shutil.make_archive(zip_path, 'zip', corpus.path)
|
||||
shutil.move(zip_path + '.zip', corpus.archive_file)
|
||||
socketio.emit('corpus_zip_created', room=request.sid)
|
||||
socketio.emit('export_corpus_' + str(corpus.id), room=request.sid)
|
||||
|
||||
|
||||
@socketio.on('corpus_analysis_init')
|
||||
|
@ -123,9 +123,9 @@ def corpus(corpus_id):
|
||||
corpus_files=corpus_files, title='Corpus')
|
||||
|
||||
|
||||
@corpora.route('/<int:corpus_id>/export')
|
||||
@corpora.route('/<int:corpus_id>/download')
|
||||
@login_required
|
||||
def export_corpus(corpus_id):
|
||||
def download_corpus(corpus_id):
|
||||
corpus = Corpus.query.get_or_404(corpus_id)
|
||||
if not (corpus.creator == current_user or current_user.is_administrator()):
|
||||
abort(403)
|
||||
|
Reference in New Issue
Block a user