lpcmanager

c9f9599194ca
Parents b8992ad86bb7
Children 7dd488886ff5
Added error report to sentry for testing.
Overirde one function.
  • +454 -411
    LPCManager.py
  • --- a/LPCManager.py Thu Jun 01 12:44:46 2017 +0200
    +++ b/LPCManager.py Fri Jun 02 14:58:43 2017 +0200
    @@ -1,16 +1,21 @@
    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    +import sys
    import shutil
    import socket
    import zipfile
    import fnmatch
    import threading
    import faulthandler
    +from raven import Client
    +
    +
    +client = Client('https://2d582ee8f9234cc08283f8a686c92dae:631a5b935bf64b36b5a2d1781af437b2@sentry.io/174818')
    faulthandler.enable()
    __version__ = "$Revision$"
    -import os, sys, getopt, tempfile
    +import os, getopt, tempfile
    import __builtin__
    from types import TupleType, StringType, UnicodeType
    @@ -170,6 +175,48 @@
    from py_ext import PythonFileCTNMixin
    +def _Generate_C(self, buildpath, locations):
    + # Generate confnodes [(Cfiles, CFLAGS)], LDFLAGS, DoCalls, extra_files
    + # extra_files = [(fname,fobject), ...]
    + gen_result = self.CTNGenerate_C(buildpath, locations)
    + CTNCFilesAndCFLAGS, CTNLDFLAGS, DoCalls = gen_result[:3]
    + extra_files = gen_result[3:]
    + # if some files have been generated put them in the list with their location
    + if CTNCFilesAndCFLAGS:
    + LocationCFilesAndCFLAGS = [(self.GetCurrentLocation(), CTNCFilesAndCFLAGS, DoCalls)]
    + else:
    + LocationCFilesAndCFLAGS = []
    +
    + # confnode asks for some LDFLAGS
    + if CTNLDFLAGS:
    + # LDFLAGS can be either string
    + if type(CTNLDFLAGS) == type(str()) or type(CTNLDFLAGS) == type(unicode()):
    + LDFLAGS = [CTNLDFLAGS]
    + # or list of strings
    + elif type(CTNLDFLAGS) == type(list()):
    + LDFLAGS = CTNLDFLAGS[:]
    + else:
    + LDFLAGS = []
    +
    + # recurse through all children, and stack their results
    + for CTNChild in self.IECSortedChildren():
    + new_location = CTNChild.GetCurrentLocation()
    + # How deep are we in the tree ?
    + depth = len(new_location)
    + _LocationCFilesAndCFLAGS, _LDFLAGS, _extra_files = \
    + CTNChild._Generate_C(
    + # keep the same path
    + buildpath,
    + # filter locations that start with current IEC location
    + [loc for loc in locations if loc["LOC"][0:depth] == new_location])
    + # stack the result
    + LocationCFilesAndCFLAGS += _LocationCFilesAndCFLAGS
    + LDFLAGS += _LDFLAGS
    + extra_files += _extra_files
    +
    + return LocationCFilesAndCFLAGS, LDFLAGS, extra_files
    +ConfigTreeNode._Generate_C = _Generate_C
    +
    def CTNGenerate_C(self, buildpath, locations):
    # location string for that CTN
    location_str = "_".join(map(lambda x: str(x),
    @@ -971,7 +1018,6 @@
    else:
    blocktypes.extend([pou.getname() for pou in project.getpous(name, ["functionBlock"])])
    return blocktypes
    -
    PLCControler.GetFunctionBlockTypes = GetFunctionBlockTypes
    def LeftClick(self, event):
    @@ -995,7 +1041,6 @@
    else:
    event.Skip()
    -
    VariablesTable.LeftClick = LeftClick
    def RefreshView(self, variablepanel=True):
    @@ -1045,14 +1090,12 @@
    "extensible": blocktype["extensible"]}
    self.Colourise(0, -1)
    -
    TextViewer.RefreshView = RefreshView
    def VariablesEditorSetCollSize(self):
    ColSizes = [20, 150] + [130] * (len(self.VariablesDefaultValue) - 2) + [300]
    for col in range(self.Table.GetNumberCols()):
    self.VariablesGrid.SetColSize(col, ColSizes[col])
    -
    VariablesEditor.VariablesEditorSetCollSize = VariablesEditorSetCollSize
    def _updateColAttrs(self, grid):
    @@ -1503,7 +1546,7 @@
    self.building = False
    # pub.sendMessage("build", msg="True")
    - self._Clean(building = True)
    + # self._Clean(building = True)
    save = self.ProjectTestModified()
    if save:
    self.SaveProject()
    @@ -1511,6 +1554,7 @@
    if self.BuildPath is not None:
    mycopytree(self.OrigBuildPath, self.BuildPath)
    if len(filter(lambda x: x.getName() == "OnBuildThread", threads)) == 0:
    + self._Clean(building=True)
    build_thread = Thread(name="OnBuildThread", target=__Build, args=(self,save))
    build_thread.daemon = True
    build_thread.start()
    @@ -2468,414 +2512,413 @@
    if __name__ == '__main__':
    - try:
    -
    - from threading import Thread, Timer, Semaphore, Lock
    - import cmd
    -
    - build_lock = Lock()
    - wx_eval_lock = Semaphore(0)
    + # try:
    +
    + from threading import Thread, Timer, Semaphore, Lock
    + import cmd
    +
    + build_lock = Lock()
    + wx_eval_lock = Semaphore(0)
    + eval_res = None
    +
    +
    + def wx_evaluator(callable, *args, **kwargs):
    + global eval_res
    eval_res = None
    -
    -
    - def wx_evaluator(callable, *args, **kwargs):
    - global eval_res
    - eval_res = None
    - try:
    - eval_res = callable(*args, **kwargs)
    - finally:
    - wx_eval_lock.release()
    -
    -
    - def evaluator(callable, *args, **kwargs):
    - global eval_res
    - wx.CallAfter(wx_evaluator, callable, *args, **kwargs)
    - wx_eval_lock.acquire()
    - return eval_res
    -
    -
    - # Command log for debug, for viewing from wxInspector
    - if BMZ_DBG:
    - __builtins__.cmdlog = []
    -
    -
    - class LPCBeremiz_Cmd(cmd.Cmd):
    -
    - prompt = ""
    - RefreshTimer = None
    -
    - def __init__(self, CTR, Log):
    - cmd.Cmd.__init__(self, stdin=Log, stdout=Log)
    - self.use_rawinput = False
    - self.restore_last_state = False
    - self.Log = Log
    - self.CTR = CTR
    -
    - def RestartTimer(self):
    - if self.RefreshTimer is not None:
    - self.RefreshTimer.cancel()
    - self.RefreshTimer = Timer(0.1, wx.CallAfter, args=[self.Refresh])
    - self.RefreshTimer.start()
    -
    - def Exit(self):
    - global frame, app
    - self.Close()
    - app.ExitMainLoop()
    - return True
    -
    - def do_EOF(self, line):
    - return self.Exit()
    -
    - def Show(self):
    - global frame
    - if frame is not None:
    - self.CTR.SetAppFrame(frame, frame.Log)
    - self.CTR.UpdateMethodsFromPLCStatus()
    - frame.Show()
    - frame.Raise()
    - self.restore_last_state = True
    - #self.RestartTimer()
    -
    - def Refresh(self):
    - global frame
    - if frame is not None:
    - if self.restore_last_state:
    - self.restore_last_state = False
    - frame.RestoreLastState()
    - else:
    - frame.RefreshEditor()
    - frame._Refresh(TITLE, PROJECTTREE, POUINSTANCEVARIABLESPANEL, FILEMENU, EDITMENU)
    - frame.RefreshAll()
    -
    - def Close(self):
    - global frame
    -
    - self.CTR.ResetAppFrame(self.Log)
    - if frame is not None:
    - frame.Hide()
    -
    - def Compile(self):
    - self.CTR._Build()
    -
    - def SetProjectProperties(self, projectname, productname, productversion, companyname):
    - new_properties = {
    - "projectName": projectname,
    - "productName": productname,
    - "productVersion": productversion,
    - "companyName": companyname}
    - self.CTR.SetProjectProperties(properties=new_properties, buffer=False)
    - self.RestartTimer()
    -
    - def SetOnlineMode(self, mode, path=None):
    - self.CTR.SetOnlineMode(mode, path)
    - self.RestartTimer()
    -
    - def AddBus(self, iec_channel, name, icon=None):
    - for child in self.CTR.IterChildren():
    - if child.BaseParams.getName() == name:
    - return "Error: A bus named %s already exists\n" % name
    - elif child.BaseParams.getIEC_Channel() == iec_channel:
    - return "Error: A bus with IEC_channel %d already exists\n" % iec_channel
    - bus = self.CTR.CTNAddChild(name, "LPCBus", iec_channel)
    - if bus is None:
    - return "Error: Unable to create bus\n"
    - bus.SetIcon(icon)
    - self.RestartTimer()
    -
    - def RenameBus(self, iec_channel, name):
    - bus = self.CTR.GetChildByIECLocation((iec_channel,))
    - if bus is None:
    - return "Error: No bus found\n"
    - for child in self.CTR.IterChildren():
    - if child != bus and child.BaseParams.getName() == name:
    - return "Error: A bus named %s already exists\n" % name
    - bus.BaseParams.setName(name)
    - self.RestartTimer()
    -
    - def ChangeBusIECChannel(self, old_iec_channel, new_iec_channel):
    - bus = self.CTR.GetChildByIECLocation((old_iec_channel,))
    - if bus is None:
    - return "Error: No bus found\n"
    - for child in self.CTR.IterChildren():
    - if child != bus and child.BaseParams.getIEC_Channel() == new_iec_channel:
    - return "Error: A bus with IEC_channel %d already exists\n" % new_iec_channel
    - if wx.GetApp() is None:
    - self.CTR.UpdateProjectVariableLocation(str(old_iec_channel),
    - str(new_iec_channel))
    + try:
    + eval_res = callable(*args, **kwargs)
    + finally:
    + wx_eval_lock.release()
    +
    +
    + def evaluator(callable, *args, **kwargs):
    + global eval_res
    + wx.CallAfter(wx_evaluator, callable, *args, **kwargs)
    + wx_eval_lock.acquire()
    + return eval_res
    +
    +
    + # Command log for debug, for viewing from wxInspector
    + if BMZ_DBG:
    + __builtins__.cmdlog = []
    +
    +
    + class LPCBeremiz_Cmd(cmd.Cmd):
    +
    + prompt = ""
    + RefreshTimer = None
    +
    + def __init__(self, CTR, Log):
    + cmd.Cmd.__init__(self, stdin=Log, stdout=Log)
    + self.use_rawinput = False
    + self.restore_last_state = False
    + self.Log = Log
    + self.CTR = CTR
    +
    + def RestartTimer(self):
    + if self.RefreshTimer is not None:
    + self.RefreshTimer.cancel()
    + self.RefreshTimer = Timer(0.1, wx.CallAfter, args=[self.Refresh])
    + self.RefreshTimer.start()
    +
    + def Exit(self):
    + global frame, app
    + self.Close()
    + app.ExitMainLoop()
    + return True
    +
    + def do_EOF(self, line):
    + return self.Exit()
    +
    + def Show(self):
    + global frame
    + if frame is not None:
    + self.CTR.SetAppFrame(frame, frame.Log)
    + self.CTR.UpdateMethodsFromPLCStatus()
    + frame.Show()
    + frame.Raise()
    + self.restore_last_state = True
    + #self.RestartTimer()
    +
    + def Refresh(self):
    + global frame
    + if frame is not None:
    + if self.restore_last_state:
    + self.restore_last_state = False
    + frame.RestoreLastState()
    else:
    - self.CTR.UpdateProjectVariableLocation(
    - str(old_iec_channel),
    - str(new_iec_channel))
    - bus.BaseParams.setIEC_Channel(new_iec_channel)
    - self.RestartTimer()
    -
    - def RemoveBus(self, iec_channel):
    - bus = self.CTR.GetChildByIECLocation((iec_channel,))
    - if bus is None:
    - return "Error: No bus found\n"
    - self.CTR.RemoveProjectVariableByFilter(str(iec_channel))
    - self.CTR.Children["LPCBus"].remove(bus)
    - self.RestartTimer()
    -
    - def AddModule(self, parent, iec_channel, name, icode, icon=None):
    - module = self.CTR.GetChildByIECLocation(parent)
    - if module is None:
    - return "Error: No parent found\n"
    - for child in GetModuleChildren(module):
    + frame.RefreshEditor()
    + frame._Refresh(TITLE, PROJECTTREE, POUINSTANCEVARIABLESPANEL, FILEMENU, EDITMENU)
    + frame.RefreshAll()
    +
    + def Close(self):
    + global frame
    +
    + self.CTR.ResetAppFrame(self.Log)
    + if frame is not None:
    + frame.Hide()
    +
    + def Compile(self):
    + self.CTR._Build()
    +
    + def SetProjectProperties(self, projectname, productname, productversion, companyname):
    + new_properties = {
    + "projectName": projectname,
    + "productName": productname,
    + "productVersion": productversion,
    + "companyName": companyname}
    + self.CTR.SetProjectProperties(properties=new_properties, buffer=False)
    + self.RestartTimer()
    +
    + def SetOnlineMode(self, mode, path=None):
    + self.CTR.SetOnlineMode(mode, path)
    + self.RestartTimer()
    +
    + def AddBus(self, iec_channel, name, icon=None):
    + for child in self.CTR.IterChildren():
    + if child.BaseParams.getName() == name:
    + return "Error: A bus named %s already exists\n" % name
    + elif child.BaseParams.getIEC_Channel() == iec_channel:
    + return "Error: A bus with IEC_channel %d already exists\n" % iec_channel
    + bus = self.CTR.CTNAddChild(name, "LPCBus", iec_channel)
    + if bus is None:
    + return "Error: Unable to create bus\n"
    + bus.SetIcon(icon)
    + self.RestartTimer()
    +
    + def RenameBus(self, iec_channel, name):
    + bus = self.CTR.GetChildByIECLocation((iec_channel,))
    + if bus is None:
    + return "Error: No bus found\n"
    + for child in self.CTR.IterChildren():
    + if child != bus and child.BaseParams.getName() == name:
    + return "Error: A bus named %s already exists\n" % name
    + bus.BaseParams.setName(name)
    + self.RestartTimer()
    +
    + def ChangeBusIECChannel(self, old_iec_channel, new_iec_channel):
    + bus = self.CTR.GetChildByIECLocation((old_iec_channel,))
    + if bus is None:
    + return "Error: No bus found\n"
    + for child in self.CTR.IterChildren():
    + if child != bus and child.BaseParams.getIEC_Channel() == new_iec_channel:
    + return "Error: A bus with IEC_channel %d already exists\n" % new_iec_channel
    + if wx.GetApp() is None:
    + self.CTR.UpdateProjectVariableLocation(str(old_iec_channel),
    + str(new_iec_channel))
    + else:
    + self.CTR.UpdateProjectVariableLocation(
    + str(old_iec_channel),
    + str(new_iec_channel))
    + bus.BaseParams.setIEC_Channel(new_iec_channel)
    + self.RestartTimer()
    +
    + def RemoveBus(self, iec_channel):
    + bus = self.CTR.GetChildByIECLocation((iec_channel,))
    + if bus is None:
    + return "Error: No bus found\n"
    + self.CTR.RemoveProjectVariableByFilter(str(iec_channel))
    + self.CTR.Children["LPCBus"].remove(bus)
    + self.RestartTimer()
    +
    + def AddModule(self, parent, iec_channel, name, icode, icon=None):
    + module = self.CTR.GetChildByIECLocation(parent)
    + if module is None:
    + return "Error: No parent found\n"
    + for child in GetModuleChildren(module):
    + if child["name"] == name:
    + return "Error: A module named %s already exists\n" % name
    + elif child["IEC_Channel"] == iec_channel:
    + return "Error: A module with IEC_channel %d already exists\n" % iec_channel
    + GetLastModuleGroup(module).append({"name": name,
    + "type": LOCATION_MODULE,
    + "IEC_Channel": iec_channel,
    + "icon": icon,
    + "init": icode,
    + "children": []})
    + self.RestartTimer()
    +
    + def RenameModule(self, iec_location, name):
    + module = self.CTR.GetChildByIECLocation(iec_location)
    + if module is None:
    + return "Error: No module found\n"
    + parent = self.CTR.GetChildByIECLocation(iec_location[:-1])
    + if parent is self.CTR:
    + return "Error: No module found\n"
    + if module["name"] != name:
    + for child in GetModuleChildren(parent):
    if child["name"] == name:
    return "Error: A module named %s already exists\n" % name
    - elif child["IEC_Channel"] == iec_channel:
    - return "Error: A module with IEC_channel %d already exists\n" % iec_channel
    - GetLastModuleGroup(module).append({"name": name,
    - "type": LOCATION_MODULE,
    - "IEC_Channel": iec_channel,
    - "icon": icon,
    - "init": icode,
    - "children": []})
    - self.RestartTimer()
    -
    - def RenameModule(self, iec_location, name):
    - module = self.CTR.GetChildByIECLocation(iec_location)
    - if module is None:
    - return "Error: No module found\n"
    - parent = self.CTR.GetChildByIECLocation(iec_location[:-1])
    - if parent is self.CTR:
    - return "Error: No module found\n"
    - if module["name"] != name:
    - for child in GetModuleChildren(parent):
    - if child["name"] == name:
    - return "Error: A module named %s already exists\n" % name
    - module["name"] = name
    - self.RestartTimer()
    -
    - def ChangeModuleIECChannel(self, old_iec_location, new_iec_channel):
    - module = self.CTR.GetChildByIECLocation(old_iec_location)
    - if module is None:
    - return "Error: No module found\n"
    - parent = self.CTR.GetChildByIECLocation(old_iec_location[:-1])
    - if parent is self.CTR:
    - return "Error: No module found\n"
    - if module["IEC_Channel"] != new_iec_channel:
    - for child in GetModuleChildren(parent):
    - if child["IEC_Channel"] == new_iec_channel:
    - return "Error: A module with IEC_channel %d already exists\n" % new_iec_channel
    - self.CTR.UpdateProjectVariableLocation(".".join(map(str, old_iec_location)),
    - ".".join(map(str, old_iec_location[:1] + (new_iec_channel,))))
    - module["IEC_Channel"] = new_iec_channel
    - self.RestartTimer()
    -
    - def ChangeModuleInitCode(self, iec_location, icode):
    - module = self.CTR.GetChildByIECLocation(iec_location)
    - if module is None:
    - return "Error: No module found\n"
    - module["init"] = icode
    -
    - def RemoveModule(self, parent, iec_channel):
    - module = self.CTR.GetChildByIECLocation(parent)
    - if module is None:
    - return "Error: No parent found\n"
    - child = GetModuleBySomething(module, "IEC_Channel", (iec_channel,))
    - if child is None:
    - return "Error: No module found\n"
    - self.CTR.RemoveProjectVariableByFilter(".".join(map(str, parent + (iec_channel,))))
    - RemoveModuleChild(module, child)
    - self.RestartTimer()
    -
    - def StartGroup(self, parent, name, icon=None):
    - module = self.CTR.GetChildByIECLocation(parent)
    - if module is None:
    - return "Error: No parent found\n"
    - for child in module["children"]:
    - if child["type"] == LOCATION_GROUP and child["name"] == name:
    - return "Error: A group named %s already exists\n" % name
    - module["children"].append({"name": name,
    - "type": LOCATION_GROUP,
    - "icon": icon,
    - "children": []})
    - self.RestartTimer()
    -
    - def AddVariable(self, parent, location, name, direction, type, rcode, pcode, description=""):
    - module = self.CTR.GetChildByIECLocation(parent)
    - if module is None:
    - return "Error: No parent found\n"
    - for child in GetModuleChildren(module):
    - if child["name"] == name:
    - return "Error: A variable named %s already exists\n" % name
    - if child["location"] == location and child["type"] == LOCATION_TYPES[direction]:
    - return "Error: A variable with location %s already exists\n" % ".".join(map(str, location))
    - GetLastModuleGroup(module).append({"name": name,
    - "location": location,
    - "type": LOCATION_TYPES[direction],
    - "IEC_type": type,
    - "description": description,
    - "retrieve": rcode,
    - "publish": pcode})
    - self.RestartTimer()
    -
    - def ChangeVariableParams(self, parent, location, new_name, new_direction, new_type, new_rcode, new_pcode,
    - new_description=None):
    - module = self.CTR.GetChildByIECLocation(parent)
    - if module is None:
    - return "Error: No parent found\n"
    - variable = None
    - for child in GetModuleChildren(module):
    - if child["location"] == location and child["type"] == LOCATION_TYPES[new_direction]:
    - variable = child
    - elif child["name"] == new_name:
    - return "Error: A variable named %s already exists\n" % new_name
    - if variable is None:
    - return "Error: No variable found\n"
    - if variable["name"] != new_name:
    - self.CTR.UpdateProjectVariableName(variable["name"], new_name)
    - variable["name"] = new_name
    - variable["type"] = LOCATION_TYPES[new_direction]
    - variable["IEC_type"] = new_type
    - variable["retrieve"] = new_rcode
    - variable["publish"] = new_pcode
    - if new_description is not None:
    - variable["description"] = new_description
    - self.RestartTimer()
    -
    - def RemoveVariable(self, parent, location, direction):
    - module = self.CTR.GetChildByIECLocation(parent)
    - if module is None:
    - return "Error: No parent found\n"
    - child = GetModuleVariable(module, location, direction)
    - if child is None:
    - return "Error: No variable found\n"
    - size = LOCATION_SIZES[self.CTR.GetBaseType(child["IEC_type"])]
    - address = "%" + LOCATION_DIRS[child["type"]] + size + ".".join(map(str, parent + location))
    - self.CTR.RemoveProjectVariableByAddress(address)
    - RemoveModuleChild(module, child)
    - self.RestartTimer()
    -
    -
    - def location(loc):
    - return tuple(map(int, loc.split(".")))
    -
    -
    - def GetCmdFunction(function, arg_types, opt=0):
    - arg_number = len(arg_types)
    -
    - def CmdFunction(self, line):
    - args_toks = line.split('"')
    - if len(args_toks) % 2 == 0:
    - self.Log.write("Error: Invalid command\n")
    + module["name"] = name
    + self.RestartTimer()
    +
    + def ChangeModuleIECChannel(self, old_iec_location, new_iec_channel):
    + module = self.CTR.GetChildByIECLocation(old_iec_location)
    + if module is None:
    + return "Error: No module found\n"
    + parent = self.CTR.GetChildByIECLocation(old_iec_location[:-1])
    + if parent is self.CTR:
    + return "Error: No module found\n"
    + if module["IEC_Channel"] != new_iec_channel:
    + for child in GetModuleChildren(parent):
    + if child["IEC_Channel"] == new_iec_channel:
    + return "Error: A module with IEC_channel %d already exists\n" % new_iec_channel
    + self.CTR.UpdateProjectVariableLocation(".".join(map(str, old_iec_location)),
    + ".".join(map(str, old_iec_location[:1] + (new_iec_channel,))))
    + module["IEC_Channel"] = new_iec_channel
    + self.RestartTimer()
    +
    + def ChangeModuleInitCode(self, iec_location, icode):
    + module = self.CTR.GetChildByIECLocation(iec_location)
    + if module is None:
    + return "Error: No module found\n"
    + module["init"] = icode
    +
    + def RemoveModule(self, parent, iec_channel):
    + module = self.CTR.GetChildByIECLocation(parent)
    + if module is None:
    + return "Error: No parent found\n"
    + child = GetModuleBySomething(module, "IEC_Channel", (iec_channel,))
    + if child is None:
    + return "Error: No module found\n"
    + self.CTR.RemoveProjectVariableByFilter(".".join(map(str, parent + (iec_channel,))))
    + RemoveModuleChild(module, child)
    + self.RestartTimer()
    +
    + def StartGroup(self, parent, name, icon=None):
    + module = self.CTR.GetChildByIECLocation(parent)
    + if module is None:
    + return "Error: No parent found\n"
    + for child in module["children"]:
    + if child["type"] == LOCATION_GROUP and child["name"] == name:
    + return "Error: A group named %s already exists\n" % name
    + module["children"].append({"name": name,
    + "type": LOCATION_GROUP,
    + "icon": icon,
    + "children": []})
    + self.RestartTimer()
    +
    + def AddVariable(self, parent, location, name, direction, type, rcode, pcode, description=""):
    + module = self.CTR.GetChildByIECLocation(parent)
    + if module is None:
    + return "Error: No parent found\n"
    + for child in GetModuleChildren(module):
    + if child["name"] == name:
    + return "Error: A variable named %s already exists\n" % name
    + if child["location"] == location and child["type"] == LOCATION_TYPES[direction]:
    + return "Error: A variable with location %s already exists\n" % ".".join(map(str, location))
    + GetLastModuleGroup(module).append({"name": name,
    + "location": location,
    + "type": LOCATION_TYPES[direction],
    + "IEC_type": type,
    + "description": description,
    + "retrieve": rcode,
    + "publish": pcode})
    + self.RestartTimer()
    +
    + def ChangeVariableParams(self, parent, location, new_name, new_direction, new_type, new_rcode, new_pcode,
    + new_description=None):
    + module = self.CTR.GetChildByIECLocation(parent)
    + if module is None:
    + return "Error: No parent found\n"
    + variable = None
    + for child in GetModuleChildren(module):
    + if child["location"] == location and child["type"] == LOCATION_TYPES[new_direction]:
    + variable = child
    + elif child["name"] == new_name:
    + return "Error: A variable named %s already exists\n" % new_name
    + if variable is None:
    + return "Error: No variable found\n"
    + if variable["name"] != new_name:
    + self.CTR.UpdateProjectVariableName(variable["name"], new_name)
    + variable["name"] = new_name
    + variable["type"] = LOCATION_TYPES[new_direction]
    + variable["IEC_type"] = new_type
    + variable["retrieve"] = new_rcode
    + variable["publish"] = new_pcode
    + if new_description is not None:
    + variable["description"] = new_description
    + self.RestartTimer()
    +
    + def RemoveVariable(self, parent, location, direction):
    + module = self.CTR.GetChildByIECLocation(parent)
    + if module is None:
    + return "Error: No parent found\n"
    + child = GetModuleVariable(module, location, direction)
    + if child is None:
    + return "Error: No variable found\n"
    + size = LOCATION_SIZES[self.CTR.GetBaseType(child["IEC_type"])]
    + address = "%" + LOCATION_DIRS[child["type"]] + size + ".".join(map(str, parent + location))
    + self.CTR.RemoveProjectVariableByAddress(address)
    + RemoveModuleChild(module, child)
    + self.RestartTimer()
    +
    +
    + def location(loc):
    + return tuple(map(int, loc.split(".")))
    +
    +
    + def GetCmdFunction(function, arg_types, opt=0):
    + arg_number = len(arg_types)
    +
    + 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
    - 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
    -
    - func = getattr(self, function)
    - res = evaluator(func, *args)
    -
    - if BMZ_DBG:
    - 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
    -
    - return CmdFunction
    -
    -
    - def CmdThreadProc(CTR, Log):
    - global lpcberemiz_cmd
    - for function, (arg_types, opt) in {"Exit": ([], 0),
    - "Show": ([], 0),
    - "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():
    - setattr(LPCBeremiz_Cmd, "do_%s" % function, GetCmdFunction(function, arg_types, opt))
    - lpcberemiz_cmd = LPCBeremiz_Cmd(CTR, Log)
    - lpcberemiz_cmd.cmdloop()
    -
    - def ResetwxGlade():
    - # reset pid of running wxGlade
    - config = wx.ConfigBase.Get()
    - wxGladePid = 0
    - config.Write("BeremizRoot.wxGlade", str(wxGladePid))
    - config.Flush()
    -
    - Log = StdoutPseudoFile(port)
    -
    - if projectOpen is not None:
    - projectOpen = DecodeFileSystemPath(projectOpen, False)
    -
    - CTR = LPCProjectController(None, Log, buildpath)
    - if projectOpen is not None and os.path.isdir(projectOpen):
    - result = CTR.LoadProject(projectOpen)
    - if result:
    - Log.write("Error: Invalid project directory", result)
    - else:
    - Log.write("Error: No such file or directory")
    -
    - cmd_thread = Thread(target=CmdThreadProc, args=[CTR, Log])
    - cmd_thread.start()
    -
    - # Install a exception handle for bug reports
    - AddExceptHook(os.getcwd(), __version__)
    -
    - frame = LPCBeremiz(None, ctr=CTR, debug=True)
    -
    - ResetwxGlade()
    -
    - app.MainLoop()
    -
    - except Exception, e:
    - import traceback
    - errmess = traceback.format_exc()
    - print("Traceback: {}\n{}".format(e, errmess))
    -
    +
    + func = getattr(self, function)
    + res = evaluator(func, *args)
    +
    + if BMZ_DBG:
    + 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
    +
    + return CmdFunction
    +
    +
    + def CmdThreadProc(CTR, Log):
    + global lpcberemiz_cmd
    + for function, (arg_types, opt) in {"Exit": ([], 0),
    + "Show": ([], 0),
    + "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():
    + setattr(LPCBeremiz_Cmd, "do_%s" % function, GetCmdFunction(function, arg_types, opt))
    + lpcberemiz_cmd = LPCBeremiz_Cmd(CTR, Log)
    + lpcberemiz_cmd.cmdloop()
    +
    + def ResetwxGlade():
    + # reset pid of running wxGlade
    + config = wx.ConfigBase.Get()
    + wxGladePid = 0
    + config.Write("BeremizRoot.wxGlade", str(wxGladePid))
    + config.Flush()
    +
    + Log = StdoutPseudoFile(port)
    +
    + if projectOpen is not None:
    + projectOpen = DecodeFileSystemPath(projectOpen, False)
    +
    + CTR = LPCProjectController(None, Log, buildpath)
    + if projectOpen is not None and os.path.isdir(projectOpen):
    + result = CTR.LoadProject(projectOpen)
    + if result:
    + Log.write("Error: Invalid project directory", result)
    + else:
    + Log.write("Error: No such file or directory")
    +
    + cmd_thread = Thread(target=CmdThreadProc, args=[CTR, Log])
    + cmd_thread.start()
    +
    + # Install a exception handle for bug reports
    + AddExceptHook(os.getcwd(), __version__)
    +
    + frame = LPCBeremiz(None, ctr=CTR, debug=True)
    +
    + ResetwxGlade()
    +
    + app.MainLoop()
    +
    + # except Exception, e:
    + # import traceback
    + # errmess = traceback.format_exc()
    + # print("Traceback: {}\n{}".format(e, errmess))
    \ No newline at end of file