customize chroot dir for external storage
This commit is contained in:
parent
f52b378611
commit
06c186b970
16
.env.dist
16
.env.dist
@ -1,6 +1,16 @@
|
||||
DEMO=false
|
||||
# Core
|
||||
DEBUG=false
|
||||
PORT=5000
|
||||
PORT_HTTP_EXTERNAL_STORAGE=5001
|
||||
SECRET_KEY=ANY_SECRET_KEY_HERE
|
||||
|
||||
# Application Server
|
||||
PORT=5000
|
||||
BIND=0.0.0.0
|
||||
|
||||
|
||||
# HTTP External Storage Server
|
||||
PORT_HTTP_EXTERNAL_STORAGE=5001
|
||||
BIND_HTTP_EXTERNAL_STORAGE=localhost
|
||||
CHROOT_HTTP_EXTERNAL_STORAGE=%application_dir%/var/run/storage
|
||||
|
||||
# Misc
|
||||
DEMO=false
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -87,6 +87,19 @@ form {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
|
||||
&.vertical {
|
||||
flex-direction: column;
|
||||
|
||||
select,
|
||||
input {
|
||||
align-self: stretch;
|
||||
|
||||
&:first-child {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.btn {
|
||||
margin-left: 10px;
|
||||
}
|
||||
@ -158,6 +171,7 @@ form {
|
||||
background: $gscale0;
|
||||
border-radius: $baseRadius;
|
||||
padding-left: 10px;
|
||||
padding-right: 10px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -285,7 +285,7 @@
|
||||
"enum_application_language_italian": "Italian",
|
||||
"enum_application_language_spanish": "Spanish",
|
||||
"enum_content_type_external_storage": "External Storage",
|
||||
"enum_content_type_external_storage_object_label": "Specify an existing directory path with displayable files within your removeable device",
|
||||
"enum_content_type_external_storage_object_label": "Specify an existing directory relative to the following path",
|
||||
"enum_content_type_external_storage_flashdrive_label": "Path relative to a removeable device",
|
||||
"enum_content_type_url": "URL",
|
||||
"enum_content_type_video": "Video",
|
||||
|
||||
@ -286,7 +286,7 @@
|
||||
"enum_application_language_italian": "Italiano",
|
||||
"enum_application_language_spanish": "Español",
|
||||
"enum_content_type_external_storage": "Almacenamiento externo",
|
||||
"enum_content_type_external_storage_object_label": "Especifique una ruta de directorio existente con archivos visualizables dentro de su dispositivo extraíble",
|
||||
"enum_content_type_external_storage_object_label": "Especifique un directorio existente relativo a la siguiente ruta",
|
||||
"enum_content_type_external_storage_flashdrive_label": "Ruta relativa a un dispositivo extraíble",
|
||||
"enum_content_type_url": "URL",
|
||||
"enum_content_type_video": "Video",
|
||||
|
||||
@ -287,7 +287,7 @@
|
||||
"enum_application_language_italian": "Italien",
|
||||
"enum_application_language_spanish": "Espagnol",
|
||||
"enum_content_type_external_storage": "Stockage externe",
|
||||
"enum_content_type_external_storage_object_label": "Spécifiez un chemin de répertoire existant avec des fichiers affichables dans votre périphérique amovible",
|
||||
"enum_content_type_external_storage_object_label": "Spécifiez un répertoire existant par rapport au chemin suivant",
|
||||
"enum_content_type_external_storage_flashdrive_label": "Chemin relatif à un périphérique amovible",
|
||||
"enum_content_type_url": "URL",
|
||||
"enum_content_type_video": "Vidéo",
|
||||
|
||||
@ -286,7 +286,7 @@
|
||||
"enum_application_language_italian": "Italiano",
|
||||
"enum_application_language_spanish": "Spagnolo",
|
||||
"enum_content_type_external_storage": "Archiviazione esterna",
|
||||
"enum_content_type_external_storage_object_label": "Specifica un percorso di directory esistente con file visualizzabili all'interno del tuo dispositivo rimovibile",
|
||||
"enum_content_type_external_storage_object_label": "Specificare una directory esistente relativi al seguente percorso",
|
||||
"enum_content_type_external_storage_flashdrive_label": "Percorso relativo ad un dispositivo rimovibile",
|
||||
"enum_content_type_url": "URL",
|
||||
"enum_content_type_video": "Video",
|
||||
|
||||
@ -4,5 +4,5 @@ import os
|
||||
from src.Application import Application
|
||||
|
||||
if __name__ == '__main__':
|
||||
app = Application(project_dir=os.path.dirname(__file__))
|
||||
app = Application(application_dir=os.path.dirname(__file__))
|
||||
app.start()
|
||||
|
||||
@ -13,8 +13,8 @@ from src.model.enum.HookType import HookType
|
||||
|
||||
class Application:
|
||||
|
||||
def __init__(self, project_dir: str):
|
||||
self._project_dir = project_dir
|
||||
def __init__(self, application_dir: str):
|
||||
self._application_dir = application_dir
|
||||
self._stop_event = threading.Event()
|
||||
self._model_store = ModelStore(self.get_plugins)
|
||||
self._template_renderer = TemplateRenderer(kernel=self, model_store=self._model_store, render_hook=self.render_hook)
|
||||
@ -40,8 +40,8 @@ class Application:
|
||||
self._stop_event.set()
|
||||
sys.exit(0)
|
||||
|
||||
def get_project_dir(self) -> str:
|
||||
return self._project_dir
|
||||
def get_application_dir(self) -> str:
|
||||
return self._application_dir
|
||||
|
||||
def render_hook(self, hook: HookType) -> str:
|
||||
return self._template_renderer.render_hooks(self._plugin_store.map_hooks()[hook])
|
||||
|
||||
@ -59,7 +59,8 @@ class ContentController(ObController):
|
||||
working_folder=working_folder,
|
||||
working_folder_children=self._model_store.folder().get_children(folder=working_folder, entity=FolderEntity.CONTENT, sort='created_at', ascending=False),
|
||||
enum_content_type=ContentType,
|
||||
enum_folder_entity=FolderEntity
|
||||
enum_folder_entity=FolderEntity,
|
||||
chroot_http_external_storage=self.get_external_storage_server().get_directory(),
|
||||
)
|
||||
|
||||
def slideshow_content_add(self):
|
||||
@ -118,6 +119,7 @@ class ContentController(ObController):
|
||||
working_folder_path=working_folder_path,
|
||||
working_folder=working_folder,
|
||||
enum_content_type=ContentType,
|
||||
chroot_http_external_storage=self.get_external_storage_server().get_directory(),
|
||||
)
|
||||
|
||||
def slideshow_content_save(self, content_id: int = 0):
|
||||
|
||||
@ -84,12 +84,12 @@ class ObPlugin(abc.ABC):
|
||||
def _init_rendering_env(self) -> Environment:
|
||||
alias_paths = {
|
||||
"::": "{}/".format(WebDirConstant.FOLDER_TEMPLATES),
|
||||
"@": "{}/{}/".format(self._plugin_dir.replace(self._kernel.get_project_dir(), ''), WebDirConstant.FOLDER_TEMPLATES)
|
||||
"@": "{}/{}/".format(self._plugin_dir.replace(self._kernel.get_application_dir(), ''), WebDirConstant.FOLDER_TEMPLATES)
|
||||
}
|
||||
|
||||
env = Environment(
|
||||
loader=AliasFileSystemLoader(
|
||||
searchpath=self._kernel.get_project_dir(),
|
||||
searchpath=self._kernel.get_application_dir(),
|
||||
alias_paths=alias_paths
|
||||
),
|
||||
autoescape=select_autoescape(['html', 'xml'])
|
||||
|
||||
@ -16,7 +16,8 @@ class ConfigManager:
|
||||
'version': None,
|
||||
'demo': False,
|
||||
'port_http_external_storage': None,
|
||||
'bind_http_external_storage': '0.0.0.0',
|
||||
'bind_http_external_storage': 'localhost',
|
||||
'chroot_http_external_storage': '%application_dir%/var/run/storage',
|
||||
'port': self.DEFAULT_PORT,
|
||||
'bind': '0.0.0.0',
|
||||
'debug': False,
|
||||
@ -48,8 +49,9 @@ class ConfigManager:
|
||||
parser.add_argument('--log-level', '-ll', default=self._CONFIG['log_level'], help='Log Level')
|
||||
parser.add_argument('--log-stdout', '-ls', default=self._CONFIG['log_stdout'], action='store_true', help='Log to standard output')
|
||||
parser.add_argument('--demo', '-o', default=self._CONFIG['demo'], help='Demo mode to showcase obscreen in a sandbox')
|
||||
parser.add_argument('--port-http-external-storage', '-bx', default=self._CONFIG['port_http_external_storage'], help='Port of http server serving external storage directory')
|
||||
parser.add_argument('--bind-http-external-storage', '-px', default=self._CONFIG['bind_http_external_storage'], help='Bind address of http server serving external storage directory')
|
||||
parser.add_argument('--port-http-external-storage', '-bx', default=self._CONFIG['port_http_external_storage'], help='Port of http server serving external storage')
|
||||
parser.add_argument('--bind-http-external-storage', '-px', default=self._CONFIG['bind_http_external_storage'], help='Bind address of http server serving external storage')
|
||||
parser.add_argument('--chroot-http-external-storage', '-cx', default=self._CONFIG['chroot_http_external_storage'], help='Chroot directory of http server serving external storage')
|
||||
parser.add_argument('--version', '-v', default=None, action='store_true', help='Get version number')
|
||||
|
||||
return parser.parse_args()
|
||||
@ -69,6 +71,8 @@ class ConfigManager:
|
||||
self._CONFIG['port_http_external_storage'] = args.port_http_external_storage
|
||||
if args.bind_http_external_storage:
|
||||
self._CONFIG['bind_http_external_storage'] = args.bind_http_external_storage
|
||||
if args.chroot_http_external_storage:
|
||||
self._CONFIG['chroot_http_external_storage'] = args.chroot_http_external_storage
|
||||
if args.log_file:
|
||||
self._CONFIG['log_file'] = args.log_file
|
||||
if args.secret_key:
|
||||
|
||||
@ -19,14 +19,14 @@ from src.model.entity.ExternalStorage import ExternalStorage
|
||||
|
||||
class ExternalStorageServer:
|
||||
|
||||
MOUNTPOINT = Path("var/run/storage")
|
||||
|
||||
def __init__(self, kernel, model_store: ModelStore):
|
||||
self._kernel = kernel
|
||||
self._model_store = model_store
|
||||
|
||||
def get_directory(self):
|
||||
return Path(self._kernel.get_project_dir(), self.MOUNTPOINT)
|
||||
return self._model_store.config().map().get('chroot_http_external_storage').replace(
|
||||
'%application_dir%', self._kernel.get_application_dir()
|
||||
)
|
||||
|
||||
def get_port(self) -> Optional[int]:
|
||||
port = self._model_store.config().map().get('port_http_external_storage')
|
||||
@ -53,7 +53,7 @@ class ExternalStorageServer:
|
||||
allow_reuse_address = True
|
||||
|
||||
with ReusableTCPServer((bind, port), Handler) as httpd:
|
||||
logging.info("Serving external storage on dir://{}:{}".format(directory, port))
|
||||
logging.info("Serving external storage on path>{}:{}".format(directory, port))
|
||||
httpd.serve_forever()
|
||||
|
||||
@staticmethod
|
||||
|
||||
@ -54,7 +54,7 @@ class PluginStore:
|
||||
|
||||
def find_plugins_in_directory(self, directory: str) -> list:
|
||||
plugins = []
|
||||
for root, dirs, files in os.walk('{}/{}'.format(self._kernel.get_project_dir(), directory)):
|
||||
for root, dirs, files in os.walk('{}/{}'.format(self._kernel.get_application_dir(), directory)):
|
||||
for file in files:
|
||||
if file.endswith(".py"):
|
||||
module_name = file[:-3]
|
||||
|
||||
@ -54,13 +54,13 @@ class WebServer:
|
||||
return self._app
|
||||
|
||||
def get_template_folder(self) -> str:
|
||||
return "{}/{}".format(self._kernel.get_project_dir(), WebDirConstant.FOLDER_TEMPLATES)
|
||||
return "{}/{}".format(self._kernel.get_application_dir(), WebDirConstant.FOLDER_TEMPLATES)
|
||||
|
||||
def get_static_folder(self) -> str:
|
||||
return "{}/{}".format(self._kernel.get_project_dir(), WebDirConstant.FOLDER_STATIC)
|
||||
return "{}/{}".format(self._kernel.get_application_dir(), WebDirConstant.FOLDER_STATIC)
|
||||
|
||||
def get_web_folder(self) -> str:
|
||||
return "{}/{}/{}".format(self._kernel.get_project_dir(), WebDirConstant.FOLDER_STATIC, WebDirConstant.FOLDER_STATIC_WEB_ASSETS)
|
||||
return "{}/{}/{}".format(self._kernel.get_application_dir(), WebDirConstant.FOLDER_STATIC, WebDirConstant.FOLDER_STATIC_WEB_ASSETS)
|
||||
|
||||
def _setup_flask_app(self) -> None:
|
||||
self._app = Flask(
|
||||
|
||||
@ -69,8 +69,15 @@
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="content-edit-location">{{ l.slideshow_content_form_label_location }}</label>
|
||||
<div class="widget">
|
||||
<label for="content-edit-location">
|
||||
{% if content.type == enum_content_type.EXTERNAL_STORAGE %}
|
||||
{{ l.enum_content_type_external_storage_object_label }}
|
||||
{% else %}
|
||||
{{ l.slideshow_content_form_label_location }}
|
||||
{% endif %}
|
||||
</label>
|
||||
<div class="widget vertical">
|
||||
<input type="text" class="disabled" disabled value="{{ chroot_http_external_storage }}/" />
|
||||
{% set location = content.location %}
|
||||
{% if content.type == enum_content_type.YOUTUBE %}
|
||||
{% set location = 'https://www.youtube.com/watch?v=' ~ content.location %}
|
||||
|
||||
@ -56,7 +56,8 @@
|
||||
<div class="from-group-condition hidden">
|
||||
<div class="form-group">
|
||||
<label for="" class="object-label"></label>
|
||||
<div class="widget">
|
||||
<div class="widget vertical">
|
||||
<input type="text" class="disabled" value="{{ chroot_http_external_storage }}/" />
|
||||
<input type="text" name="object" data-input-type="storage" class="content-object-input" disabled="disabled" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -72,7 +72,7 @@
|
||||
placeholder="{{ l.slideshow_slide_form_widget_cron_scheduled_placeholder }}"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="form-group form-group-horizontal slide-auto-duration-group">
|
||||
<label for="">{{ l.slideshow_slide_form_label_auto_duration }}</label>
|
||||
<div class="widget">
|
||||
|
||||
Loading…
Reference in New Issue
Block a user