ADCT Python
Python client API implementation for publishing ADCT data
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Protected Attributes | List of all members
adctk.debug_file_publisher.DebugFilePublisher Class Reference

debugging version of a file-oriented publisher. More...

Inheritance diagram for adctk.debug_file_publisher.DebugFilePublisher:
Inheritance graph
[legend]
Collaboration diagram for adctk.debug_file_publisher.DebugFilePublisher:
Collaboration graph
[legend]

Public Member Functions

 __init__ (self, path=None, **kwargs)
 
 post (self, j)
 
 publish (self, builder.Builder b)
 Publish json extracted from builder to _base_url server.
 
 publish_obj (self, obj)
 
 publish_str (self, json_string)
 
 config (self, **kwargs)
 Configure the plugin with the options given.
 
 initialize (self)
 Set up any resources needed for reuse in publish().
 
 finalize (self)
 Clean up any resources set up in initialize (files, pipes, etc).
 
- Public Member Functions inherited from adctk.publisher.Publisher
str name (self)
 Get the name which a factory or error message should use.
 
str version (self)
 
dict[str, str] get_option_defaults (self)
 
None pause (self)
 Cause publish calls to be ignored until resume is called.
 
None resume (self)
 Cancel an prior calls to pause.
 

Public Attributes

 plugin_prefix
 
- Public Attributes inherited from adctk.publisher.Publisher
 defaults
 
 plugin_prefix
 
 paused
 
 state
 
 mode
 

Protected Attributes

 _path
 

Additional Inherited Members

- Static Public Member Functions inherited from adctk.publisher.Publisher
tuple[float] get_timeout_defaults ()
 Get the adc server connect and response timeouts defined in the environment ADC_SERVER_CONNECT_TIMEOUT and ADC_SERVER_POST_TIMEOUT as a tuple or default values if not defined.
 
str get_url_default ()
 Get the alleged adc server url base from environment ADC_SERVER_URL or the default if it is not present.
 
str get_port_default ()
 Get the adc server port number to use if it is properly defined in the environment ADC_SERVER_PORT or the default if it is not.
 
- Static Public Attributes inherited from adctk.publisher.Publisher
 API_VERSION = adc_version.AdcVersion()._dict()
 
- Protected Member Functions inherited from adctk.publisher.Publisher
str _get (self, dict[str, str] opts, str field)
 
bool _get_bool (self, dict[str, str] opts, str field)
 
- Static Protected Attributes inherited from adctk.publisher.Publisher
str _name = "unknown"
 
str _version = "0.0.0"
 

Detailed Description

debugging version of a file-oriented publisher.

This assumes a single process writing to a given file and it has no evironment-based initialization. File is reopened for append on every publication. *** Do not use in production code. ***

Constructor & Destructor Documentation

◆ __init__()

adctk.debug_file_publisher.DebugFilePublisher.__init__ (   self,
  path = None,
**  kwargs 
)

Reimplemented from adctk.publisher.Publisher.

18 def __init__(self, path=None, **kwargs):
19 super().__init__()
20 if not path:
21 self.plugin_prefix = "ADC_DEBUG_FILE_PLUGIN_"
22 self._path = self._get(kwargs, "FILE")
23 if not self._path:
24 self._path = "adc.debug_file_publisher.log"
25 else:
26 self._path = path
27

Member Function Documentation

◆ config()

adctk.debug_file_publisher.DebugFilePublisher.config (   self,
**  kwargs 
)

Configure the plugin with the options given.

For plugin QQQ, Environment variables ADC_QQQ_PLUGIN_<key> will override the plugin default for any key not defined in kwargs. Here QQQ is plugin.name().upper(). Generic options:

Parameters
kwargsIf env_prefix is included in kwargs, replaces plugin environment variables with those which are prefixed using env_prefix.
env_prefixTypically, env_prefix is set to "PPP_ADC_QQQ_PLUGIN_" if application PPP wants to override the defaults of adctk plugin QQQ. Here QQQ is plugin.name().upper(). If no prefixed version of the variable is present, the plugin default is used. kwargs takes precedence over environment variables. Plugin defaults are used if not overridden by kwargs or an environment variable.
Returns
int non-zero if configuration cannot be completed using the arguments, environment, and default.

Reimplemented from adctk.publisher.Publisher.

57 def config(self, **kwargs):
58 pass # config: nothing to do here

◆ finalize()

adctk.debug_file_publisher.DebugFilePublisher.finalize (   self)

Clean up any resources set up in initialize (files, pipes, etc).

Reimplemented from adctk.publisher.Publisher.

61 def finalize(self):
62 pass # finalize: nothing to do here

◆ initialize()

adctk.debug_file_publisher.DebugFilePublisher.initialize (   self)

Set up any resources needed for reuse in publish().

Reimplemented from adctk.publisher.Publisher.

59 def initialize(self):
60 pass # initialize: nothing to do here

◆ post()

adctk.debug_file_publisher.DebugFilePublisher.post (   self,
  j 
)
 log the message 
28 def post(self, j):
29 """ log the message """
30 try:
31 with open(self._path, mode="a", encoding='utf-8') as f:
32 print(j, file=f)
33 return 0
34 except OSError as e:
35 log.logger("error opening %s: %s", self._path, e)
36 return 1
37

◆ publish()

adctk.debug_file_publisher.DebugFilePublisher.publish (   self,
builder.Builder  b 
)

Publish json extracted from builder to _base_url server.

Reimplemented from adctk.publisher.Publisher.

38 def publish(self, b: builder.Builder):
39 """! Publish json extracted from builder to _base_url server"""
40 ret = self.post(b.get_json_dump())
41 return ret
42

◆ publish_obj()

adctk.debug_file_publisher.DebugFilePublisher.publish_obj (   self,
  obj 
)
publish obj (json.dumps(obj) result) from caller to file.
Does not produce valid ADCT messages.

Reimplemented from adctk.publisher.Publisher.

43 def publish_obj(self, obj):
44 """publish obj (json.dumps(obj) result) from caller to file.
45 Does not produce valid ADCT messages.
46 """
47 ret = self.post(json.dumps(obj))
48 return ret
49

◆ publish_str()

adctk.debug_file_publisher.DebugFilePublisher.publish_str (   self,
  json_string 
)
publish json_string (json.dumps result) from caller to file.
Does not produce valid ADCT messages.

Reimplemented from adctk.publisher.Publisher.

50 def publish_str(self, json_string):
51 """publish json_string (json.dumps result) from caller to file.
52 Does not produce valid ADCT messages.
53 """
54 ret = self.post(json_string)
55 return ret
56

Member Data Documentation

◆ _path

adctk.debug_file_publisher.DebugFilePublisher._path
protected

◆ plugin_prefix

adctk.debug_file_publisher.DebugFilePublisher.plugin_prefix

The documentation for this class was generated from the following file: