lpcmanager

Parents 334fec6af85a
Children d1c8a008e121
Many small fixes. Mostly typos and forgotten things while splitting LPCManager.py. Reached a point where LPCManager starts again when launched from batch script. Matches with beremiz changeset 7e6b03251bfe.
--- a/LPCBeremiz.py Mon Feb 12 14:44:43 2018 +0100
+++ b/LPCBeremiz.py Tue Feb 13 14:03:25 2018 +0100
@@ -1,5 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
+from __future__ import absolute_import
import wx
from BeremizIDE import *
from VariableExporter import VariableWriter
--- a/LPCBus.py Mon Feb 12 14:44:43 2018 +0100
+++ b/LPCBus.py Tue Feb 13 14:03:25 2018 +0100
@@ -1,3 +1,4 @@
+from __future__ import absolute_import
import os
modpath = os.path.split(__file__)[0]
@@ -5,11 +6,9 @@
from LPCArch import GetLPCArch, PLC_module
arch = GetLPCArch()
if arch in PLC_module:
- LPCarch = "MC9"
- arch = arch
+ bus_template_name = "MC9"
else:
- LPCarch = arch
- arch = arch
+ bus_template_name = arch
def GetLocalCode(fname):
@@ -287,7 +286,7 @@
if var["Publish"] != "":
code_str["publish_code"] += " " + var["Publish"] % ("*" + var["location"]) + "\n"
- BusName = LPCarch + ":" + self.BaseParams.getName()
+ BusName = bus_template_name + ":" + self.BaseParams.getName()
def bcode(section):
@@ -305,12 +304,12 @@
"bus_publish_code": bcode("publish"),
})
- if LPCarch not in bus_template_code:
+ if bus_template_name not in bus_template_code:
raise Exception, "Unknown arch %s. Please use %s"%(
- LPCarch,repr(bus_template_code.keys()))
+ bus_template_name,repr(bus_template_code.keys()))
Gen_Module_path = os.path.join(buildpath, "Bus_%s.c"%location_str)
module = open(Gen_Module_path,'w')
- module.write(bus_template_code[LPCarch] % code_str)
+ module.write(bus_template_code[bus_template_name] % code_str)
module.close()
matiec_flags = '"-I%s" -Wno-unused-function'%os.path.abspath(self.GetCTRoot().GetIECLibPath())
--- a/LPCCanFestival.py Mon Feb 12 14:44:43 2018 +0100
+++ b/LPCCanFestival.py Tue Feb 13 14:03:25 2018 +0100
@@ -1,5 +1,8 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
+from __future__ import absolute_import
+
+import os
from ConfigTreeNode import ConfigTreeNode
--- a/LPCCommand.py Mon Feb 12 14:44:43 2018 +0100
+++ b/LPCCommand.py Tue Feb 13 14:03:25 2018 +0100
@@ -1,5 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
+from __future__ import absolute_import
import sys
import cmd
from threading import Thread, Semaphore, Lock, Timer
@@ -40,92 +41,96 @@
prompt = ""
RefreshTimer = None
- def __init__(self, CTR, Log):
+ def __init__(self, Launcher, CTR, Log):
cmd.Cmd.__init__(self, stdin=Log, stdout=Log)
self.use_rawinput = False
self.restore_last_state = False
+ self.Launcher = Launcher
self.Log = Log
self.CTR = CTR
- for function, (arg_types, opt) in {
- "Exit": ([], 0),
- "Show": ([bool], 1),
- "Refresh": ([], 0),
- "Close": ([], 0),
- "Compile": ([], 0),
- "SetProjectProperties": ([str, str, str, str], 0),
- "SetOnlineMode": ([str, str], 1),
- "AddBus": ([int, str, str], 1),
- "RenameBus": ([int, str], 0),
- "ChangeBusIECChannel": ([int, int], 0),
- "RemoveBus": ([int], 0),
- "AddModule": ([location, int, str, str, str], 1),
- "RenameModule": ([location, str], 0),
- "ChangeModuleIECChannel": ([location, int], 0),
- "ChangeModuleInitCode": ([location, str], 0),
- "RemoveModule": ([location, int], 0),
- "StartGroup": ([location, str, str], 1),
- "AddVariable": ([location, location, str, str, str, str, str, str], 1),
- "ChangeVariableParams": (
- [location, location, str, str, str, str, str, str], 1),
- "RemoveVariable": ([location, location], 0)
- }.iteritems():
- arg_number = len(arg_types)
+ for function, (arg_types, opt) in [
+ ("Exit", ([], 0)),
+ ("Show", ([bool], 1)),
+ ("Refresh", ([], 0)),
+ ("Close", ([], 0)),
+ ("Compile", ([], 0)),
+ ("SetProjectProperties", ([str, str, str, str], 0)),
+ ("SetOnlineMode", ([str, str], 1)),
+ ("AddBus", ([int, str, str], 1)),
+ ("RenameBus", ([int, str], 0)),
+ ("ChangeBusIECChannel", ([int, int], 0)),
+ ("RemoveBus", ([int], 0)),
+ ("AddModule", ([location, int, str, str, str], 1)),
+ ("RenameModule", ([location, str], 0)),
+ ("ChangeModuleIECChannel", ([location, int], 0)),
+ ("ChangeModuleInitCode", ([location, str], 0)),
+ ("RemoveModule", ([location, int], 0)),
+ ("StartGroup", ([location, str, str], 1)),
+ ("AddVariable", ([location, location, str, str, str, str, str, str], 1)),
+ ("ChangeVariableParams", ([location, location, str, str, str, str, str, str], 1)),
+ ("RemoveVariable", ([location, location], 0))
+ ]:
+ self.SetCmdFunc(function, arg_types, opt)
+
+ def SetCmdFunc(self, function, arg_types, opt):
+ setattr(self, "do_%s" % function,
+ lambda line : self.CmdFunction(
+ line, function, arg_types, opt))
- def CmdFunction(self, line):
- args_toks = line.split('"')
- if len(args_toks) % 2 == 0:
- self.Log.write("Error: Invalid command\n")
- sys.stdout.flush()
- return
- args = []
- for num, arg in enumerate(args_toks):
- if num % 2 == 0:
- stripped = arg.strip()
- if stripped:
- args.extend(stripped.split(" "))
- else:
- args.append(arg)
- number = None
- extra = ""
- if opt == 0 and len(args) != arg_number:
- number = arg_number
- elif len(args) > arg_number:
- number = arg_number
- extra = " at most"
- elif len(args) < arg_number - opt:
- number = arg_number - opt
- extra = " at least"
- if number is not None:
- if number == 0:
- self.Log.write("Error: No argument%s expected\n" % extra)
- elif number == 1:
- self.Log.write("Error: 1 argument%s expected\n" % extra)
- else:
- self.Log.write("Error: %d arguments%s expected\n" % (number, extra))
- sys.stdout.flush()
- return
- for num, arg in enumerate(args):
- try:
- args[num] = arg_types[num](arg)
- except:
- self.Log.write("Error: Invalid value for argument %d\n" % (num + 1))
- sys.stdout.flush()
- return
+ def CmdFunction(self, line, function, arg_types, opt):
+ arg_number = len(arg_types)
+ args_toks = line.split('"')
+ if len(args_toks) % 2 == 0:
+ self.Log.write("Error: Invalid command\n")
+ sys.stdout.flush()
+ return
+ args = []
+ for num, arg in enumerate(args_toks):
+ if num % 2 == 0:
+ stripped = arg.strip()
+ if stripped:
+ args.extend(stripped.split(" "))
+ else:
+ args.append(arg)
+ number = None
+ extra = ""
+ if opt == 0 and len(args) != arg_number:
+ number = arg_number
+ elif len(args) > arg_number:
+ number = arg_number
+ extra = " at most"
+ elif len(args) < arg_number - opt:
+ number = arg_number - opt
+ extra = " at least"
+ if number is not None:
+ if number == 0:
+ self.Log.write("Error: No argument%s expected for %s\n" % (extra, function))
+ elif number == 1:
+ self.Log.write("Error: 1 argument%s expected for %s\n" % (extra, function))
+ else:
+ self.Log.write("Error: %d arguments%s expecte for %s\n" % (number, extra, function))
+ sys.stdout.flush()
+ return
+ for num, arg in enumerate(args):
+ try:
+ args[num] = arg_types[num](arg)
+ except:
+ self.Log.write("Error: Invalid value for argument %d\n" % (num + 1))
+ sys.stdout.flush()
+ return
- func = getattr(self, function)
- res = evaluator(func, *args)
-
- # cmdlog.append((function, line, res))
- # if len(cmdlog) > 100: # prevent debug log to grow too much
- # cmdlog.pop(0)
+ func = getattr(self, function)
+ res = evaluator(func, *args)
- if isinstance(res, (StringType, UnicodeType)):
- self.Log.write(res)
- return False
- else:
- return res
-
- setattr(self, "do_%s" % function, CmdFunction)
+ # cmdlog.append((function, line, res))
+ # if len(cmdlog) > 100: # prevent debug log to grow too much
+ # cmdlog.pop(0)
+
+ if isinstance(res, (StringType, UnicodeType)):
+ self.Log.write(res)
+ return False
+ else:
+ return res
def RestartTimer(self):
if self.RefreshTimer is not None:
@@ -134,41 +139,36 @@
self.RefreshTimer.start()
def Exit(self):
- global frame, app
self.Close()
- app.ExitMainLoop()
+ self.Launcher.app.ExitMainLoop()
return True
def do_EOF(self, line):
return self.Exit()
def Show(self, loading=False):
- global frame
- if frame is not None:
- self.CTR.SetAppFrame(frame, frame.Log)
+ if self.Launcher.frame is not None:
+ self.CTR.SetAppFrame(self.Launcher.frame, self.Launcher.frame.Log)
self.CTR.UpdateMethodsFromPLCStatus()
- frame.Show(loading)
- frame.Raise()
+ self.Launcher.frame.Show(loading)
+ self.Launcher.frame.Raise()
self.restore_last_state = True
#self.RestartTimer()
def Refresh(self):
- global frame
- if frame is not None:
+ if self.Launcher.frame is not None:
if self.restore_last_state:
self.restore_last_state = False
- frame.RestoreLastState()
+ self.Launcher.frame.RestoreLastState()
else:
- frame.RefreshEditor()
- frame._Refresh(TITLE, PROJECTTREE, POUINSTANCEVARIABLESPANEL, FILEMENU, EDITMENU)
- frame.RefreshAll()
+ self.Launcher.frame.RefreshEditor()
+ self.Launcher.frame._Refresh(TITLE, PROJECTTREE, POUINSTANCEVARIABLESPANEL, FILEMENU, EDITMENU)
+ self.Launcher.frame.RefreshAll()
def Close(self):
- global frame
-
self.CTR.ResetAppFrame(self.Log)
- if frame is not None:
- frame.Hide()
+ if self.Launcher.frame is not None:
+ self.Launcher.frame.Hide()
def Compile(self):
self.CTR._Build()
--- a/LPCExtension.py Mon Feb 12 14:44:43 2018 +0100
+++ b/LPCExtension.py Tue Feb 13 14:03:25 2018 +0100
@@ -1,5 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
+from __future__ import absolute_import
#
# --------- Libraries Extension ------------
@@ -7,6 +8,7 @@
import features
from POULibrary import SimplePOULibraryFactory
+from LPCArch import arch, PLC_MC9_module, PLC_GOT_module
# _lpcmanager_path, arch, etc are defined here because
# globals() of LPCManager.py are passed to extentions
@@ -18,7 +20,7 @@
if arch in PLC_MC9_module:
features.libraries += [('Python', 'py_ext.PythonLibrary'),
- ('RTC', SimplePOULibraryFactory(_poulibpath("RTC"))]
+ ('RTC', SimplePOULibraryFactory(_poulibpath("RTC")))]
elif arch in PLC_GOT_module:
features.libraries += [('Python', 'py_ext.PythonLibrary'),
('RTC', SimplePOULibraryFactory(_poulibpath("RTC"))),
--- a/LPCManager.py Mon Feb 12 14:44:43 2018 +0100
+++ b/LPCManager.py Tue Feb 13 14:03:25 2018 +0100
@@ -1,10 +1,12 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
+from __future__ import absolute_import
import sys
import os
import getopt
import __builtin__
import time
+from threading import Thread
# On Windows install schema, we compute path to beremiz
# relative to path to python folder (sys.path[0] in that case)
@@ -21,13 +23,14 @@
_lpcmanager_path = os.path.split(__file__)[0]
from LPCArch import PLC_module, SetLPCArch
+from Beremiz import BeremizIDELauncher
class LPCManagerLauncher(BeremizIDELauncher):
def __init__(self):
BeremizIDELauncher.__init__(self)
self.arch = None
self.port = None
- self.extensions = [os.path.join(_lpcmanager_path, "extention.py")]
+ self.extensions = [os.path.join(_lpcmanager_path, "LPCExtension.py")]
self.modules.extend([
"LPCBeremiz",
"StdoutPseudoFile",
@@ -87,13 +90,13 @@
else:
CMDpipe.write("Error: No such file or directory")
- lpcberemiz_cmd = LPCCommand(CTR, CMDpipe)
+ lpcberemiz_cmd = self.LPCCommand.LPCCommand(self, CTR, CMDpipe)
cmd_thread = Thread(target=lpcberemiz_cmd.cmdloop)
cmd_thread.start()
# TODO: join() when exiting
- self.frame = self.LPCBeremiz.LPCBeremiz(None, ctr=CTR)
+ self.frame = self.LPCBeremiz.LPCBeremiz(None, ctr=CTR, pipe=CMDpipe)
def ShowUI(self):
# the "Show" command from composer does it instead
--- a/LPCProjectController.py Mon Feb 12 14:44:43 2018 +0100
+++ b/LPCProjectController.py Tue Feb 13 14:03:25 2018 +0100
@@ -1,10 +1,8 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
-
-import fnmatch
-import shutil
+from __future__ import absolute_import
+import os
import zipfile
-import tempfile
from ProjectController import ProjectController
from LPCArch import PLC_module
@@ -66,7 +64,7 @@
self.SaveProject()
self.AppFrame.RefreshAfterSave()
- result = ProjectController._Build(self):
+ result = ProjectController._Build(self)
if result:
self.ToZIPFile()
@@ -125,7 +123,7 @@
"pageSize": (0, 0),
"scaling": {}})
- ProjectController.LoadProject(self, ProjectPath, BuildPath=None):
+ ProjectController.LoadProject(self, ProjectPath, BuildPath=None)
canopen_child = self.GetChildByName("CanOpen")
if canopen_child is None: