Skip to main content

Persistent filesystem based flags for state and control.

Filesystem visible boolean flags for control and status, allowing easy monitoring of services or other status, and control by flag management for programmes which also monitor the flags.

The flags are expressed as individual files with uppercase names in a common directory ($HOME/var/flags by default); an empty or missing file is "false" and a nonempty file is "true".

The Flags class provides easy Pythonic access to this directory. It presents as a modifiable mapping whose keys are the flag names:

  flags = Flags()
  flags['UNTOPPOST'] = True

There is also a FlaggedMixin class providing convenient methods and attributes for maintaining a collection of flags associated with some object with flag names prefixed by the object's .name attribute uppercased and with an underscore appended:

  class SvcD(...,FlaggedMixin):
    def __init__(self, name, ...)
      self.name = name
      FlaggedMixin.__init__(self)
      ...
    def disable(self):
      self.flag_disable = True
    def restart(self):
      self.flag_restart = True
    def _restart(self):
      self.flag_restart = False
      ... restart the SvcD ...

so that an object set up as:

  svcd = SvcD("portfwd")
  print(svcd.flag_disable)

accesses the flag named "PORTFWD_DISABLE".

Class FlaggedMixin

A mixin class adding flag_* and flagname_* attributes.

Class Flags

MRO: collections.abc.MutableMapping, collections.abc.Mapping, collections.abc.Collection, collections.abc.Sized, collections.abc.Iterable, collections.abc.Container, FlaggedMixin
A mapping which directly inspects the flags directory.

Function lowername(s)

Lowercase letters, transmute '_' to '-'. Note: NOT the reverse of uppername.

Function main(argv=None)

Main program: inspect or modify flags.

Function main_flagset(argv=None, stdin=None)

Main program for "flagset" command.

Class PolledFlags

MRO: builtins.dict
A mapping which maintains a dict of the current state of the flags directory and updates it regularly.

This allows an application to consult the flags very frequently without hammering the filesystem.

Function truthy(value)

Decide whether a value is considered true.

Strings are converted to:

  • '0': False
  • '1': True
  • 'true': True (case insensitive)
  • 'false': False (case insensitive)
  • Other values are unchanged.

Other types are converted with bool().

Function uppername(s)

Uppercase letters, transmute some characters to '_' or '__'.

Release files for cs.app.flag 20181109

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cs.app.flag 20181109
File Size Uploaded
cs.app.flag-20181109.tar.gz 6.5 kB Details

Release files / cs.app.flag-20181109.tar.gz

Download URL cs.app.flag-20181109.tar.gz
Size 6.5 kB
Tags Source
SHA-256 checksum
How to use checksums
9658f03ca9faf92e4206170642309fc25675fee6cd334559cae9966d18c6c08b
BLAKE2b-256 checksum
How to use checksums
7c966225c0b560a5f9b3c77846f2df913fb6ed657c3c704705d636d8d7eb2f33
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.23.0 CPython/3.6.6

Release history Release notifications | RSS feed

This release

20181109 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page