OptrisOptrisDocumentation

Documentation/OTC SDK/optris_sdk — Python API referencev12.0

file_names — functions

The rule the SDK names its own files by, for an application that names its files the same way. Added in 12.0.35.

An alarm's snapshot or recording, and every still of a time-lapse, is named from a pattern such as {rule}_{timestamp}. These are the very functions the SDK uses for them, so a manual snapshot named here looks like an alarm's and stays that way when the rule changes::

import optris_sdk

stem = optris_sdk.expand_file_name('{rule}_{sequence}',
                                   rule='over temp', sequence=7)
# 'over_temp_000007'
path = optris_sdk.unique_file_path('shots', stem, '.png')

The placeholders are {rule}, {region}, {serial}, {model}, {sequence} (six digits), {timestamp} (the local date and time as YYYYmmdd_HHMMSS, read when the name is made) and {timestamp_us}. Each value goes in once, so a rule named {timestamp} is named that; {{ and }} write a literal brace, and a name in braces that is none of these is written as it stands.

sanitize_file_name(text, fallback = '')

text as one part of a file name: a slash, a backslash, a colon, *, ?, ", <, >, |, a control character and a space each become _.

  • Parameter text — what to clean.
  • Parameter fallback — what to return when text is empty.
  • Returns — the cleaned text, or fallback.

expand_file_name(pattern, rule = None, region = None, serial = None, model = None, sequence = None, timestamp_us = None, fallback = '')

pattern with its placeholders filled in, then cleaned as sanitize_file_name cleans.

Each value is cleaned on its own first, so a rule named ../../etc cannot walk out of a directory. A placeholder whose value is None expands to nothing.

  • Parameter pattern — the pattern, without a directory or an extension.
  • Parameter rule — {rule}, for example an alarm rule's name.
  • Parameter region — {region}, a measuring area's name.
  • Parameter serial — {serial}, the camera's serial number.
  • Parameter model — {model}, the camera's model.
  • Parameter sequence — {sequence}, a counter.
  • Parameter timestamp_us — {timestamp_us}, a raw microsecond stamp.
  • Parameter fallback — what to return when nothing is left; the SDK's alarm actions use 'alarm'.
  • Returns — the file name's stem.

unique_file_path(directory, stem, extension)

directory/stem + extension, or, when that exists, the first of stem-1, stem-2 ... up to stem-9999 that does not.

Nothing is created, so two programs asking at once can be told the same name.

  • Parameter directory — the directory; empty means the current one.
  • Parameter stem — the name without its extension, for example from expand_file_name.
  • Parameter extension — the extension with its dot, for example '.png'.
  • Returns — the path.