Verified Commit 152d6654 authored by Štěpán Henek's avatar Štěpán Henek 🐻
Browse files

new plugin format addopted

* installs to regular python directory
* uses jinja2 templates
* uses libsass to compile sass files
parent 5674c88d
This diff is collapsed.
__path__ = __import__('pkgutil').extend_path(__path__, __name__)
import os
from foris import fapi, validators
from foris import fapi
from foris.config import ConfigPageMixin, add_config_page
from foris.config_handlers import BaseConfigHandler
from foris.form import Textbox, Checkbox, Number
from foris.plugins import ForisPlugin
from foris.state import current_state
from foris.utils.translators import gettext_dummy as gettext, ugettext as _
from foris.utils.translators import gettext_dummy as gettext
class StoragePluginConfigHandler(BaseConfigHandler):
......@@ -15,7 +14,8 @@ class StoragePluginConfigHandler(BaseConfigHandler):
def get_form(self):
form = fapi.ForisForm("storage", [])
main = form.add_section(name="set_srv", title=_(self.userfriendly_title))
form.add_section(name="set_srv", title=self.userfriendly_title)
def form_cb(data):
msg = {"drive": self.data["new_disk"]}
current_state.backend.perform("storage", "prepare_srv_drive", msg)
......@@ -27,22 +27,25 @@ class StoragePluginConfigHandler(BaseConfigHandler):
class StoragePluginPage(ConfigPageMixin, StoragePluginConfigHandler):
menu_order = 60
template = "storage_plugin/storage_plugin.tpl"
template = "storage_plugin/storage_plugin"
template_type = "jinja2"
userfriendly_title = gettext("Storage")
def render(self, **kwargs):
kwargs['settings'] = current_state.backend.perform("storage", "get_settings")
tmp = current_state.backend.perform("storage", "get_drives")
if not tmp:
tmp = { "drives": []}
kwargs['drives'] = tmp['drives']
kwargs['settings']['old_device_name'] = \
kwargs['settings']["old_device"].replace("/dev/", "")
drives = current_state.backend.perform("storage", "get_drives")["drives"]
kwargs['drives'] = sorted(drives, key=lambda d: d['dev'])
return super(StoragePluginPage, self).render(**kwargs)
class StoragePlugin(ForisPlugin):
PLUGIN_NAME = "storage_plugin"
DIRNAME = os.path.dirname(os.path.abspath(__file__))
PLUGIN_STYLES = [
"css/storage.css",
]
PLUGIN_STATIC_SCRIPTS = [
]
......
# Czech translations for Foris Storage Plugin.
# Copyright (C) 2018 ORGANIZATION
# This file is distributed under the same license as the Foris Storage
# Plugin project.
# FIRST AUTHOR <EMAIL@ADDRESS>, 2018.
#
msgid ""
msgstr ""
"Project-Id-Version: Foris Storage Plugin 1\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2018-06-28 17:16+0200\n"
"PO-Revision-Date: 2018-06-28 17:23+0200\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language: cs\n"
"Language-Team: cs <LL@li.org>\n"
"Plural-Forms: nplurals=3; plural=((n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 2.6.0\n"
msgid "storage"
msgstr ""
msgid "Storage"
msgstr ""
msgid ""
"Here you can setup where your persistent data should be stored. If you "
"want to use Nextcloud, LXC or other IO intensive applications, don't put "
"them on internal flash, but always use external storage. Also make sure "
"that your data will fit on the new drive before switching."
msgstr ""
msgid ""
"Once you choose a drive, it will be formatted to Btrfs filesystem and on "
"next reboot your <em>/srv</em> (directory where all IO intesive "
"applications should reisde) will get moved to this new drive."
msgstr ""
#, python-format
msgid ""
"\n"
" Device currently in use is %(old_device_name)s (%(uuid_text)s).\n"
" "
msgstr ""
msgid "Processing changes at the moment, please wait..."
msgstr ""
msgid "Device"
msgstr ""
msgid "Description"
msgstr ""
msgid "Filesystem"
msgstr ""
msgid "UUID"
msgstr ""
msgid "Changes to this setting will take effect on next reboot!"
msgstr ""
msgid "Format &amp; Set"
msgstr ""
msgid "No drives connected, please connect a drive and refresh the page."
msgstr ""
msgid ""
"Are you sure you want to change where your srv is stored? Newly selected "
"drive will be formated and you will loose all the data on it. Once "
"formating is done, you'll get notification and you will be asked to "
"reboot. On the reboot data will be moved from old drive to the new one. "
"This can take some time so your next reboot will take longer. Are you "
"sure you want to continue?"
msgstr ""
# German translations for Foris Storage Plugin.
# Copyright (C) 2018 ORGANIZATION
# This file is distributed under the same license as the Foris Storage
# Plugin project.
# FIRST AUTHOR <EMAIL@ADDRESS>, 2018.
#
msgid ""
msgstr ""
"Project-Id-Version: Foris Storage Plugin 1\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2018-06-28 17:16+0200\n"
"PO-Revision-Date: 2018-06-28 17:23+0200\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language: de\n"
"Language-Team: de <LL@li.org>\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 2.6.0\n"
msgid "storage"
msgstr ""
msgid "Storage"
msgstr ""
msgid ""
"Here you can setup where your persistent data should be stored. If you "
"want to use Nextcloud, LXC or other IO intensive applications, don't put "
"them on internal flash, but always use external storage. Also make sure "
"that your data will fit on the new drive before switching."
msgstr ""
msgid ""
"Once you choose a drive, it will be formatted to Btrfs filesystem and on "
"next reboot your <em>/srv</em> (directory where all IO intesive "
"applications should reisde) will get moved to this new drive."
msgstr ""
#, python-format
msgid ""
"\n"
" Device currently in use is %(old_device_name)s (%(uuid_text)s).\n"
" "
msgstr ""
msgid "Processing changes at the moment, please wait..."
msgstr ""
msgid "Device"
msgstr ""
msgid "Description"
msgstr ""
msgid "Filesystem"
msgstr ""
msgid "UUID"
msgstr ""
msgid "Changes to this setting will take effect on next reboot!"
msgstr ""
msgid "Format &amp; Set"
msgstr ""
msgid "No drives connected, please connect a drive and refresh the page."
msgstr ""
msgid ""
"Are you sure you want to change where your srv is stored? Newly selected "
"drive will be formated and you will loose all the data on it. Once "
"formating is done, you'll get notification and you will be asked to "
"reboot. On the reboot data will be moved from old drive to the new one. "
"This can take some time so your next reboot will take longer. Are you "
"sure you want to continue?"
msgstr ""
# Translations template for Foris Storage Plugin.
# Copyright (C) 2018 ORGANIZATION
# This file is distributed under the same license as the Foris Storage
# Plugin project.
# FIRST AUTHOR <EMAIL@ADDRESS>, 2018.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: Foris Storage Plugin 1\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2018-06-28 17:16+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Generated-By: Babel 2.6.0\n"
msgid "storage"
msgstr ""
msgid "Storage"
msgstr ""
msgid ""
"Here you can setup where your persistent data should be stored. If you "
"want to use Nextcloud, LXC or other IO intensive applications, don't put "
"them on internal flash, but always use external storage. Also make sure "
"that your data will fit on the new drive before switching."
msgstr ""
msgid ""
"Once you choose a drive, it will be formatted to Btrfs filesystem and on "
"next reboot your <em>/srv</em> (directory where all IO intesive "
"applications should reisde) will get moved to this new drive."
msgstr ""
#, python-format
msgid ""
"\n"
" Device currently in use is %(old_device_name)s (%(uuid_text)s).\n"
" "
msgstr ""
msgid "Processing changes at the moment, please wait..."
msgstr ""
msgid "Device"
msgstr ""
msgid "Description"
msgstr ""
msgid "Filesystem"
msgstr ""
msgid "UUID"
msgstr ""
msgid "Changes to this setting will take effect on next reboot!"
msgstr ""
msgid "Format &amp; Set"
msgstr ""
msgid "No drives connected, please connect a drive and refresh the page."
msgstr ""
msgid ""
"Are you sure you want to change where your srv is stored? Newly selected "
"drive will be formated and you will loose all the data on it. Once "
"formating is done, you'll get notification and you will be asked to "
"reboot. On the reboot data will be moved from old drive to the new one. "
"This can take some time so your next reboot will take longer. Are you "
"sure you want to continue?"
msgstr ""
td, th
padding: 5px
th
font-weight: bold
tbody tr:hover
background-color: #f2f2f2
{% extends 'config/base.html.j2' %}
%rebase("config/base.tpl", **locals())
<style>
td,th {
padding: 5px;
}
th {
font-weight: bold;
}
tbody tr:hover {
background-color: #f2f2f2;
}
</style>
{% block config_base %}
<div id="page-sample-plugin" class="config-page">
%include("_messages.tpl")
{% include '_messages.html.j2' %}
<form action="{{ request.fullpath }}" id="storage-form" method="post" class="config-form">
<p>
{{ trans("Here you can setup where your persistent data should be stored. If you want to use Nextcloud, LXC or other IO intensive applications, don't put them on internal flash, but always use external storage. Also make sure that your data will fit on the new drive before switching.") }}
{% trans %}Here you can setup where your persistent data should be stored. If you want to use Nextcloud, LXC or other IO intensive applications, don't put them on internal flash, but always use external storage. Also make sure that your data will fit on the new drive before switching.{% endtrans %}
</p>
<p>
{{! trans("Once you choose a drive, it will be formatted to Btrfs filesystem and on next reboot your <em>/srv</em> (directory where all IO intesive applications should reisde) will get moved to this new drive.") }}
</p>
{% trans %}Once you choose a drive, it will be formatted to Btrfs filesystem and on next reboot your <em>/srv</em> (directory where all IO intesive applications should reisde) will get moved to this new drive.{% endtrans %}
</p>
<span id="test-results">
<p class="{{! settings['old_uuid'] == 'rootfs' and 'result test-fail' or 'result test-success' }}">
{{ trans("Device currently in use is {} ({}).").format(settings['old_device'].replace("/dev/",""), settings['old_uuid'] == 'rootfs' and 'internal flash' or 'uuid: {}'.format(settings['old_uuid'])) }}
{% if settings['old_uuid'] == 'rootfs' %}
<p class="result test-fail">
{% trans old_device_name=settings["old_device_name"], uuid_text='rootfs' %}
Device currently in use is {{ old_device_name }} ({{ uuid_text }}).
{% endtrans %}
</p>
{% else %}
<p class="result test-success">
{% trans old_device_name=settings["old_device_name"], uuid_text='uuid: ' + settings['old_uuid'] %}
Device currently in use is {{ old_device_name }} ({{ uuid_text }}).
{% endtrans %}
</p>
{% endif %}
</span>
%if settings['formating']:
{% if settings['formating'] %}
<p>
{{ trans("Processing changes at the moment, please wait...") }}
{% trans %}Processing changes at the moment, please wait...{% endtrans %}
</p>
%end
%if drives:
{% endif %}
{% if drives %}
<input type="hidden" name="csrf_token" value="{{ get_csrf_token() }}">
<input type="hidden" name="uuid" value="{{ settings['uuid'] }}">
<input type="hidden" name="old_uuid" value="{{ settings['old_uuid'] }}">
<input type="hidden" name="old_device" value="{{ settings['old_device'] }}">
<table>
<thead>
<tr><th></th><th>{{ trans("Device") }}</th><th>{{ trans("Description") }}</th><th>{{ trans("Filesystem") }}</th><th>{{ trans("UUID") }}</th></tr>
<tr><th></th><th>{% trans %}Device{% endtrans %}</th><th>{% trans %}Description{% endtrans %}</th><th>{% trans %}Filesystem{% endtrans %}</th><th>{% trans %}UUID{% endtrans %}</th></tr>
</thead>
<tbody>
%for drv in sorted(drives, key=lambda d: d['dev']):
%if "/dev/{}".format(drv['dev']) == settings['old_device']:
{% for drv in drives %}
{% if "/dev/" + drv['dev'] == settings['old_device'] %}
<tr class="button" style="display: table-row; height: 1em; line-height: 1em;">
%else:
<tr onClick='$("input[name=new_disk]").val(["{{ drv['dev'] }}"]).change();'>
%end
{% else %}
<tr onClick='$("input[name=new_disk]").val(["{{ drv['dev'] }}"]).change();'>
{% endif %}
<td>
<input type="radio" name="new_disk" value="{{ drv['dev'] }}"/>
</td>
......@@ -58,17 +55,17 @@ tbody tr:hover {
<td>{{ drv['fs'] }}</td>
<td>{{ drv['uuid'] }}</td>
</tr>
%end
{% endfor %}
</tbody>
</table>
<br />
<p>
{{ trans("Changes to this setting will take effect on next reboot!") }}
{% trans %}Changes to this setting will take effect on next reboot!{% endtrans %}
</p>
<button type="submit" name="send" class="button">{{ trans("Format & Set") }}</button>
%else:
<p>{{ trans("No drives connected, please connect a drive and refresh the page.") }}</p>
%end
<button type="submit" name="send" class="button">{% trans %}Format &amp; Set{% endtrans %}</button>
{% else %}
<p>{% trans %}No drives connected, please connect a drive and refresh the page.{% endtrans %}</p>
{% endif %}
</form>
</div>
......@@ -76,20 +73,21 @@ tbody tr:hover {
<script>
$(document).ready(function() {
$("[name=new_disk]").val(["{{ settings['old_device'].replace("/dev/","") }}"]);
%for drv in drives:
%if 'uuid' in drv and drv['uuid'] == settings['uuid'] and settings['uuid']:
{% for drv in drives %}
{% if 'uuid' in drv and drv['uuid'] == settings['uuid'] and settings['uuid'] %}
$("[name=new_disk]").val(["{{ drv['dev'] }}"]);
%end
%end
{% endif %}
{% endfor %}
$("[name=send]").prop('disabled', true);
$("[name=new_disk]").change(function() { $("[name=send]").prop('disabled', false); });
%if settings['formating']:
{%if settings['formating'] %}
$("[name=new_disk]").prop('disabled', true);
setInterval(function() { location.reload(); }, 10000);
%end
{% endif %}
$('#storage-form').submit(function() {
var c = confirm("{{! trans("Are you sure you want to change where your srv is stored? Newly selected drive will be formated and you will loose all the data on it. Once formating is done, you'll get notification and you will be asked to reboot. On the reboot data will be moved from old drive to the new one. This can take some time so your next reboot will take longer. Are you sure you want to continue?") }}");
var c = confirm("{% trans %}Are you sure you want to change where your srv is stored? Newly selected drive will be formated and you will loose all the data on it. Once formating is done, you'll get notification and you will be asked to reboot. On the reboot data will be moved from old drive to the new one. This can take some time so your next reboot will take longer. Are you sure you want to continue?{% endtrans %}");
return c;
});
});
</script>
{% endblock %}
#!/usr/bin/env python
import copy
from setuptools import setup
from setuptools.command.build_py import build_py
class BuildCmd(build_py):
def run(self):
# build foris plugin files
from foris_plugins_distutils import build
cmd = build(copy.copy(self.distribution))
cmd.ensure_finalized()
cmd.run()
# build package
build_py.run(self)
setup(
name="Foris Storage Plugin",
version="1",
description="Storage plugin for foris web interfce",
author="CZ.NIC, z. s. p. o.",
author_email="stepan.henek@nic.cz",
url="https://gitlab.labs.nic.cz/turris/foris-storage-plugin/",
license="GPL-3.0",
requires=[
"foris",
],
setup_requires=[
'babel',
'jinja2',
'libsass',
'foris_plugins_distutils',
],
provides=[
"foris_plugins.storage",
],
packages=[
"foris_plugins.storage",
],
package_data={
'': [
"templates/**",
"templates/**/*",
"templates/javascript/**",
"templates/javascript/**/*",
"locale/**/LC_MESSAGES/*.mo",
"static/css/*.css",
"static/fonts/*",
"static/img/*",
"static/js/*.js",
"static/js/contrib/*",
],
},
cmdclass={
"build_py": BuildCmd, # modify build_py to build the foris files as well
}
)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment