Skip to content

Commit

Permalink
Updated documentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
wdolinar committed Aug 15, 2023
1 parent fcd6c86 commit 18132bf
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 83 deletions.
2 changes: 1 addition & 1 deletion _package/tests/unit_tests/filesystem_pyt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions _package/xms/core/filesystem/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def removefile(filename):
"""
try:
os.remove(filename)
except Exception:
except OSError:
pass


Expand Down Expand Up @@ -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':
Expand Down
132 changes: 66 additions & 66 deletions _package/xms/core/misc/observer.py
Original file line number Diff line number Diff line change
@@ -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)
24 changes: 13 additions & 11 deletions _package/xms/core/misc/progress_listener.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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.
Expand All @@ -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

Expand Down

0 comments on commit 18132bf

Please sign in to comment.