diff options
| author | Ritesh Raj Sarraf <[email protected]> | 2025-05-12 12:31:43 +0530 |
|---|---|---|
| committer | git-ubuntu importer <[email protected]> | 2025-05-12 10:36:24 +0000 |
| commit | 65d05b4fa356401807209210d0740781ea5eb029 (patch) | |
| tree | 2b505e163647b1dd22efa44e15bb4403a16f5b98 | |
| parent | 1f0f1fcbdf08e4d6f8caa6c929b84012b2882416 (diff) | |
| parent | 776213f3152bf431033e60d947115d1959669fd7 (diff) | |
1:2.0.0-2 (patches applied)applied/1%2.0.0-2applied/ubuntu/resolute-develapplied/ubuntu/resoluteapplied/ubuntu/questing-proposedapplied/ubuntu/questing-develapplied/ubuntu/questingapplied/ubuntu/develapplied/debian/sid
Imported using git-ubuntu import.
| -rw-r--r-- | configshell/shell.py | 72 | ||||
| -rw-r--r-- | debian/changelog | 6 | ||||
| -rw-r--r-- | debian/patches/configshell-path-expansion.patch | 132 | ||||
| -rw-r--r-- | debian/patches/series | 1 |
4 files changed, 188 insertions, 23 deletions
diff --git a/configshell/shell.py b/configshell/shell.py index bc9b6e1..51a7b91 100644 --- a/configshell/shell.py +++ b/configshell/shell.py @@ -128,8 +128,7 @@ class ConfigShell: parameter = kparam | pparam parameters = OneOrMore(parameter) bookmark = Regex('@([A-Za-z0-9:_.]|-)+') - pathstd = Regex(r'([A-Za-z0-9:_.\[\]]|-)*' + '/' + r'([A-Za-z0-9:_.\[\]/]|-)*') \ - | '..' | '.' + pathstd = Regex(r'([A-Za-z0-9:_.\[\]]|-)*' + '/' + r'([A-Za-z0-9:_.\[\]/]|-)*') | '..' | '.' path = locatedExpr(bookmark | pathstd | '*')('path') parser = Optional(path) + Optional(command) + Optional(parameters) self._parser = parser @@ -142,14 +141,30 @@ class ConfigShell: self.log = log.Log() if preferences_dir is not None: - preferences_dir_path = Path(preferences_dir) + try: + preferences_dir_path = Path(preferences_dir).expanduser() + except RuntimeError as e: + self.log.error( + f"Could not determine home directory for preferences '{preferences_dir}': {e}", + ) + preferences_dir = None + if not preferences_dir_path.exists(): - preferences_dir_path.mkdir(parents=True) - self._prefs_file = preferences_dir_path / 'prefs.bin' - self.prefs = prefs.Prefs(str(self._prefs_file)) - self._cmd_history = preferences_dir_path / '/history.txt' - self._save_history = True - cmd_history_path = self._cmd_history + try: + preferences_dir_path.mkdir(parents=True, exist_ok=True) + except OSError as e: + self.log.error( + f'Failed to create preferences directory {preferences_dir_path}: {e}', + ) + preferences_dir = None + + if preferences_dir: + self._prefs_file = preferences_dir_path / 'prefs.bin' + self.prefs = prefs.Prefs(str(self._prefs_file)) + self._cmd_history = preferences_dir_path / 'history.txt' + self._save_history = True + cmd_history_path = self._cmd_history + if not cmd_history_path.is_file(): try: with cmd_history_path.open('w'): @@ -159,16 +174,19 @@ class ConfigShell: f"command history will not be saved.") self._save_history = False - if self._cmd_history.is_file() and tty: - try: - readline.read_history_file(self._cmd_history) - except OSError: - self.log.warning(f"Cannot read command history file {self._cmd_history}.") + if self._cmd_history.is_file() and tty and self._save_history: + try: + readline.read_history_file(str(self._cmd_history)) + except (OSError, FileNotFoundError) as e: + self.log.warning( + f'Cannot read command history file {self._cmd_history}: {e}', + ) - if self.prefs['logfile'] is None: - self.prefs['logfile'] = preferences_dir + '/' + 'log.txt' + if self.prefs['logfile'] is None: + log_file_path = preferences_dir_path / 'log.txt' + self.prefs['logfile'] = str(log_file_path) - self.prefs.autosave = True + self.prefs.autosave = True else: self.prefs = prefs.Prefs() @@ -176,8 +194,8 @@ class ConfigShell: try: self.prefs.load() - except OSError: - self.log.warning(f"Could not load preferences file {self._prefs_file}.") + except (OSError, FileNotFoundError): + self.log.warning(f'Could not load preferences file {self._prefs_file}.') for pref, value in self.default_prefs.items(): if pref not in self.prefs: @@ -283,9 +301,11 @@ class ConfigShell: # No identified path yet on the command line, this might be it if not path: - path_completions = [child.name + '/' - for child in self._current_node.children - if child.name.startswith(text)] + path_completions = [ + child.name + '/' + for child in self._current_node.children + if child.name.startswith(text) + ] if not text: path_completions.append('/') if len(self._current_node.children) > 1: @@ -839,10 +859,16 @@ class ConfigShell: @param exit_on_error: If True, stops the run if an error occurs @type exit_on_error: bool ''' + script_file_path = None try: - with Path(script_path).open() as script_fd: + script_file_path = Path(script_path).expanduser() + with script_file_path.open() as script_fd: self.run_stdin(script_fd, exit_on_error) + except FileNotFoundError as e: + self.log.error(f'Script file not found: {script_file_path or script_path}') + raise FileNotFoundError(e) from e except OSError as e: + self.log.error(f'Error accessing script file {script_file_path or script_path}: {e}') raise OSError(e) def run_stdin(self, file_descriptor=sys.stdin, exit_on_error=True): diff --git a/debian/changelog b/debian/changelog index 5a0436f..a7b32b1 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +python-configshell-fb (1:2.0.0-2) unstable; urgency=high + + * Fix path not being expanded (Closes: 1104106) + + -- Ritesh Raj Sarraf <[email protected]> Mon, 12 May 2025 12:31:43 +0530 + python-configshell-fb (1:2.0.0-1) unstable; urgency=medium * Team upload diff --git a/debian/patches/configshell-path-expansion.patch b/debian/patches/configshell-path-expansion.patch new file mode 100644 index 0000000..85c7faf --- /dev/null +++ b/debian/patches/configshell-path-expansion.patch @@ -0,0 +1,132 @@ +From 8ec554a5951a7785c4c4368a5db6d15577a91281 Mon Sep 17 00:00:00 2001 +From: Martin Hoyer <[email protected]> +Date: Wed, 9 Apr 2025 21:36:44 +0200 +Subject: [PATCH] Fix path not being expanded + +--- + configshell/shell.py | 72 ++++++++++++++++++++++++++++++-------------- + 1 file changed, 49 insertions(+), 23 deletions(-) + +--- a/configshell/shell.py ++++ b/configshell/shell.py +@@ -128,8 +128,7 @@ + parameter = kparam | pparam + parameters = OneOrMore(parameter) + bookmark = Regex('@([A-Za-z0-9:_.]|-)+') +- pathstd = Regex(r'([A-Za-z0-9:_.\[\]]|-)*' + '/' + r'([A-Za-z0-9:_.\[\]/]|-)*') \ +- | '..' | '.' ++ pathstd = Regex(r'([A-Za-z0-9:_.\[\]]|-)*' + '/' + r'([A-Za-z0-9:_.\[\]/]|-)*') | '..' | '.' + path = locatedExpr(bookmark | pathstd | '*')('path') + parser = Optional(path) + Optional(command) + Optional(parameters) + self._parser = parser +@@ -142,14 +141,30 @@ + self.log = log.Log() + + if preferences_dir is not None: +- preferences_dir_path = Path(preferences_dir) ++ try: ++ preferences_dir_path = Path(preferences_dir).expanduser() ++ except RuntimeError as e: ++ self.log.error( ++ f"Could not determine home directory for preferences '{preferences_dir}': {e}", ++ ) ++ preferences_dir = None ++ + if not preferences_dir_path.exists(): +- preferences_dir_path.mkdir(parents=True) +- self._prefs_file = preferences_dir_path / 'prefs.bin' +- self.prefs = prefs.Prefs(str(self._prefs_file)) +- self._cmd_history = preferences_dir_path / '/history.txt' +- self._save_history = True +- cmd_history_path = self._cmd_history ++ try: ++ preferences_dir_path.mkdir(parents=True, exist_ok=True) ++ except OSError as e: ++ self.log.error( ++ f'Failed to create preferences directory {preferences_dir_path}: {e}', ++ ) ++ preferences_dir = None ++ ++ if preferences_dir: ++ self._prefs_file = preferences_dir_path / 'prefs.bin' ++ self.prefs = prefs.Prefs(str(self._prefs_file)) ++ self._cmd_history = preferences_dir_path / 'history.txt' ++ self._save_history = True ++ cmd_history_path = self._cmd_history ++ + if not cmd_history_path.is_file(): + try: + with cmd_history_path.open('w'): +@@ -159,16 +174,19 @@ + f"command history will not be saved.") + self._save_history = False + +- if self._cmd_history.is_file() and tty: +- try: +- readline.read_history_file(self._cmd_history) +- except OSError: +- self.log.warning(f"Cannot read command history file {self._cmd_history}.") +- +- if self.prefs['logfile'] is None: +- self.prefs['logfile'] = preferences_dir + '/' + 'log.txt' ++ if self._cmd_history.is_file() and tty and self._save_history: ++ try: ++ readline.read_history_file(str(self._cmd_history)) ++ except (OSError, FileNotFoundError) as e: ++ self.log.warning( ++ f'Cannot read command history file {self._cmd_history}: {e}', ++ ) ++ ++ if self.prefs['logfile'] is None: ++ log_file_path = preferences_dir_path / 'log.txt' ++ self.prefs['logfile'] = str(log_file_path) + +- self.prefs.autosave = True ++ self.prefs.autosave = True + + else: + self.prefs = prefs.Prefs() +@@ -176,8 +194,8 @@ + + try: + self.prefs.load() +- except OSError: +- self.log.warning(f"Could not load preferences file {self._prefs_file}.") ++ except (OSError, FileNotFoundError): ++ self.log.warning(f'Could not load preferences file {self._prefs_file}.') + + for pref, value in self.default_prefs.items(): + if pref not in self.prefs: +@@ -283,9 +301,11 @@ + + # No identified path yet on the command line, this might be it + if not path: +- path_completions = [child.name + '/' +- for child in self._current_node.children +- if child.name.startswith(text)] ++ path_completions = [ ++ child.name + '/' ++ for child in self._current_node.children ++ if child.name.startswith(text) ++ ] + if not text: + path_completions.append('/') + if len(self._current_node.children) > 1: +@@ -839,10 +859,16 @@ + @param exit_on_error: If True, stops the run if an error occurs + @type exit_on_error: bool + ''' ++ script_file_path = None + try: +- with Path(script_path).open() as script_fd: ++ script_file_path = Path(script_path).expanduser() ++ with script_file_path.open() as script_fd: + self.run_stdin(script_fd, exit_on_error) ++ except FileNotFoundError as e: ++ self.log.error(f'Script file not found: {script_file_path or script_path}') ++ raise FileNotFoundError(e) from e + except OSError as e: ++ self.log.error(f'Error accessing script file {script_file_path or script_path}: {e}') + raise OSError(e) + + def run_stdin(self, file_descriptor=sys.stdin, exit_on_error=True): diff --git a/debian/patches/series b/debian/patches/series new file mode 100644 index 0000000..99a16a6 --- /dev/null +++ b/debian/patches/series @@ -0,0 +1 @@ +configshell-path-expansion.patch |
