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.
This defines the following attributes on instances:
flags: theFlagsinstance providing the flag values.flags_prefix: the prefix for the flags of interest.flagname_name: the full name within.flagsof the flag referred to as name. This is.flags_prefix + '_' +name if.flags_prefixis not empty, or just name otherwise.flag_name: the value from.flagsof the flag referred to as name. This is a setable attribute with changes propagated to.flags.
Method FlaggedMixin.__init__(self, flags=None, debug=None, prefix=None)
Initialise the mixin.
Parameters:
flags: optional parameter; ifNonedefaults to a new defaultFlags().prefix: optional prefix; if not provided the prefix is derived from the object's.nameattribute, or is empty if there is no.name
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.
Method Flags.__init__(self, flagdir=None, environ=None, lock=None, debug=None)
Initialise the Flags instance.
Parameters:
flagdir: the directory holding flag state files; if omitted use the value fromcs.env.FLAGDIR(environ)environ: the environment mapping to use, defaultos.environlock: aLocklike mutex to control multithreaded access; if omitted no locking is downdebug: debug mode, defaultFalse
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 string values are unchanged.
Other types are converted with bool().
Function uppername(s)
Uppercase letters, transmute some characters to '_' or '__'.
Metadata
Release files for cs.app.flag 20190729
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| cs.app.flag-20190729.tar.gz | 7.3 kB | Without provenance | Details for cs.app.flag-20190729.tar.gz |
Release files / cs.app.flag-20190729.tar.gz
| Download URL | cs.app.flag-20190729.tar.gz |
|---|---|
| Size | 7.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
29d36d4a7f26fc719bd68d32d53cc2d9c7d641fd7a87b4b542975ab7592e5f0b
|
|
BLAKE2b-256 checksum How to use checksums |
147448af5878b35ca2ad7888236e59ee08843f101634796e877b867d36124054
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.7.4
|
Security for cs.app.flag 20190729
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.