# HG changeset patch # User Edouard Tisserant # Date 1669715993 -3600 # Node ID 4b75f1506ea1066b025c4f74cd341e89cbf6c8e7 # Parent 6dc619fa28aaba3ddca0a0d903937f658caf7878 Runtime: add arbitrary file upload to working dir in web interface diff -r 6dc619fa28aa -r 4b75f1506ea1 runtime/NevowServer.py --- a/runtime/NevowServer.py Fri Nov 25 11:12:14 2022 +0100 +++ b/runtime/NevowServer.py Tue Nov 29 10:59:53 2022 +0100 @@ -27,6 +27,7 @@ from __future__ import print_function import os import collections +import shutil import platform as platform_module from zope.interface import implements from nevow import appserver, inevow, tags, loaders, athena, url, rend @@ -230,6 +231,18 @@ "Restart or Repair"), action=_("Do")) + # pylint: disable=no-self-argument + def uploadFile( + ctx=annotate.Context(), + uploadedfile=annotate.FileUpload(required=True, + label=_("File to upload"))): + pass + + uploadFile = annotate.autocallable(uploadFile, + label=_( + "Upload a file to PLC working directory"), + action=_("Upload")) + customSettingsURLs = { } @@ -304,8 +317,14 @@ GetPLCObjectSingleton().RepairPLC() else: MainWorker.quit() - - + + def uploadFile(self, uploadedfile, **kwargs): + if uploadedfile is not None: + fobj = getattr(uploadedfile, "file", None) + if fobj is not None: + with open(uploadedfile.filename, 'w') as destfd: + fobj.seek(0) + shutil.copyfileobj(fobj,destfd) def locateChild(self, ctx, segments): if segments[0] in customSettingsURLs: