aboutsummaryrefslogtreecommitdiff
path: root/src/hydrilla/proxy/web_ui/items.py
diff options
context:
space:
mode:
authorWojtek Kosior <koszko@koszko.org>2022-09-28 12:48:45 +0200
committerWojtek Kosior <koszko@koszko.org>2022-09-29 12:53:36 +0200
commitffe6e681b281eef2c1e62bbc6feefb0b85d040ca (patch)
tree0aa141073403beae9590135fd047d7a2ebd8fe76 /src/hydrilla/proxy/web_ui/items.py
parent1a1f750ccdc1d52a7b1bd648b2188fa6e7c1a4b8 (diff)
downloadhaketilo-hydrilla-ffe6e681b281eef2c1e62bbc6feefb0b85d040ca.tar.gz
haketilo-hydrilla-ffe6e681b281eef2c1e62bbc6feefb0b85d040ca.zip
[proxy] make it possible to create "ad hoc" packages through the web UI
Diffstat (limited to 'src/hydrilla/proxy/web_ui/items.py')
-rw-r--r--src/hydrilla/proxy/web_ui/items.py47
1 files changed, 1 insertions, 46 deletions
diff --git a/src/hydrilla/proxy/web_ui/items.py b/src/hydrilla/proxy/web_ui/items.py
index 6195107..f34b89b 100644
--- a/src/hydrilla/proxy/web_ui/items.py
+++ b/src/hydrilla/proxy/web_ui/items.py
@@ -1,6 +1,6 @@
# SPDX-License-Identifier: GPL-3.0-or-later
-# Proxy web UI packages loading.
+# Proxy web UI package/library management.
#
# This file is part of Hydrilla&Haketilo.
#
@@ -32,17 +32,11 @@
# Enable using with Python 3.7.
from __future__ import annotations
-import tempfile
-import zipfile
import typing as t
-from pathlib import Path
-
import flask
import werkzeug
-from ...exceptions import HaketiloException
-from ...translations import smart_gettext as _
from ... import item_infos
from .. import state as st
from . import _app
@@ -50,45 +44,6 @@ from . import _app
bp = flask.Blueprint('items', __package__)
-@bp.route('/load_from_disk', methods=['GET'])
-def load_from_disk(errors: t.Mapping[str, bool] = {}) -> werkzeug.Response:
- html = flask.render_template('items/load_from_disk.html.jinja', **errors)
- return flask.make_response(html, 200)
-
-@bp.route('/load_from_disk', methods=['POST'])
-def load_from_disk_post() -> werkzeug.Response:
- zip_file_storage = flask.request.files.get('items_zipfile')
- if zip_file_storage is None:
- return load_from_disk()
-
- with tempfile.TemporaryDirectory() as tmpdir_str:
- tmpdir = Path(tmpdir_str)
- tmpdir_child = tmpdir / 'childdir'
- tmpdir_child.mkdir()
-
- try:
- with zipfile.ZipFile(zip_file_storage) as zip_file:
- zip_file.extractall(tmpdir_child)
- except:
- return load_from_disk({'uploaded_file_not_zip': True})
-
- extracted_top_level_files = tuple(tmpdir_child.iterdir())
- if extracted_top_level_files == ():
- return load_from_disk({'invalid_uploaded_malcontent': True})
-
- if len(extracted_top_level_files) == 1 and \
- extracted_top_level_files[0].is_dir():
- malcontent_dir_path = extracted_top_level_files[0]
- else:
- malcontent_dir_path = tmpdir_child
-
- try:
- _app.get_haketilo_state().import_items(malcontent_dir_path)
- except:
- return load_from_disk({'invalid_uploaded_malcontent': True})
-
- return flask.redirect(flask.url_for('.packages'))
-
@bp.route('/packages')
def packages() -> werkzeug.Response:
store = _app.get_haketilo_state().mapping_store()