runtime/PLCObject.py
branchpython3
changeset 3750 f62625418bff
parent 3642 cd3d15e8ef42
child 3752 9f6f46dbe3ae
equal deleted inserted replaced
3749:fda6c1a37662 3750:f62625418bff
    20 # You should have received a copy of the GNU Lesser General Public
    20 # You should have received a copy of the GNU Lesser General Public
    21 # License along with this library; if not, write to the Free Software
    21 # License along with this library; if not, write to the Free Software
    22 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
    22 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
    23 
    23 
    24 
    24 
    25 from __future__ import absolute_import
    25 
    26 from threading import Thread, Lock, Event, Condition
    26 from threading import Thread, Lock, Event, Condition
    27 import ctypes
    27 import ctypes
    28 import os
    28 import os
    29 import sys
    29 import sys
    30 import traceback
    30 import traceback
   391             filenames = os.listdir(self.workingdir)
   391             filenames = os.listdir(self.workingdir)
   392             filenames.sort()
   392             filenames.sort()
   393             for filename in filenames:
   393             for filename in filenames:
   394                 name, ext = os.path.splitext(filename)
   394                 name, ext = os.path.splitext(filename)
   395                 if name.upper().startswith("RUNTIME") and ext.upper() == ".PY":
   395                 if name.upper().startswith("RUNTIME") and ext.upper() == ".PY":
   396                     execfile(os.path.join(self.workingdir, filename), self.python_runtime_vars)
   396                     exec(compile(open(os.path.join(self.workingdir, filename), "rb").read(), os.path.join(self.workingdir, filename), 'exec'), self.python_runtime_vars)
   397                     for methodname in MethodNames:
   397                     for methodname in MethodNames:
   398                         method = self.python_runtime_vars.get("_%s_%s" % (name, methodname), None)
   398                         method = self.python_runtime_vars.get("_%s_%s" % (name, methodname), None)
   399                         if method is not None:
   399                         if method is not None:
   400                             self.python_runtime_vars["_runtime_%s" % methodname].append(method)
   400                             self.python_runtime_vars["_runtime_%s" % methodname].append(method)
   401         except Exception:
   401         except Exception:
   559         except EOFError:
   559         except EOFError:
   560             return (PlcStatus.Disconnected, None)
   560             return (PlcStatus.Disconnected, None)
   561 
   561 
   562     @RunInMain
   562     @RunInMain
   563     def _GetPLCstatus(self):
   563     def _GetPLCstatus(self):
   564         return self.PLCStatus, map(self.GetLogCount, xrange(LogLevelsCount))
   564         return self.PLCStatus, list(map(self.GetLogCount, range(LogLevelsCount)))
   565 
   565 
   566     @RunInMain
   566     @RunInMain
   567     def GetPLCID(self):
   567     def GetPLCID(self):
   568         return getPSKID(partial(self.LogMessage, 0))
   568         return getPSKID(partial(self.LogMessage, 0))
   569 
   569 
   596         self.blobs[newBlobID] = blob
   596         self.blobs[newBlobID] = blob
   597         return newBlobID
   597         return newBlobID
   598 
   598 
   599     @RunInMain
   599     @RunInMain
   600     def PurgeBlobs(self):
   600     def PurgeBlobs(self):
   601         for fd, _path, _md5sum in self.blobs.values():
   601         for fd, _path, _md5sum in list(self.blobs.values()):
   602             os.close(fd)
   602             os.close(fd)
   603         self._init_blobs()
   603         self._init_blobs()
   604 
   604 
   605     def BlobAsFile(self, blobID, newpath):
   605     def BlobAsFile(self, blobID, newpath):
   606         blob = self.blobs.pop(blobID, None)
   606         blob = self.blobs.pop(blobID, None)