nexuslims_logger namespace

Submodules

nexuslims_logger.filewatcher module

FileWatcher will watch a directory,and sync with Cloud periodically.

It will upload any files (require file types match if specified) (modified after certain time if specified) that checksum changed wrt. cache (if any) to a GCP cloud bucket in a specified interval.

class nexuslims_logger.filewatcher.FileWatcher(watch_dir, bucket_name, bucket_dir, credential_fn, cache_fn, interval=600, file_types=None, mtime_since=None, instr_info=None, logger=None)[source]

Bases: object

property bucket_dir
classmethod from_config(config, watchdir, credential_fn, cache_fn, logger=None)[source]
get_files_to_upload()[source]

find files to upload recursively and return list of abs file names and content checksum.

file satisfying the following condition will be considered for uploading: - file type is allowed (set in app config) - file modification timestamp is after the set threshold (session start time) - file content checksum does not exist in cache or updated.

Returns

List of tuple consisting file names and MD5 checksum.

Return type

List[Tuple[str, str]]

property instr_info
property interval
property mtime_since
upload()[source]

upload to the cloud object storage, set metadata and update the cache.

nexuslims_logger.instrument module

class nexuslims_logger.instrument.GCPInstrument(output_dir, bucket_name, bucket_dir, credential_fn, logger=None)[source]

Bases: nexuslims_logger.instrument.Instrument

Mock an instrument with data stored in GCP.

classmethod from_config(config, outputdir, credential_fn, logger=None)[source]
generate_data()[source]

Download random file from GCP bucket.

save to self.output_dir, and rename by timestamp.

get_file_pool()[source]

List all files in GCP self.bucket_dir

nexuslims_logger.loggerhub module

LoggerHub

class nexuslims_logger.loggerhub.App(config, cred_json, cache_json, verbose=20)[source]

Bases: tkinter.Tk

copy_text_to_clipboard()[source]
run()[source]
start()[source]
stop()[source]
class nexuslims_logger.loggerhub.ConsoleUi(frame, logger)[source]

Bases: object

Poll messages from a logging queue and display them in a scrolled text widget

display(record)[source]
poll_log_queue()[source]
class nexuslims_logger.loggerhub.DBSessionLogger(cpu_name, dbapi_url, dbapi_username=None, dbapi_password=None, user=None, logger=None)[source]

Bases: object

communicate with database.

continue_last_session()[source]
db_logger_setup()[source]

get instrument info (pid, schema name).

db_logger_teardown()[source]

teardown routine

classmethod from_config(config, cpu_name, user=None, logger=None)[source]
handle(msg)[source]
last_session_ended()[source]

Check the database for this instrument to make sure that the last entry in the db was an “END” (properly ended). If it’s not, return False so the GUI can query the user for additional input on how to proceed.

Returns

  • is_success (bool) – If the database is consistent (i.e. the last log for this instrument is an “END” log), return True. If not (it’s a “START” log), return False

  • msg (str)

process_end()[source]

Insert a session ‘END’ log for this computer’s instrument, and change the status of the corresponding ‘START’ entry from ‘WAITING_FOR_END’ to ‘TO_BE_BUILT’

process_end_check()[source]
process_start()[source]

Insert a session ‘START’ log for this computer’s instrument

Returns True if successful, False if not

process_start_check()[source]
save_note(note_text)[source]
update_start()[source]
update_start_check()[source]
class nexuslims_logger.loggerhub.QueueHandler(log_queue)[source]

Bases: logging.Handler

Class to send logging records to a queue It can be used from different threads The ConsoleUi class polls this queue to display records in a ScrolledText widget

emit(record)[source]

Do whatever it takes to actually log the specified logging record.

This version is intended to be implemented by subclasses and so raises a NotImplementedError.

nexuslims_logger.loggerhub.main()[source]
nexuslims_logger.loggerhub.validate_config(config)[source]

nexuslims_logger.loggertem module

LoggerTEM GUI

class nexuslims_logger.loggertem.App(hubaddr, watchdir, user=None, screen_res=None, logger=None, log_text=None)[source]

Bases: tkinter.Tk

close_warning(num_to_show)[source]

set loading text to remind the closing action

create_widgets()[source]

draw widgets on main frame.

destroy()[source]

Destroy this and all descendants widgets. This will end the application of this Tcl interpreter.

disable_buttons()[source]

bring state of all buttons on main window to DISABLED

done_loading()[source]

actions by the end of loading.

put off setup_frame, put up running_frame and labels, enable buttons.

draw_buttons()[source]

buttons at the bottom

draw_info()[source]

information section

incl. loading text, progress bar, instrument label, datetime

Top NexusLIMS logo with tooltip.

enable_buttons()[source]

bring state of all buttons on main window to NORMAL

generate_data()[source]

communicate with hub via socket to generate data

on_closing()[source]

actions when user is closing the main window.

save_note()[source]
session_end()[source]

routines for session ending.

change the frame, update loading text and progress bar.

session_end_worker()[source]

communicate with hub via socket to perform end session tasks.

session_startup()[source]

start startup_thread, update loading progress bar.

session_startup_worker()[source]

communicate with hub via socket to perform start session tasks.

show_error_if_needed(res)[source]

show error box if res is an Exception

switch_gui_to_end()[source]

actions by the start of ending.

put off running_frame; putup setup_frame, diable buttons

watch_for_end_result()[source]

Check if there is something in the queue.

update loading text and progress bar.

watch_for_startup_result()[source]

Check if there is something in the queue.

update loading text and progress bar.

class nexuslims_logger.loggertem.ConfirmUi(parent, query)[source]

Bases: tkinter.Toplevel

Popup window ask user for confirmation It has three buttons: yes, no, cancel

click_cancel()[source]
click_no()[source]
click_yes()[source]
show()[source]
class nexuslims_logger.loggertem.HangingSessionDialog(parent)[source]

Bases: tkinter.Toplevel

Dialogue window prompt user for actions when previous session is detected not ended properly.

click_close()[source]

enforce user to choose between continue or start with en error box.

click_continue()[source]

record action, destroy the window.

click_new()[source]

record action, destroy the window.

destroy()[source]

destroy the window, enable buttons on the main window.

show()[source]

Show the dialogue window, return the user response.

class nexuslims_logger.loggertem.LogWindow(parent, is_error=False)[source]

Bases: tkinter.Toplevel

change_close_button(num_to_show, state='disabled')[source]
copy_text_to_clipboard()[source]
class nexuslims_logger.loggertem.NoteWindow(parent)[source]

Bases: tkinter.Toplevel

change_close_button(num_to_show, state='disabled')[source]
copy_text_to_clipboard()[source]
delete_note()[source]
on_closing()[source]
save_note()[source]
class nexuslims_logger.loggertem.PauseOrEndDialogue(parent)[source]

Bases: tkinter.Toplevel

Dialogue window prompts user for actions when the user is closing the main window

click_cancel()[source]

record action, destroy the window.

click_close()[source]

record action, destroy the window.

click_end()[source]

record action, destroy the window.

click_pause()[source]

record action, destroy the window.

destroy()[source]

destroy the window, enable buttons on the main window.

show()[source]

Show the dialogue window, return the user response.

class nexuslims_logger.loggertem.ToolTip(wdgt, tooltip_font='TkDefaultFont', msg=None, msgFunc=None, header_msg=None, delay=1, follow=True)[source]

Bases: tkinter.Toplevel

Provides a ToolTip widget for Tkinter. To apply a ToolTip to any Tkinter widget, simply pass the widget to the ToolTip constructor

hide(event=None)[source]

Hides the ToolTip. Usually this is caused by leaving the widget :param event: The event that called this function

move(event)[source]

Processes motion within the widget. :param event: The event that called this function

show()[source]

Displays the ToolTip if the time delay has been long enough

spawn(event=None)[source]

Spawn the ToolTip. This simply makes the ToolTip eligible for display. Usually this is caused by entering the widget

Parameters

event – The event that called this function

nexuslims_logger.loggertem.help()[source]
nexuslims_logger.loggertem.main()[source]
nexuslims_logger.loggertem.validate_config(config)[source]

simple validation of config settings

nexuslims_logger.utils module

utility functions

class nexuslims_logger.utils.Config(dict=None, /, **kwargs)[source]

Bases: collections.UserDict

subclass dict, get keys from environment first.

get(k[, d]) D[k] if k in D, else d.  d defaults to None.[source]
class nexuslims_logger.utils.ScreenRes(logger=None)[source]

Bases: object

get_center_geometry_string(width, height)[source]

This method will return a Tkinter geometry string that will place a Toplevel window into the middle of the screen given the widget’s width and height (using a Windows command or xrandr as needed). If it fails for some reason, a basic resolution of 800x600 is assumed.

Parameters
  • width (int) – The width of the widget desired

  • height (int) – The height of the widget desired

Returns

geometry_string – The Tkinter geometry string that will put a window of width and height at the center of the screen given the current resolution (of the format “WIDTHxHEIGHT+XPOSITION+YPOSITION”)

Return type

str

run_cmd(cmd)[source]

Run a command using the subprocess module and return the output. Note that because we want to run the eventual logger without a console visible, we do not have access to the standard stdin, stdout, and stderr, and these need to be redirected subprocess pipes, accordingly.

Parameters

cmd (str) – The command to run (will be run in a new Windows cmd shell). stderr will be redirected for stdout and included in the returned output

Returns

output – The output of cmd

Return type

str

nexuslims_logger.utils.check_singleton()[source]

make sure only ONE instance of the program running.

nexuslims_logger.utils.get_logger(name, verbose=20, stream=None)[source]

get a logger from logging module, direct output to stdout, verbose level set by verbose.

If additional stream is provided, direct output (DEBUG) to that stream too.

nexuslims_logger.utils.resource_path(relative_path)[source]
nexuslims_logger.utils.show_error_msg_box(msg)[source]

show a tkinter error box.