runtime/NevowServer.py
changeset 3703 4b75f1506ea1
parent 3440 3770ded5db5c
child 3750 f62625418bff
child 3855 beccb995b10e
equal deleted inserted replaced
3702:6dc619fa28aa 3703:4b75f1506ea1
    25 
    25 
    26 from __future__ import absolute_import
    26 from __future__ import absolute_import
    27 from __future__ import print_function
    27 from __future__ import print_function
    28 import os
    28 import os
    29 import collections
    29 import collections
       
    30 import shutil
    30 import platform as platform_module
    31 import platform as platform_module
    31 from zope.interface import implements
    32 from zope.interface import implements
    32 from nevow import appserver, inevow, tags, loaders, athena, url, rend
    33 from nevow import appserver, inevow, tags, loaders, athena, url, rend
    33 from nevow.page import renderer
    34 from nevow.page import renderer
    34 from nevow.static import File
    35 from nevow.static import File
   227 
   228 
   228     restartOrRepairPLC = annotate.autocallable(restartOrRepairPLC,
   229     restartOrRepairPLC = annotate.autocallable(restartOrRepairPLC,
   229                                            label=_(
   230                                            label=_(
   230                                                "Restart or Repair"),
   231                                                "Restart or Repair"),
   231                                            action=_("Do"))
   232                                            action=_("Do"))
       
   233 
       
   234     # pylint: disable=no-self-argument
       
   235     def uploadFile(
       
   236             ctx=annotate.Context(),
       
   237             uploadedfile=annotate.FileUpload(required=True,
       
   238                                   label=_("File to upload"))):
       
   239         pass
       
   240 
       
   241     uploadFile = annotate.autocallable(uploadFile,
       
   242                                            label=_(
       
   243                                                "Upload a file to PLC working directory"),
       
   244                                            action=_("Upload"))
   232 
   245 
   233 customSettingsURLs = {
   246 customSettingsURLs = {
   234 }
   247 }
   235 
   248 
   236 extensions_settings_od = collections.OrderedDict()
   249 extensions_settings_od = collections.OrderedDict()
   302     def restartOrRepairPLC(self, action, **kwargs):
   315     def restartOrRepairPLC(self, action, **kwargs):
   303         if(action == "Repair"):
   316         if(action == "Repair"):
   304             GetPLCObjectSingleton().RepairPLC()
   317             GetPLCObjectSingleton().RepairPLC()
   305         else:
   318         else:
   306             MainWorker.quit()
   319             MainWorker.quit()
   307             
   320 
   308         
   321     def uploadFile(self, uploadedfile, **kwargs):
       
   322         if uploadedfile is not None:
       
   323             fobj = getattr(uploadedfile, "file", None)
       
   324         if fobj is not None:
       
   325             with open(uploadedfile.filename, 'w') as destfd:
       
   326                 fobj.seek(0)
       
   327                 shutil.copyfileobj(fobj,destfd)
   309 
   328 
   310     def locateChild(self, ctx, segments):
   329     def locateChild(self, ctx, segments):
   311         if segments[0] in customSettingsURLs:
   330         if segments[0] in customSettingsURLs:
   312             return customSettingsURLs[segments[0]](ctx, segments)
   331             return customSettingsURLs[segments[0]](ctx, segments)
   313         return super(SettingsPage, self).locateChild(ctx, segments)
   332         return super(SettingsPage, self).locateChild(ctx, segments)