LPCBeremiz.py
changeset 551 d18e86b603bc
parent 550 b03f586547c9
child 552 ab7916df0de7
equal deleted inserted replaced
550:b03f586547c9 551:d18e86b603bc
     1 #!/usr/bin/env python
     1 #!/usr/bin/env python
     2 # -*- coding: utf-8 -*-
     2 # -*- coding: utf-8 -*-
     3 import shutil
     3 import shutil
       
     4 import socket
     4 
     5 
     5 __version__ = "$Revision$"
     6 __version__ = "$Revision$"
     6 
     7 
     7 import os, sys, getopt, wx, tempfile
     8 import os, sys, getopt, wx, tempfile
     8 from types import TupleType, StringType, UnicodeType
     9 from types import TupleType, StringType, UnicodeType
    13     return os.path.join(CWD,*args)
    14     return os.path.join(CWD,*args)
    14 
    15 
    15 if __name__ == '__main__':
    16 if __name__ == '__main__':
    16     def usage():
    17     def usage():
    17         print "\nUsage of LPCBeremiz.py :"
    18         print "\nUsage of LPCBeremiz.py :"
    18         print "\n   %s [Projectpath] [Buildpath]\n"%sys.argv[0]
    19         print "\n   %s Projectpath Buildpath port\n"%sys.argv[0]
    19     
    20     
    20     try:
    21     try:
    21         opts, args = getopt.getopt(sys.argv[1:], "h", ["help"])
    22         opts, args = getopt.getopt(sys.argv[1:], "h", ["help"])
    22     except getopt.GetoptError:
    23     except getopt.GetoptError:
    23         # print help information and exit:
    24         # print help information and exit:
    27     for o, a in opts:
    28     for o, a in opts:
    28         if o in ("-h", "--help"):
    29         if o in ("-h", "--help"):
    29             usage()
    30             usage()
    30             sys.exit()
    31             sys.exit()
    31     
    32     
    32     if len(args) > 2:
    33     if len(args) != 3:
    33         usage()
    34         usage()
    34         sys.exit()
    35         sys.exit()
    35     elif len(args) == 1:
    36     else:
    36         projectOpen = args[0]
       
    37         buildpath = None
       
    38     elif len(args) == 2:
       
    39         projectOpen = args[0]
    37         projectOpen = args[0]
    40         buildpath = args[1]
    38         buildpath = args[1]
    41     else:
    39         try:
    42         projectOpen = None
    40             port = int(args[2])
    43         buildpath = None
    41         except:
    44     
    42             usage()
       
    43             sys.exit()
    45 
    44 
    46 app = wx.PySimpleApp()
    45 app = wx.PySimpleApp()
    47 app.SetAppName('beremiz')
    46 app.SetAppName('beremiz')
    48 wx.InitAllImageHandlers()
    47 wx.InitAllImageHandlers()
    49 
    48 
  1060                 self.GenerateLocationTreeBranch(locations_infos, "root", location)
  1059                 self.GenerateLocationTreeBranch(locations_infos, "root", location)
  1061             if not locations_infos["root"]["expanded"]:
  1060             if not locations_infos["root"]["expanded"]:
  1062                 self.CollapseLocation(locations_infos, "root")
  1061                 self.CollapseLocation(locations_infos, "root")
  1063 
  1062 
  1064 class StdoutPseudoFile:
  1063 class StdoutPseudoFile:
       
  1064     
       
  1065     def __init__(self, port):
       
  1066         self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
       
  1067         self.socket.connect(('localhost', port))
       
  1068     
       
  1069     def __del__(self):
       
  1070         self.socket.close()
       
  1071     
       
  1072     def readline(self):
       
  1073         return self.socket.recv(2048)
       
  1074     
  1065     """ Base class for file like objects to facilitate StdOut for the Shell."""
  1075     """ Base class for file like objects to facilitate StdOut for the Shell."""
  1066     def write(self, s, style = None):
  1076     def write(self, s, style = None):
  1067         if s != '':
  1077         if s != '':
  1068             print s
  1078             self.socket.send(s)
  1069         
  1079         
  1070     def write_warning(self, s):
  1080     def write_warning(self, s):
  1071         self.write(s)
  1081         self.write(s)
  1072 
  1082 
  1073     def write_error(self, s):
  1083     def write_error(self, s):
  1075 
  1085 
  1076     def flush(self):
  1086     def flush(self):
  1077         pass
  1087         pass
  1078     
  1088     
  1079     def isatty(self):
  1089     def isatty(self):
  1080         return false
  1090         return False
  1081 
  1091 
  1082 if __name__ == '__main__':
  1092 if __name__ == '__main__':
  1083     
  1093     
  1084     from threading import Thread, Timer, Semaphore
  1094     from threading import Thread, Timer, Semaphore
  1085     import cmd
  1095     import cmd
  1108         
  1118         
  1109         prompt = ""
  1119         prompt = ""
  1110         RefreshTimer = None
  1120         RefreshTimer = None
  1111         
  1121         
  1112         def __init__(self, PluginRoot, Log):
  1122         def __init__(self, PluginRoot, Log):
  1113             cmd.Cmd.__init__(self)
  1123             cmd.Cmd.__init__(self, stdin=Log, stdout=Log)
       
  1124             self.use_rawinput = False
  1114             self.Log = Log
  1125             self.Log = Log
  1115             self.PluginRoot = PluginRoot
  1126             self.PluginRoot = PluginRoot
  1116             
  1127             
  1117         def RestartTimer(self):
  1128         def RestartTimer(self):
  1118             if self.RefreshTimer is not None:
  1129             if self.RefreshTimer is not None:
  1167             self.RestartTimer()
  1178             self.RestartTimer()
  1168         
  1179         
  1169         def AddBus(self, iec_channel, name, icon=None):
  1180         def AddBus(self, iec_channel, name, icon=None):
  1170             for child in self.PluginRoot.IterChilds():
  1181             for child in self.PluginRoot.IterChilds():
  1171                 if child.BaseParams.getName() == name:
  1182                 if child.BaseParams.getName() == name:
  1172                     return "Error: A bus named %s already exists" % name
  1183                     return "Error: A bus named %s already exists\n" % name
  1173                 elif child.BaseParams.getIEC_Channel() == iec_channel:
  1184                 elif child.BaseParams.getIEC_Channel() == iec_channel:
  1174                     return "Error: A bus with IEC_channel %d already exists" % iec_channel
  1185                     return "Error: A bus with IEC_channel %d already exists\n" % iec_channel
  1175             bus = self.PluginRoot.PlugAddChild(name, "LPCBus", iec_channel)
  1186             bus = self.PluginRoot.PlugAddChild(name, "LPCBus", iec_channel)
  1176             if bus is None:
  1187             if bus is None:
  1177                 return "Error: Unable to create bus"
  1188                 return "Error: Unable to create bus\n"
  1178             bus.SetIcon(icon)
  1189             bus.SetIcon(icon)
  1179             self.RestartTimer()
  1190             self.RestartTimer()
  1180         
  1191         
  1181         def RenameBus(self, iec_channel, name):
  1192         def RenameBus(self, iec_channel, name):
  1182             bus = self.PluginRoot.GetChildByIECLocation((iec_channel,))
  1193             bus = self.PluginRoot.GetChildByIECLocation((iec_channel,))
  1183             if bus is None:
  1194             if bus is None:
  1184                 return "Error: No bus found"
  1195                 return "Error: No bus found\n"
  1185             for child in self.PluginRoot.IterChilds():
  1196             for child in self.PluginRoot.IterChilds():
  1186                 if child != bus and child.BaseParams.getName() == name:
  1197                 if child != bus and child.BaseParams.getName() == name:
  1187                     return "Error: A bus named %s already exists" % name
  1198                     return "Error: A bus named %s already exists\n" % name
  1188             bus.BaseParams.setName(name)
  1199             bus.BaseParams.setName(name)
  1189             self.RestartTimer()
  1200             self.RestartTimer()
  1190         
  1201         
  1191         def ChangeBusIECChannel(self, old_iec_channel, new_iec_channel):
  1202         def ChangeBusIECChannel(self, old_iec_channel, new_iec_channel):
  1192             bus = self.PluginRoot.GetChildByIECLocation((old_iec_channel,))
  1203             bus = self.PluginRoot.GetChildByIECLocation((old_iec_channel,))
  1193             if bus is None:
  1204             if bus is None:
  1194                 return "Error: No bus found"
  1205                 return "Error: No bus found\n"
  1195             for child in self.PluginRoot.IterChilds():
  1206             for child in self.PluginRoot.IterChilds():
  1196                 if child != bus and child.BaseParams.getIEC_Channel() == new_iec_channel:
  1207                 if child != bus and child.BaseParams.getIEC_Channel() == new_iec_channel:
  1197                     return "Error: A bus with IEC_channel %d already exists" % new_iec_channel
  1208                     return "Error: A bus with IEC_channel %d already exists\n" % new_iec_channel
  1198             if wx.GetApp() is None:
  1209             if wx.GetApp() is None:
  1199                 self.PluginRoot.UpdateProjectVariableLocation(str(old_iec_channel), 
  1210                 self.PluginRoot.UpdateProjectVariableLocation(str(old_iec_channel), 
  1200                                                               str(new_iec_channel))
  1211                                                               str(new_iec_channel))
  1201             else:
  1212             else:
  1202                 self.PluginRoot.UpdateProjectVariableLocation(
  1213                 self.PluginRoot.UpdateProjectVariableLocation(
  1206             self.RestartTimer()
  1217             self.RestartTimer()
  1207         
  1218         
  1208         def RemoveBus(self, iec_channel):
  1219         def RemoveBus(self, iec_channel):
  1209             bus = self.PluginRoot.GetChildByIECLocation((iec_channel,))
  1220             bus = self.PluginRoot.GetChildByIECLocation((iec_channel,))
  1210             if bus is None:
  1221             if bus is None:
  1211                 return "Error: No bus found"
  1222                 return "Error: No bus found\n"
  1212             self.PluginRoot.RemoveProjectVariableByFilter(str(iec_channel))
  1223             self.PluginRoot.RemoveProjectVariableByFilter(str(iec_channel))
  1213             self.PluginRoot.PluggedChilds["LPCBus"].remove(bus)
  1224             self.PluginRoot.PluggedChilds["LPCBus"].remove(bus)
  1214             self.RestartTimer()
  1225             self.RestartTimer()
  1215     
  1226     
  1216         def AddModule(self, parent, iec_channel, name, icon=None):
  1227         def AddModule(self, parent, iec_channel, name, icon=None):
  1217             module = self.PluginRoot.GetChildByIECLocation(parent)
  1228             module = self.PluginRoot.GetChildByIECLocation(parent)
  1218             if module is None:
  1229             if module is None:
  1219                 return "Error: No parent found"
  1230                 return "Error: No parent found\n"
  1220             for child in _GetModuleChildren(module):
  1231             for child in _GetModuleChildren(module):
  1221                 if child["name"] == name:
  1232                 if child["name"] == name:
  1222                     return "Error: A module named %s already exists" % name
  1233                     return "Error: A module named %s already exists\n" % name
  1223                 elif child["IEC_Channel"] == iec_channel:
  1234                 elif child["IEC_Channel"] == iec_channel:
  1224                     return "Error: A module with IEC_channel %d already exists" % iec_channel 
  1235                     return "Error: A module with IEC_channel %d already exists\n" % iec_channel 
  1225             _GetLastModuleGroup(module).append({"name": name, 
  1236             _GetLastModuleGroup(module).append({"name": name, 
  1226                                                 "type": LOCATION_MODULE, 
  1237                                                 "type": LOCATION_MODULE, 
  1227                                                 "IEC_Channel": iec_channel, 
  1238                                                 "IEC_Channel": iec_channel, 
  1228                                                 "icon": icon, 
  1239                                                 "icon": icon, 
  1229                                                 "children": []})
  1240                                                 "children": []})
  1230             self.RestartTimer()
  1241             self.RestartTimer()
  1231     
  1242     
  1232         def RenameModule(self, iec_location, name):
  1243         def RenameModule(self, iec_location, name):
  1233             module = self.PluginRoot.GetChildByIECLocation(iec_location)
  1244             module = self.PluginRoot.GetChildByIECLocation(iec_location)
  1234             if module is None:
  1245             if module is None:
  1235                 return "Error: No module found"
  1246                 return "Error: No module found\n"
  1236             parent = self.PluginRoot.GetChildByIECLocation(iec_location[:-1])
  1247             parent = self.PluginRoot.GetChildByIECLocation(iec_location[:-1])
  1237             if parent is self.PluginRoot:
  1248             if parent is self.PluginRoot:
  1238                 return "Error: No module found"
  1249                 return "Error: No module found\n"
  1239             if module["name"] != name:
  1250             if module["name"] != name:
  1240                 for child in _GetModuleChildren(parent):
  1251                 for child in _GetModuleChildren(parent):
  1241                     if child["name"] == name:
  1252                     if child["name"] == name:
  1242                         return "Error: A module named %s already exists" % name
  1253                         return "Error: A module named %s already exists\n" % name
  1243                 module["name"] = name
  1254                 module["name"] = name
  1244             self.RestartTimer()
  1255             self.RestartTimer()
  1245     
  1256     
  1246         def ChangeModuleIECChannel(self, old_iec_location, new_iec_channel):
  1257         def ChangeModuleIECChannel(self, old_iec_location, new_iec_channel):
  1247             module = self.PluginRoot.GetChildByIECLocation(old_iec_location)
  1258             module = self.PluginRoot.GetChildByIECLocation(old_iec_location)
  1248             if module is None:
  1259             if module is None:
  1249                 return "Error: No module found"
  1260                 return "Error: No module found\n"
  1250             parent = self.PluginRoot.GetChildByIECLocation(old_iec_location[:-1])
  1261             parent = self.PluginRoot.GetChildByIECLocation(old_iec_location[:-1])
  1251             if parent is self.PluginRoot:
  1262             if parent is self.PluginRoot:
  1252                 return "Error: No module found"
  1263                 return "Error: No module found\n"
  1253             if module["IEC_Channel"] != new_iec_channel:
  1264             if module["IEC_Channel"] != new_iec_channel:
  1254                 for child in _GetModuleChildren(parent):
  1265                 for child in _GetModuleChildren(parent):
  1255                     if child["IEC_Channel"] == new_iec_channel:
  1266                     if child["IEC_Channel"] == new_iec_channel:
  1256                         return "Error: A module with IEC_channel %d already exists" % new_iec_channel
  1267                         return "Error: A module with IEC_channel %d already exists\n" % new_iec_channel
  1257             self.PluginRoot.UpdateProjectVariableLocation(".".join(map(str, old_iec_location)), ".".join(map(str, old_iec_location[:1] + (new_iec_channel,))))
  1268             self.PluginRoot.UpdateProjectVariableLocation(".".join(map(str, old_iec_location)), ".".join(map(str, old_iec_location[:1] + (new_iec_channel,))))
  1258             module["IEC_Channel"] = new_iec_channel
  1269             module["IEC_Channel"] = new_iec_channel
  1259             self.RestartTimer()
  1270             self.RestartTimer()
  1260     
  1271     
  1261         def RemoveModule(self, parent, iec_channel):
  1272         def RemoveModule(self, parent, iec_channel):
  1262             module = self.PluginRoot.GetChildByIECLocation(parent)
  1273             module = self.PluginRoot.GetChildByIECLocation(parent)
  1263             if module is None:
  1274             if module is None:
  1264                 return "Error: No parent found"
  1275                 return "Error: No parent found\n"
  1265             child = _GetModuleBySomething(module, "IEC_Channel", (iec_channel,))
  1276             child = _GetModuleBySomething(module, "IEC_Channel", (iec_channel,))
  1266             if child is None:
  1277             if child is None:
  1267                 return "Error: No module found"
  1278                 return "Error: No module found\n"
  1268             self.PluginRoot.RemoveProjectVariableByFilter(".".join(map(str, parent + (iec_channel,))))
  1279             self.PluginRoot.RemoveProjectVariableByFilter(".".join(map(str, parent + (iec_channel,))))
  1269             _RemoveModuleChild(module, child)
  1280             _RemoveModuleChild(module, child)
  1270             self.RestartTimer()
  1281             self.RestartTimer()
  1271         
  1282         
  1272         def StartGroup(self, parent, name, icon=None):
  1283         def StartGroup(self, parent, name, icon=None):
  1273             module = self.PluginRoot.GetChildByIECLocation(parent)
  1284             module = self.PluginRoot.GetChildByIECLocation(parent)
  1274             if module is None:
  1285             if module is None:
  1275                 return "Error: No parent found"
  1286                 return "Error: No parent found\n"
  1276             for child in module["children"]:
  1287             for child in module["children"]:
  1277                 if child["type"] == LOCATION_GROUP and child["name"] == name:
  1288                 if child["type"] == LOCATION_GROUP and child["name"] == name:
  1278                     return "Error: A group named %s already exists" % name
  1289                     return "Error: A group named %s already exists\n" % name
  1279             module["children"].append({"name": name, 
  1290             module["children"].append({"name": name, 
  1280                                       "type": LOCATION_GROUP, 
  1291                                       "type": LOCATION_GROUP, 
  1281                                       "icon": icon, 
  1292                                       "icon": icon, 
  1282                                       "children": []})
  1293                                       "children": []})
  1283             self.RestartTimer()
  1294             self.RestartTimer()
  1284     
  1295     
  1285         def AddVariable(self, parent, location, name, direction, type, dcode, rcode, pcode, description=""):
  1296         def AddVariable(self, parent, location, name, direction, type, dcode, rcode, pcode, description=""):
  1286             module = self.PluginRoot.GetChildByIECLocation(parent)
  1297             module = self.PluginRoot.GetChildByIECLocation(parent)
  1287             if module is None:
  1298             if module is None:
  1288                 return "Error: No parent found"
  1299                 return "Error: No parent found\n"
  1289             for child in _GetModuleChildren(module):
  1300             for child in _GetModuleChildren(module):
  1290                 if child["name"] == name:
  1301                 if child["name"] == name:
  1291                     return "Error: A variable named %s already exists" % name
  1302                     return "Error: A variable named %s already exists\n" % name
  1292                 if child["location"] == location and child["type"] == LOCATION_TYPES[direction]:
  1303                 if child["location"] == location and child["type"] == LOCATION_TYPES[direction]:
  1293                     return "Error: A variable with location %s already exists" % ".".join(map(str, location))
  1304                     return "Error: A variable with location %s already exists\n" % ".".join(map(str, location))
  1294             _GetLastModuleGroup(module).append({"name": name, 
  1305             _GetLastModuleGroup(module).append({"name": name, 
  1295                                                 "location": location, 
  1306                                                 "location": location, 
  1296                                                 "type": LOCATION_TYPES[direction], 
  1307                                                 "type": LOCATION_TYPES[direction], 
  1297                                                 "IEC_type": type, 
  1308                                                 "IEC_type": type, 
  1298                                                 "description": description, 
  1309                                                 "description": description, 
  1302             self.RestartTimer()
  1313             self.RestartTimer()
  1303 
  1314 
  1304         def ChangeVariableParams(self, parent, location, new_name, new_direction, new_type, new_dcode, new_rcode, new_pcode, new_description=None):
  1315         def ChangeVariableParams(self, parent, location, new_name, new_direction, new_type, new_dcode, new_rcode, new_pcode, new_description=None):
  1305             module = self.PluginRoot.GetChildByIECLocation(parent)
  1316             module = self.PluginRoot.GetChildByIECLocation(parent)
  1306             if module is None:
  1317             if module is None:
  1307                 return "Error: No parent found"
  1318                 return "Error: No parent found\n"
  1308             variable = None
  1319             variable = None
  1309             for child in _GetModuleChildren(module):
  1320             for child in _GetModuleChildren(module):
  1310                 if child["location"] == location and child["type"] == LOCATION_TYPES[new_direction]:
  1321                 if child["location"] == location and child["type"] == LOCATION_TYPES[new_direction]:
  1311                     variable = child
  1322                     variable = child
  1312                 elif child["name"] == new_name:
  1323                 elif child["name"] == new_name:
  1313                     return "Error: A variable named %s already exists" % new_name
  1324                     return "Error: A variable named %s already exists\n" % new_name
  1314             if variable is None:
  1325             if variable is None:
  1315                 return "Error: No variable found"
  1326                 return "Error: No variable found\n"
  1316             if variable["name"] != new_name:
  1327             if variable["name"] != new_name:
  1317                 self.PluginRoot.UpdateProjectVariableName(variable["name"], new_name)
  1328                 self.PluginRoot.UpdateProjectVariableName(variable["name"], new_name)
  1318                 variable["name"] = new_name
  1329                 variable["name"] = new_name
  1319             variable["type"] = LOCATION_TYPES[new_direction]
  1330             variable["type"] = LOCATION_TYPES[new_direction]
  1320             variable["IEC_type"] = new_type
  1331             variable["IEC_type"] = new_type
  1326             self.RestartTimer()
  1337             self.RestartTimer()
  1327     
  1338     
  1328         def RemoveVariable(self, parent, location, direction):
  1339         def RemoveVariable(self, parent, location, direction):
  1329             module = self.PluginRoot.GetChildByIECLocation(parent)
  1340             module = self.PluginRoot.GetChildByIECLocation(parent)
  1330             if module is None:
  1341             if module is None:
  1331                 return "Error: No parent found"
  1342                 return "Error: No parent found\n"
  1332             child = _GetModuleVariable(module, location, direction)
  1343             child = _GetModuleVariable(module, location, direction)
  1333             if child is None:
  1344             if child is None:
  1334                 return "Error: No variable found"
  1345                 return "Error: No variable found\n"
  1335             size = LOCATION_SIZES[self.PluginRoot.GetBaseType(child["IEC_type"])]
  1346             size = LOCATION_SIZES[self.PluginRoot.GetBaseType(child["IEC_type"])]
  1336             address = "%" + LOCATION_DIRS[child["type"]] + size + ".".join(map(str, parent + location))
  1347             address = "%" + LOCATION_DIRS[child["type"]] + size + ".".join(map(str, parent + location))
  1337             self.PluginRoot.RemoveProjectVariableByAddress(address)
  1348             self.PluginRoot.RemoveProjectVariableByAddress(address)
  1338             _RemoveModuleChild(module, child)
  1349             _RemoveModuleChild(module, child)
  1339             self.RestartTimer()
  1350             self.RestartTimer()
  1344     def GetCmdFunction(function, arg_types, opt=0):
  1355     def GetCmdFunction(function, arg_types, opt=0):
  1345         arg_number = len(arg_types)
  1356         arg_number = len(arg_types)
  1346         def CmdFunction(self, line):
  1357         def CmdFunction(self, line):
  1347             args_toks = line.split('"')
  1358             args_toks = line.split('"')
  1348             if len(args_toks) % 2 == 0:
  1359             if len(args_toks) % 2 == 0:
  1349                 print "Error: Invalid command"
  1360                 self.Log.write("Error: Invalid command\n")
  1350                 sys.stdout.flush()
  1361                 sys.stdout.flush()
  1351                 return
  1362                 return
  1352             args = []
  1363             args = []
  1353             for num, arg in enumerate(args_toks):
  1364             for num, arg in enumerate(args_toks):
  1354                 if num % 2 == 0:
  1365                 if num % 2 == 0:
  1367             elif len(args) < arg_number - opt:
  1378             elif len(args) < arg_number - opt:
  1368                 number = arg_number - opt
  1379                 number = arg_number - opt
  1369                 extra = " at least"
  1380                 extra = " at least"
  1370             if number is not None:
  1381             if number is not None:
  1371                 if number == 0:
  1382                 if number == 0:
  1372                     print "Error: No argument%s expected" % extra
  1383                     self.Log.write("Error: No argument%s expected\n" % extra)
  1373                 elif number == 1:
  1384                 elif number == 1:
  1374                     print "Error: 1 argument%s expected" % extra
  1385                     self.Log.write("Error: 1 argument%s expected\n" % extra)
  1375                 else:
  1386                 else:
  1376                     print "Error: %d arguments%s expected" % (number, extra)
  1387                     self.Log.write("Error: %d arguments%s expected\n" % (number, extra))
  1377                 sys.stdout.flush()
  1388                 sys.stdout.flush()
  1378                 return
  1389                 return
  1379             for num, arg in enumerate(args):
  1390             for num, arg in enumerate(args):
  1380                 try:
  1391                 try:
  1381                     args[num] = arg_types[num](arg)
  1392                     args[num] = arg_types[num](arg)
  1382                 except:
  1393                 except:
  1383                     print "Error: Invalid value for argument %d" % (num + 1)
  1394                     self.Log.write("Error: Invalid value for argument %d\n" % (num + 1))
  1384                     sys.stdout.flush()
  1395                     sys.stdout.flush()
  1385                     return
  1396                     return
  1386 
  1397 
  1387             cmdlogf.write(str((function,line))+'\n')
  1398             cmdlogf.write(str((function,line))+'\n')
  1388 
  1399 
  1394             cmdlog.append((function,line,res))
  1405             cmdlog.append((function,line,res))
  1395             if len(cmdlog) > 100: #prevent debug log to grow too much
  1406             if len(cmdlog) > 100: #prevent debug log to grow too much
  1396                 cmdlog.pop(0) 
  1407                 cmdlog.pop(0) 
  1397 
  1408 
  1398             if isinstance(res, (StringType, UnicodeType)):
  1409             if isinstance(res, (StringType, UnicodeType)):
  1399                 print res
  1410                 self.Log.write(res)
  1400                 sys.stdout.flush()
       
  1401                 return False
  1411                 return False
  1402             else:
  1412             else:
  1403                 return res
  1413                 return res
  1404         return CmdFunction
  1414         return CmdFunction
  1405 
  1415 
  1427             
  1437             
  1428             setattr(LPCBeremiz_Cmd, "do_%s" % function, GetCmdFunction(function, arg_types, opt))
  1438             setattr(LPCBeremiz_Cmd, "do_%s" % function, GetCmdFunction(function, arg_types, opt))
  1429         lpcberemiz_cmd = LPCBeremiz_Cmd(PluginRoot, Log)
  1439         lpcberemiz_cmd = LPCBeremiz_Cmd(PluginRoot, Log)
  1430         lpcberemiz_cmd.cmdloop()
  1440         lpcberemiz_cmd.cmdloop()
  1431 
  1441 
  1432     Log = StdoutPseudoFile()
  1442     Log = StdoutPseudoFile(port)
  1433 
  1443 
  1434     PluginRoot = LPCPluginsRoot(None, Log)
  1444     PluginRoot = LPCPluginsRoot(None, Log)
  1435     if projectOpen is not None and os.path.isdir(projectOpen):
  1445     if projectOpen is not None and os.path.isdir(projectOpen):
  1436         result = PluginRoot.LoadProject(projectOpen, buildpath)
  1446         result = PluginRoot.LoadProject(projectOpen, buildpath)
  1437         if result:
  1447         if result:
  1438             print "Error: Invalid project directory", result
  1448             Log.write("Error: Invalid project directory", result)
  1439     else:
  1449     else:
  1440         print "Error: No such file or directory"
  1450         Log.write("Error: No such file or directory")
  1441     
  1451     
  1442     cmd_thread=Thread(target=CmdThreadProc, args=[PluginRoot, Log])
  1452     cmd_thread=Thread(target=CmdThreadProc, args=[PluginRoot, Log])
  1443     cmd_thread.start()
  1453     cmd_thread.start()
  1444 
  1454 
  1445     # Install a exception handle for bug reports
  1455     # Install a exception handle for bug reports