IDE: Add -l or --log command line parameter to give a file where all content witten to console window will be appended. File can be /dev/stdout. wxPython4
authorEdouard Tisserant <edouard.tisserant@gmail.com>
Sun, 13 Feb 2022 20:53:00 +0100
branchwxPython4
changeset 3423 84afcc0ebadd
parent 3422 700b39cb4525
child 3424 7db96e011fe7
IDE: Add -l or --log command line parameter to give a file where all content witten to console window will be appended. File can be /dev/stdout.
Beremiz.py
BeremizIDE.py
--- a/Beremiz.py	Wed Feb 02 20:27:17 2022 +0100
+++ b/Beremiz.py	Sun Feb 13 20:53:00 2022 +0100
@@ -50,6 +50,7 @@
         self.modules = ["BeremizIDE"]
         self.debug = os.path.exists("BEREMIZ_DEBUG")
         self.handle_exception = None
+        self.logf = None
 
     def Bpath(self, *args):
         return os.path.join(self.app_dir, *args)
@@ -62,12 +63,13 @@
         print("-h --help                    Print this help")
         print("-u --updatecheck URL         Retrieve update information by checking URL")
         print("-e --extend PathToExtension  Extend IDE functionality by loading at start additional extensions")
+        print("-l --log path                write content of console tab to given file")
         print("")
         print("")
 
     def SetCmdOptions(self):
-        self.shortCmdOpts = "hu:e:"
-        self.longCmdOpts = ["help", "updatecheck=", "extend="]
+        self.shortCmdOpts = "hu:e:l:"
+        self.longCmdOpts = ["help", "updatecheck=", "extend=", "log="]
 
     def ProcessOption(self, o, a):
         if o in ("-h", "--help"):
@@ -77,6 +79,8 @@
             self.updateinfo_url = a
         if o in ("-e", "--extend"):
             self.extensions.append(a)
+        if o in ("-l", "--log"):
+            self.logf = open(a, 'a')
 
     def ProcessCommandLineArgs(self):
         self.SetCmdOptions()
@@ -185,7 +189,7 @@
         self.handle_exception = util.ExceptionHandler.AddExceptHook(version.app_version)
 
     def CreateUI(self):
-        self.frame = self.BeremizIDE.Beremiz(None, self.projectOpen, self.buildpath)
+        self.frame = self.BeremizIDE.Beremiz(None, self.projectOpen, self.buildpath, logf=self.logf)
 
     def CloseSplash(self):
         if self.splash:
--- a/BeremizIDE.py	Wed Feb 02 20:27:17 2022 +0100
+++ b/BeremizIDE.py	Sun Feb 13 20:53:00 2022 +0100
@@ -115,7 +115,7 @@
 
 class LogPseudoFile(object):
     """ Base class for file like objects to facilitate StdOut for the Shell."""
-    def __init__(self, output, risecall):
+    def __init__(self, output, risecall, logf):
         self.red_white = 1
         self.red_yellow = 2
         self.black_white = wx.stc.STC_STYLE_DEFAULT
@@ -131,8 +131,11 @@
         self.LastRefreshTime = gettime()
         self.LastRefreshTimer = None
         self.refreshPending = False
+        self.logf = logf
 
     def write(self, s, style=None):
+        if self.logf is not None:
+            self.logf.write(s)
         self.StackLock.acquire()
         self.stack.append((s, style))
         self.StackLock.release()
@@ -436,13 +439,13 @@
             # found here.
             os.environ["PATH"] = os.getcwd()+';'+os.environ["PATH"]
 
-    def __init__(self, parent, projectOpen=None, buildpath=None, ctr=None, debug=True):
+    def __init__(self, parent, projectOpen=None, buildpath=None, ctr=None, debug=True, logf=None):
         # Add beremiz's icon in top left corner of the frame
         self.icon = wx.Icon(Bpath("images", "brz.ico"), wx.BITMAP_TYPE_ICO)
         self.__init_execute_path()
 
         IDEFrame.__init__(self, parent, debug)
-        self.Log = LogPseudoFile(self.LogConsole, self.SelectTab)
+        self.Log = LogPseudoFile(self.LogConsole, self.SelectTab, logf)
 
         self.local_runtime = None
         self.runtime_port = None