From 90f28a6781c6130b02643269619e747c503357ce Mon Sep 17 00:00:00 2001 From: Bill Dolinar Date: Tue, 15 Aug 2023 12:16:29 -0600 Subject: [PATCH] Updated documentation. --- _package/tests/unit_tests/filesystem_pyt.py | 2 +- _package/xms/core/filesystem/filesystem.py | 10 +- _package/xms/core/misc/observer.py | 132 ++++++++++---------- _package/xms/core/misc/progress_listener.py | 28 +++-- 4 files changed, 87 insertions(+), 85 deletions(-) diff --git a/_package/tests/unit_tests/filesystem_pyt.py b/_package/tests/unit_tests/filesystem_pyt.py index e5bf0eb26..ed832653d 100644 --- a/_package/tests/unit_tests/filesystem_pyt.py +++ b/_package/tests/unit_tests/filesystem_pyt.py @@ -41,7 +41,7 @@ def test_temp_filename(self): # With dir arg d = tempfile.mkdtemp() - f = filesystem.temp_filename(dir=d) + f = filesystem.temp_filename(directory=d) self.assertEqual(os.path.normpath(os.path.dirname(f)), os.path.normpath(d)) # With suffix arg diff --git a/_package/xms/core/filesystem/filesystem.py b/_package/xms/core/filesystem/filesystem.py index 6a713e0c9..a967c383a 100644 --- a/_package/xms/core/filesystem/filesystem.py +++ b/_package/xms/core/filesystem/filesystem.py @@ -87,7 +87,7 @@ def removefile(filename): """ try: os.remove(filename) - except Exception: + except OSError: pass @@ -186,19 +186,19 @@ def file_prefix(filepath): return os.path.splitext(basename)[0] -def temp_filename(dir='', suffix=''): +def temp_filename(directory='', suffix=''): """Returns a temporary filename, in the XMS temp directory by default. Args: - dir: If provided, filename will be in the directory. Otherwise it will be in the + directory: If provided, filename will be in the directory. Otherwise it will be in the system temp directory. suffix: The suffix to use for the file. You must include a '.' if you want it to be an extension. Returns: See description. """ - if dir: # If we call the next line with dir == '', it seems to use the working directory. - file = tempfile.NamedTemporaryFile(mode='wt', suffix=suffix, dir=dir, delete=True) + if directory: # If we call the next line with dir == '', it seems to use the working directory. + file = tempfile.NamedTemporaryFile(mode='wt', suffix=suffix, dir=directory, delete=True) else: xms_temp = os.environ.get('XMS_PYTHON_APP_TEMP_DIRECTORY', 'unknown') if xms_temp != 'unknown': diff --git a/_package/xms/core/misc/observer.py b/_package/xms/core/misc/observer.py index 66f23880a..2bb9065a9 100644 --- a/_package/xms/core/misc/observer.py +++ b/_package/xms/core/misc/observer.py @@ -1,66 +1,66 @@ -""" -The Observer class for the xms.core library. -""" -from .._xmscore.misc import Observer as Obs - - -class Observer(Obs): - """ - Mock Observer class for testing. - """ - def __init__(self): - """ - The __init__ function for the Observer class. - """ - super(Observer, self).__init__() - - def on_progress_status(self, percent_complete): - """ - Captures the progress of an operation. - - Args: - percent_complete (float): The percent complete - """ - self.on_progress_status(percent_complete) - - def on_begin_operation_string(self, operation): - """ - The operation string. - - Args: - operation: Name of the operation being monitored. - """ - self.on_begin_operation_string(operation) - - def on_end_operation(self): - """ - The end operation event. - """ - self.on_end_operation() - - def on_update_message(self, message): - """ - When update message has been sent. - - Args: - message: The new message - """ - self.on_update_message(message) - - def time_remaining_in_seconds(self, remaining_seconds): - """ - Sets the time remaining in seconds. - - Args: - remaining_seconds (Float): The time remaining for the current operation that the class is observing. - """ - self.time_remaining_in_seconds(remaining_seconds) - - def time_elapsed_in_seconds(self, elapsed_seconds): - """ - Sets the time elapsed since the operation began. - - Args: - elapsed_seconds (Float): The elapsed time since the operation began. - """ - self.time_elapsed_in_seconds(elapsed_seconds) +""" +The Observer class for the xms.core library. +""" +from .._xmscore.misc import Observer as Obs + + +class Observer(Obs): + """ + Mock Observer class for testing. + """ + def __init__(self): + """ + The constructor. + """ + super(Observer, self).__init__() + + def on_progress_status(self, percent_complete: float): + """ + Captures the progress of an operation. + + Args: + percent_complete: The percentage complete. + """ + super(Observer, self).on_progress_status(percent_complete) + + def on_begin_operation_string(self, operation: str): + """ + Called when an operation begins. + + Args: + operation: Name of the operation being monitored. + """ + super(Observer, self).on_begin_operation_string(operation) + + def on_end_operation(self): + """ + Called when an operation ends. + """ + super(Observer, self).on_end_operation() + + def on_update_message(self, message): + """ + When update message has been sent. + + Args: + message: The new message + """ + super(Observer, self).on_update_message(message) + + def time_remaining_in_seconds(self, remaining_seconds): + """ + Sets the time remaining in seconds. + + Args: + remaining_seconds (Float): The time remaining for the current operation that the class is observing. + """ + super(Observer, self).time_remaining_in_seconds(remaining_seconds) + + def time_elapsed_in_seconds(self, elapsed_seconds): + """ + Sets the time elapsed since the operation began. + + Args: + elapsed_seconds (Float): The elapsed time since the operation began. + """ + super(Observer, self).time_elapsed_in_seconds(elapsed_seconds) diff --git a/_package/xms/core/misc/progress_listener.py b/_package/xms/core/misc/progress_listener.py index f62e2175f..55f66d1b8 100644 --- a/_package/xms/core/misc/progress_listener.py +++ b/_package/xms/core/misc/progress_listener.py @@ -1,17 +1,19 @@ """ -The Observer class for the xms.core library. +The ProgressListener class for the xms.core library. """ +from typing import Callable + from .._xmscore.misc import ProgressListener as Prog -def set_listener_callback(call_back): +def set_listener_callback(call_back: Callable[[str, int, str], None]) -> "ProgressListener": """Sets a call back method that is called by the progress listener class. Args: call_back (callable): takes a tuple (string, int, string) (msg_type, stack_index, message) Returns: - (ProgressListener): this class with the call back set + A ProgressListener with the call back set. """ p = ProgressListener() p.call_back = call_back @@ -28,27 +30,27 @@ def __init__(self): """ super().__init__() - def set_update_delay_seconds(self, delay): + def set_update_delay_seconds(self, delay: int): """ Sets the time to delay messages in seconds. Args: - delay (int): time to delay in seconds + delay: time to delay in seconds """ super().set_update_delay_seconds(delay) - def on_progress_status(self, stack_index, percent_complete): + def on_progress_status(self, stack_index: int, percent_complete: float): """ - Captures the progress of an operation. + Called to update the progress status. Args: - stack_index (int): stack index for the progress - percent_complete (float): The percent complete + stack_index: stack index for the progress + percent_complete: The percent complete """ msg = f'Percent complete {int(100 * percent_complete)}' self.call_back(('progress_status', stack_index, msg)) - def on_begin_operation_string(self, operation): + def on_begin_operation_string(self, operation: str): """ The operation string. @@ -58,7 +60,7 @@ def on_begin_operation_string(self, operation): Returns: (int): stack index for the operation """ - stack_index = self.on_begin_operation_string(operation) + stack_index = super(ProgressListener, self).on_begin_operation_string(operation) self.call_back(('begin_operation', stack_index, operation)) return stack_index @@ -68,12 +70,12 @@ def on_end_operation(self, stack_index): """ self.call_back(('end_operation', stack_index, '')) - def on_update_message(self, stack_index, message): + def on_update_message(self, stack_index: int, message): """ When update message has been sent. Args: - stack_index (int): stack index for the progress + stack_index: stack index for the progress message: The new message """ self.call_back(('update_message', -1, message))