Skip to content

mjiggidy/pybinhistory

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

57 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pybinhistory

Because pybinlog was taken™

pybinhistory reads and writes .log access log files, which accompany .avb Avid bins. It includes data validation and convenience methods, such as the ability to "touch" a bin in one command.

Warning

While the .log log file format is a very simple one, it is officially undocumented. Use this library at your own risk -- I assume no responsibility for any damage to your project, loss of data, or reshoots being blatantly obvious in the final cut.

Convenience Methods

Touching A Bin

You can easily add an entry to the bin log with the BinLog.touch() convenience method.

from binlog import BinLog
BinLog.touch("/path/to/bin.log")

Getting The Most Recent Entry

You can obtain the most recent bin log entry with the BinLog.last_entry() convenience method.

from binlog import BinLog
print(BinLog.last_entry("/path/to/bin.log"))

This returns the most recent BinLogEntry item in the log:

BinLogEntry(timestamp=datetime.datetime(2023, 9, 22, 14, 8, 4), computer='zMichael', user='mj4u')

BinLog

A BinLog represents a... uh... bin log. It handles reading and writing to log files, and essentially encapsulates a list of BinLogEntrys.

Reading Bin Logs

A bin log can be read from a given file path with the class method BinLog.from_path()

from binlog import BinLog
log = BinLog.from_path("/path/to/bin.log")

Or, you can pass a text stream directly with the class method BinLog.from_path(). This can be helpful if you're dealing with a weird text encoding, or outputting to something other than a typical file.

from binlog import BinLog
with open("/path/to/bin.log", encoding="mac_roman", errors="replace") as log_handle:
  log = BinLog.from_stream(log_handle)

Writing Bin Logs

Similar to reading, BinLog can be written to a bin log with BinLog.to_path("/path/to/bin.log") or BinLog.to_stream(textio_stream).

Creating Bin Logs

Aside from reading a bin log from a file, a new BinLog can be created directly with BinLog(), optionally passing it a list of BinLogEntrys.

Accessing BinLogEntrys

To access the BinLogEntrys in a BinLog, the BinLog object can be directly iterated over; or a list of BinLogEntrys can be retrieved via the BinLog.entries property.

BinLogEntry

A BinLog contains a list of BinLogEntry objects. BinLogEntry is really just a python dataclass with the following fields:

  • timestamp [datetime]: Timestamp of access
  • computer [str]: Typically the hostname of the Avid that accessed the bin
  • user [str]: The Avid user who accessed the bin

Formatting

Although BinLog typically handles reading and writing BinLogEntrys internally, BinLogEntry can be formatted as a typical log entry string with .to_string(), or read in from a log entry string with .from_string(str).

See Also