From 09eb4e008b41f2cf59743311b96ac1288f5dbdac Mon Sep 17 00:00:00 2001 From: Phil Downey Date: Thu, 29 May 2025 10:02:29 +1000 Subject: [PATCH 01/15] limit commnd history string length --- openad/app/main.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/openad/app/main.py b/openad/app/main.py index 578ad34b..dce34e40 100644 --- a/openad/app/main.py +++ b/openad/app/main.py @@ -528,7 +528,8 @@ def postloop(self): def add_history(self, inp): """CMD class called function: adds history file""" - readline.add_history(inp) + if (inp.strip()) < 4096: + readline.add_history(inp) def complete(self, text, state): """CMD class called function: @@ -1105,7 +1106,8 @@ def api_remote( # Note, may be possible add code completion here #revisit else: magic_prompt.preloop() - magic_prompt.add_history(inp) + if len(inp.strip()) < 4096: + magic_prompt.add_history(inp.strip()) magic_prompt.postloop() readline.write_history_file(magic_prompt.histfile) @@ -1170,8 +1172,10 @@ def cmd_line(): command_line.settings["workspace"] == words[1 + word_increment].upper() and command_line.settings["context"] == words[2 + word_increment].upper() ): + command_line.preloop() - command_line.add_history(str(" ".join(words[3 + word_increment :])).strip()) + if len(str(" ".join(words[3 + word_increment :])).strip()) < 4096: + command_line.add_history(str(" ".join(words[3 + word_increment :])).strip()) command_line.postloop() result = command_line.default(str(" ".join(words[3 + word_increment :])).strip()) else: @@ -1179,7 +1183,8 @@ def cmd_line(): # Note, may be possible add code completion here #revisit command_line.preloop() - command_line.add_history(inp[+increment:].strip()) + if len(inp[+increment:].strip()) < 4096: + command_line.add_history(inp[+increment:].strip()) command_line.postloop() result = command_line.default(inp[+increment:].strip()) command_line.do_exit("dummy do not remove") From b4a71412a1b5163c2c8878fa3d09fa5e3585c4a9 Mon Sep 17 00:00:00 2001 From: Phil Downey Date: Thu, 29 May 2025 10:05:24 +1000 Subject: [PATCH 02/15] limit commnd history string length --- openad/app/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openad/app/main.py b/openad/app/main.py index dce34e40..97822617 100644 --- a/openad/app/main.py +++ b/openad/app/main.py @@ -528,7 +528,7 @@ def postloop(self): def add_history(self, inp): """CMD class called function: adds history file""" - if (inp.strip()) < 4096: + if len(inp.strip()) < 4096: readline.add_history(inp) def complete(self, text, state): From d447314d888683ca1681e0cc013a1224f3dafec7 Mon Sep 17 00:00:00 2001 From: Phil Downey Date: Thu, 29 May 2025 10:13:34 +1000 Subject: [PATCH 03/15] limit commnd history string length --- openad/app/main.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/openad/app/main.py b/openad/app/main.py index 97822617..06289760 100644 --- a/openad/app/main.py +++ b/openad/app/main.py @@ -528,8 +528,8 @@ def postloop(self): def add_history(self, inp): """CMD class called function: adds history file""" - if len(inp.strip()) < 4096: - readline.add_history(inp) + if len(str(str(inp).strip())) < 4096: + readline.add_history(str(str(inp).strip())) def complete(self, text, state): """CMD class called function: @@ -1106,8 +1106,8 @@ def api_remote( # Note, may be possible add code completion here #revisit else: magic_prompt.preloop() - if len(inp.strip()) < 4096: - magic_prompt.add_history(inp.strip()) + if len(str(inp.strip())) < 4096: + magic_prompt.add_history(inp) magic_prompt.postloop() readline.write_history_file(magic_prompt.histfile) From 037c2931f6afb8f59f56d70a0abfd2fed5c67a0d Mon Sep 17 00:00:00 2001 From: Phil Downey Date: Thu, 29 May 2025 10:19:05 +1000 Subject: [PATCH 04/15] limit commnd history string length --- openad/app/main.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/openad/app/main.py b/openad/app/main.py index 06289760..a2a123a3 100644 --- a/openad/app/main.py +++ b/openad/app/main.py @@ -528,7 +528,8 @@ def postloop(self): def add_history(self, inp): """CMD class called function: adds history file""" - if len(str(str(inp).strip())) < 4096: + inp - str(inp) + if len(str(str(inp).strip())) < int(4096): readline.add_history(str(str(inp).strip())) def complete(self, text, state): @@ -1106,7 +1107,7 @@ def api_remote( # Note, may be possible add code completion here #revisit else: magic_prompt.preloop() - if len(str(inp.strip())) < 4096: + if len(str(inp.strip())) < int(4096): magic_prompt.add_history(inp) magic_prompt.postloop() readline.write_history_file(magic_prompt.histfile) @@ -1174,7 +1175,7 @@ def cmd_line(): ): command_line.preloop() - if len(str(" ".join(words[3 + word_increment :])).strip()) < 4096: + if len(str(" ".join(words[3 + word_increment :])).strip()) < int(4096): command_line.add_history(str(" ".join(words[3 + word_increment :])).strip()) command_line.postloop() result = command_line.default(str(" ".join(words[3 + word_increment :])).strip()) @@ -1183,7 +1184,7 @@ def cmd_line(): # Note, may be possible add code completion here #revisit command_line.preloop() - if len(inp[+increment:].strip()) < 4096: + if len(inp[+increment:].strip()) < int(4096): command_line.add_history(inp[+increment:].strip()) command_line.postloop() result = command_line.default(inp[+increment:].strip()) From 5ff3e161e2049b43751c6eecb82f904869fbc931 Mon Sep 17 00:00:00 2001 From: Phil Downey Date: Thu, 29 May 2025 10:27:38 +1000 Subject: [PATCH 05/15] limit commnd history string length --- openad/app/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openad/app/main.py b/openad/app/main.py index a2a123a3..b16947e4 100644 --- a/openad/app/main.py +++ b/openad/app/main.py @@ -528,7 +528,7 @@ def postloop(self): def add_history(self, inp): """CMD class called function: adds history file""" - inp - str(inp) + inp = str(inp) if len(str(str(inp).strip())) < int(4096): readline.add_history(str(str(inp).strip())) From d3bdd172b2bc1feb0426441ff071e755f7fef46d Mon Sep 17 00:00:00 2001 From: Phil Downey Date: Thu, 29 May 2025 10:49:22 +1000 Subject: [PATCH 06/15] limit commnd history string length --- openad/app/main.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/openad/app/main.py b/openad/app/main.py index b16947e4..00502613 100644 --- a/openad/app/main.py +++ b/openad/app/main.py @@ -524,7 +524,10 @@ def preloop(self): def postloop(self): """CMD class called function: Post loop is called by cmd to get an update the history file""" readline.set_history_length(self.histfile_size) - readline.write_history_file(self.histfile) + try: + readline.write_history_file(self.histfile) + except: + print(readline.get_current_history_length) def add_history(self, inp): """CMD class called function: adds history file""" @@ -1110,7 +1113,8 @@ def api_remote( if len(str(inp.strip())) < int(4096): magic_prompt.add_history(inp) magic_prompt.postloop() - readline.write_history_file(magic_prompt.histfile) + # Not required as post loop writes history file + # readline.write_history_file(magic_prompt.histfile) result = magic_prompt.default(inp) From fab1aa4f1cf32cd98b9c982545a0c58b7674f5e5 Mon Sep 17 00:00:00 2001 From: Phil Downey Date: Thu, 29 May 2025 10:52:05 +1000 Subject: [PATCH 07/15] limit commnd history string length --- openad/app/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openad/app/main.py b/openad/app/main.py index 00502613..51baee25 100644 --- a/openad/app/main.py +++ b/openad/app/main.py @@ -527,7 +527,7 @@ def postloop(self): try: readline.write_history_file(self.histfile) except: - print(readline.get_current_history_length) + print(readline.get_current_history_length()) def add_history(self, inp): """CMD class called function: adds history file""" From dd8154282527015d35a3edc13a3bea15bb4d68ac Mon Sep 17 00:00:00 2001 From: Phil Downey Date: Thu, 29 May 2025 11:04:17 +1000 Subject: [PATCH 08/15] catch os error and reset history --- openad/app/main.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/openad/app/main.py b/openad/app/main.py index 51baee25..c4fe20c6 100644 --- a/openad/app/main.py +++ b/openad/app/main.py @@ -519,6 +519,8 @@ def preloop(self): # >> create new workspace foobar # >> ctrl+c # (Reboot) + print(readline.get_current_history_length()) + readline.clear_history() readline.write_history_file(self.histfile) def postloop(self): @@ -528,10 +530,13 @@ def postloop(self): readline.write_history_file(self.histfile) except: print(readline.get_current_history_length()) + readline.clear_history() + readline.write_history_file(self.histfile) def add_history(self, inp): """CMD class called function: adds history file""" inp = str(inp) + if len(str(str(inp).strip())) < int(4096): readline.add_history(str(str(inp).strip())) From 0dbe0356944363ab48c79e5acd413d781270f088 Mon Sep 17 00:00:00 2001 From: Phil Downey Date: Thu, 29 May 2025 11:05:03 +1000 Subject: [PATCH 09/15] catch os error and reset history --- openad/app/main.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/openad/app/main.py b/openad/app/main.py index c4fe20c6..1f2d68c3 100644 --- a/openad/app/main.py +++ b/openad/app/main.py @@ -519,8 +519,6 @@ def preloop(self): # >> create new workspace foobar # >> ctrl+c # (Reboot) - print(readline.get_current_history_length()) - readline.clear_history() readline.write_history_file(self.histfile) def postloop(self): From 74f165abdb28f82e67c2a2e82c526b7bd85b746f Mon Sep 17 00:00:00 2001 From: Phil Downey Date: Thu, 29 May 2025 11:15:42 +1000 Subject: [PATCH 10/15] catch os error and reset history --- openad/app/main.py | 1 + 1 file changed, 1 insertion(+) diff --git a/openad/app/main.py b/openad/app/main.py index 1f2d68c3..f568adcd 100644 --- a/openad/app/main.py +++ b/openad/app/main.py @@ -519,6 +519,7 @@ def preloop(self): # >> create new workspace foobar # >> ctrl+c # (Reboot) + readline.set_history_length(self.histfile_size) readline.write_history_file(self.histfile) def postloop(self): From 193caaa2a9ab0d6e25442098fef1ee495263f981 Mon Sep 17 00:00:00 2001 From: Phil Downey Date: Thu, 29 May 2025 11:32:00 +1000 Subject: [PATCH 11/15] catch os error and reset history --- openad/app/main.py | 1 + 1 file changed, 1 insertion(+) diff --git a/openad/app/main.py b/openad/app/main.py index f568adcd..2af11e73 100644 --- a/openad/app/main.py +++ b/openad/app/main.py @@ -519,6 +519,7 @@ def preloop(self): # >> create new workspace foobar # >> ctrl+c # (Reboot) + print(readline.get_current_history_length()) readline.set_history_length(self.histfile_size) readline.write_history_file(self.histfile) From 7518b0a2a5ffe8b8384798fae0d7c44091c0ea08 Mon Sep 17 00:00:00 2001 From: Phil Downey Date: Thu, 29 May 2025 15:53:13 +1000 Subject: [PATCH 12/15] clear history before reading --- openad/core/lang_workspaces.py | 1 + 1 file changed, 1 insertion(+) diff --git a/openad/core/lang_workspaces.py b/openad/core/lang_workspaces.py index aa34894e..421fe1bf 100644 --- a/openad/core/lang_workspaces.py +++ b/openad/core/lang_workspaces.py @@ -37,6 +37,7 @@ def set_workspace(cmd_pointer, parser): try: # Open history file if not corrupt if readline and os.path.exists(cmd_pointer.histfile): + readline.clear_history() readline.read_history_file(cmd_pointer.histfile) except Exception: readline.write_history_file(cmd_pointer.histfile) From 48be695f94eb88c6164be6c8b43f51abe6c114a6 Mon Sep 17 00:00:00 2001 From: Phil Downey Date: Thu, 29 May 2025 16:19:12 +1000 Subject: [PATCH 13/15] ensure history file length is set --- openad/app/main.py | 6 ++++++ openad/core/lang_runs.py | 1 + openad/core/lang_workspaces.py | 6 +++++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/openad/app/main.py b/openad/app/main.py index 2af11e73..3899e451 100644 --- a/openad/app/main.py +++ b/openad/app/main.py @@ -511,6 +511,7 @@ def preloop(self): if readline and os.path.exists(self.histfile): # note history files can get corrupted so using try to compensate try: + readline.clear_history() readline.read_history_file(self.histfile) except Exception: # pylint: disable=broad-exception-caught # do not need to know exception # Create history file in case it doesn't exist yet. @@ -527,10 +528,13 @@ def postloop(self): """CMD class called function: Post loop is called by cmd to get an update the history file""" readline.set_history_length(self.histfile_size) try: + readline.read_history_file(self.histfile) + readline.set_history_length(self.histfile_size) readline.write_history_file(self.histfile) except: print(readline.get_current_history_length()) readline.clear_history() + readline.set_history_length(self.histfile_size) readline.write_history_file(self.histfile) def add_history(self, inp): @@ -1079,10 +1083,12 @@ def api_remote( # We now manage history. The history sometimes gets corrupted through no fault of ours. # If so, we just reset it. try: + readline.clear_history() readline.read_history_file(magic_prompt.histfile) except Exception: # pylint: disable=broad-exception-caught # could be a number of errors readline.add_history("") readline.write_history_file(magic_prompt.histfile) + readline.clear_history() readline.read_history_file(magic_prompt.histfile) for i in arguments: inp = inp + a_space + i diff --git a/openad/core/lang_runs.py b/openad/core/lang_runs.py index 9efdb838..27232165 100644 --- a/openad/core/lang_runs.py +++ b/openad/core/lang_runs.py @@ -23,6 +23,7 @@ def _create_workspace_dir_if_nonexistent(cmd_pointer, dir_name): def save_run(cmd_pointer, parser): """Saves a Run""" _create_workspace_dir_if_nonexistent(cmd_pointer, "_runs") + readline.set_history_length(self.histfile_size) readline.write_history_file(cmd_pointer.histfile) # f =_meta_workspaces+'/'+ cmd_pointer.settings['workspace'].upper()+'/.cmd_history' diff --git a/openad/core/lang_workspaces.py b/openad/core/lang_workspaces.py index 421fe1bf..10862482 100644 --- a/openad/core/lang_workspaces.py +++ b/openad/core/lang_workspaces.py @@ -21,6 +21,7 @@ # Sets the current workspace from the fgiven workspaces available def set_workspace(cmd_pointer, parser): """Sets the current Workspace""" + readline.set_history_length(cmd_pointer.histfile_size) readline.write_history_file(cmd_pointer.histfile) current_workspace_name = cmd_pointer.settings["workspace"].upper() new_workspace_name = parser["Workspace_Name"].upper() @@ -40,8 +41,9 @@ def set_workspace(cmd_pointer, parser): readline.clear_history() readline.read_history_file(cmd_pointer.histfile) except Exception: + readline.set_history_length(cmd_pointer.histfile_size) readline.write_history_file(cmd_pointer.histfile) - + readline.set_history_length(cmd_pointer.histfile_size) readline.write_history_file(cmd_pointer.histfile) return output_success(msg("success_workspace_set", new_workspace_name)) @@ -133,6 +135,7 @@ def remove_workspace(cmd_pointer, parser): def create_workspace(cmd_pointer, parser): """Creates a Workspace""" # Make sure existing workspace history file is saved. + readline.set_history_length(cmd_pointer.histfile_size) readline.write_history_file(cmd_pointer.histfile) cmd_pointer.refresh_vector = True cmd_pointer.refresh_train = True @@ -208,6 +211,7 @@ def create_workspace(cmd_pointer, parser): write_registry(cmd_pointer.settings, cmd_pointer) readline.clear_history() + readline.set_history_length(cmd_pointer.histfile_size) readline.write_history_file(cmd_pointer.histfile) # raise ValueError('This is a test error.\n') @later this causes the app to break permamenently. except Exception as err: From 96ee5d61b379c969917e68d48acf3c04daec0bec Mon Sep 17 00:00:00 2001 From: Phil Downey Date: Thu, 29 May 2025 16:33:14 +1000 Subject: [PATCH 14/15] ensure history file length is set --- openad/app/main.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/openad/app/main.py b/openad/app/main.py index 3899e451..1b2bd0e1 100644 --- a/openad/app/main.py +++ b/openad/app/main.py @@ -1082,14 +1082,14 @@ def api_remote( magic_prompt.api_variables = api_var_list # We now manage history. The history sometimes gets corrupted through no fault of ours. # If so, we just reset it. - try: - readline.clear_history() - readline.read_history_file(magic_prompt.histfile) - except Exception: # pylint: disable=broad-exception-caught # could be a number of errors - readline.add_history("") - readline.write_history_file(magic_prompt.histfile) - readline.clear_history() - readline.read_history_file(magic_prompt.histfile) + # try: + # readline.clear_history() + # readline.read_history_file(magic_prompt.histfile) + # except Exception: # pylint: disable=broad-exception-caught # could be a number of errors + # readline.add_history("") + # readline.write_history_file(magic_prompt.histfile) + # readline.clear_history() + # readline.read_history_file(magic_prompt.histfile) for i in arguments: inp = inp + a_space + i a_space = " " From 32ed90aab6d3f9f18aeac7a9369a52f1a7c3e1fd Mon Sep 17 00:00:00 2001 From: Phil Downey Date: Thu, 29 May 2025 16:43:25 +1000 Subject: [PATCH 15/15] ensure history file length is set --- openad/core/lang_workspaces.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/openad/core/lang_workspaces.py b/openad/core/lang_workspaces.py index 10862482..1f67152a 100644 --- a/openad/core/lang_workspaces.py +++ b/openad/core/lang_workspaces.py @@ -34,8 +34,6 @@ def set_workspace(cmd_pointer, parser): cmd_pointer.settings["workspace"] = new_workspace_name write_registry(cmd_pointer.settings, cmd_pointer) cmd_pointer.histfile = os.path.expanduser(cmd_pointer.workspace_path(new_workspace_name) + "/.cmd_history") - readline.clear_history() - try: # Open history file if not corrupt if readline and os.path.exists(cmd_pointer.histfile): readline.clear_history() @@ -210,7 +208,6 @@ def create_workspace(cmd_pointer, parser): write_registry(cmd_pointer.settings, cmd_pointer, True) write_registry(cmd_pointer.settings, cmd_pointer) - readline.clear_history() readline.set_history_length(cmd_pointer.histfile_size) readline.write_history_file(cmd_pointer.histfile) # raise ValueError('This is a test error.\n') @later this causes the app to break permamenently.