From ffe6e681b281eef2c1e62bbc6feefb0b85d040ca Mon Sep 17 00:00:00 2001 From: Wojtek Kosior Date: Wed, 28 Sep 2022 12:48:45 +0200 Subject: [proxy] make it possible to create "ad hoc" packages through the web UI --- src/hydrilla/proxy/web_ui/items.py | 47 +------------------------------------- 1 file changed, 1 insertion(+), 46 deletions(-) (limited to 'src/hydrilla/proxy/web_ui/items.py') 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() -- cgit v1.2.3