LogBook.Note

Name

LogBook.Note, LogBook.Image -- Encapsulate notes for python

Synopsis


PYTHONPATH=$DAQROOT/pythonLibs/nscldaq python3

import LogBook.LogBook as LogBook
...
book  = LogBook.LogBook('logbookfile.log')
note  = book.get_note(1)
image = note.get_image(0)
      

image_id    = image.id
note_id     = image.note_id
note_no     = image.index
offset      = image.offset
original_fn = image.original_file
exported_fn = image.exported_file

      

note_id     = note.id
note_run    = note.run
if note_run is None:
    print("Note has no associated run")
timestamp   = note.time
raw_text    = note.contents
author      = note.author
      
      

nimages  = note.image_count()
image    = note.get_image(index)
markdown = note.sustitute_images()

         
      

DESCRIPTION

LogBook.Note encapsulates a single logbook note. Related to this class is LogBook.Image which encapsulates a single image. Images can be fetched from a note object using get_image.

Notes are stored in the logbook along with their associated images. The note text is assumed to be in Markdown format. Image links, however point to image files that may or may not still be in the filesystem. These images, however, have been pulled into the logbook database. They can be exported back out into the filesystem and the raw note text image references fixed up to point to these exported images using substitute_images. Therefore the way to render a note is to first invoke substitute_image on the note to get usable Markdown from the note and then append or prepend any markdown headers or trailers desired (for example, lg_browse and lg_print prepend a table of note metadata), and then pass the resulting text to a mardown processor, such as Python-Markdown (https://python-markdown.github.io) for html output or pandoc for other output formats such as e.g. PDF. NSCL Container images include pandoc (https://pandoc.org -- packages exist as well for most Linux variants).

The remaining sections of this reference page will first document the attributes and methods of LogBook.Note and then the attributes of LogBook.Image, instances of which can be produced by note instances.

LogBook.Note

LogBook.Note objects encapsulate a single note from the logbook database. In general they are not constructed directly but obtaind from method calls to LogBook.LogBook instances. See: LogBook

Attributes

LogBook.Note objects have several read-only attributes:

Integer id

Returns the primary key of the note. This is a unique integer that identifies the note.

LogBook.Run run

If the note is associated with a run, this attribute will provide a LogBook.Run object encapsulating that run. LogBook.Run objects are described in LogBook.Run.

If there is no run associated with this note, the value of this attribute is None.

Long time

Returns the time the note was added to the logbook in a form usable as input to datetime.fromtimestamp. The time provided is not the time at which note authoring began, authoring can take a macroscopic amount of time, but the time at which the note was added to the logbook database.

String contents

Accesses the raw text of the note. Unless the note has no associated images, this is not suitable for rendering as it will contain possibly broken image references.

LogBook.Person author

Returns a LogBook.Person that wraps the author of the note. LogBook.Person is described in LogBook.Person

METHODS

LogBook.Note defines the following methods:

Integer image_count();

Returns the number of images that are referenced by the note.

LogBook.Image get_image(Integer index);

Returns the index'th image associated with the note as a LogBook.Image object. If index is out of range, a LogBook.error exception is raised.

String substitute_images();

This method generates usable markdown from the raw note text and referenced images. It does so by exporting referenced images to the filesystem and fixing up the markdown links to them to point at the exported images. The return value of this method is the fixed markdown text. This text is suitable to be rendered by a markdown processor.

LogBook.Image

This class encapsulates a single image. It is not generally constructed directly but via a call to a LogBook.Note object's get_image method. LogBook.Image objects have several read-only attributes:

Integer id

Provides the primary key of the image.

Integer note_id

Provides the primary key of the note this image is used in.

Integer index

Provides the note index within the note. This is the value that was passed to a note's get_image method call.

Integer offset

The byte offset in the note text at which the markdown link referencing this note begins. This is the index of that link's leading ! character.

String orgininal_file

Provides the image's original file system path.

Stringexported_file

Provides the image's exported filesystem path. The first call of this method does the export. Note that this is because all of the Python image processing packages I peeked at operate on files rather than bytes in memory.

FILES

~/.nscl-logbook - image export directory