ka-uts-com 2023.6.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,19 @@
1
+ #
2
+ # Copyright (c) 2022 Kosakya, GmbH. All rights reserved.
3
+ #
4
+ # This program is free software: you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation, either version 3 of the License, or
7
+ # (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more detail.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ #
17
+ # Person: Role: Email:
18
+ # Bernd Stroehle Author bernd.stroehle@kosakya.de
19
+ # Maintainer
@@ -0,0 +1,15 @@
1
+ include MANIFEST.in
2
+ include LICENSE.txt
3
+ include README.rst
4
+ include setup.cfg
5
+ include requirements.txt
6
+
7
+ recursive-include * *.txt
8
+ recursive-include * *.in
9
+ recursive-include * *.md
10
+ recursive-exclude * __pycache__
11
+ recursive-exclude * *.pyc
12
+ recursive-exclude * *.pyo
13
+ recursive-exclude * *.orig
14
+
15
+ prune __pycache__*
@@ -0,0 +1,222 @@
1
+ Metadata-Version: 2.1
2
+ Name: ka_uts_com
3
+ Version: 2023.6.0
4
+ Summary: Communication Class Utilities
5
+ Author-email: Bernd Stroehle <bernd.stroehle@bs29.com>
6
+ Maintainer-email: Bernd Stroehle <bernd.stroehle@bs29.com>
7
+ Project-URL: Source Code, https://github.com/bs29/ka_uts_com/tree/master
8
+ Project-URL: Homepage, https://kosakya.de/
9
+ Project-URL: Documentation, https://ka-com.readthedocs.io/en/latest
10
+ Project-URL: Apache-2.0 License, https://apache.org/licenses/LICENSE-2.0
11
+ Classifier: Development Status :: 5 - Production/Stable
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved :: Apache Software License
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Natural Language :: English
17
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
18
+ Requires-Python: >=3.10
19
+ Description-Content-Type: text/x-rst
20
+ License-File: LICENSE.txt
21
+ Requires-Dist: Jinja2>=3.1.4
22
+ Requires-Dist: PyYAML>=6.0.2
23
+ Requires-Dist: setuptools>=70.1.1
24
+
25
+ ##########
26
+ ka_uts_com
27
+ ##########
28
+
29
+ Overview
30
+ ========
31
+
32
+ .. start short_desc
33
+
34
+ **Communication Utilities**
35
+
36
+ .. end short_desc
37
+
38
+ Installation
39
+ ============
40
+ .. start installation
41
+
42
+ ``ka_uts_com`` can be installed from PyPI or Anaconda.
43
+
44
+ To install with ``pip``:
45
+
46
+ .. code-block:: shell
47
+
48
+ $ python -m pip install ka_uts_com
49
+
50
+ To install with ``conda``:
51
+
52
+ .. code-block:: shell
53
+
54
+ $ conda install -c conda-forge ka_uts_com
55
+
56
+ .. end installation
57
+
58
+ This requires that the ``readme`` extra is installed:
59
+
60
+ .. code-block:: bash
61
+
62
+ $ python -m pip install ka_uts_com[readme]
63
+
64
+ Configuration
65
+ =============
66
+
67
+ The Configuration of general or tenant specific Package logging is defined in Yaml Configuration Files in the data directory <Package Name>/data of the Package.
68
+
69
+ .. _configuration-file-label:
70
+ .. list-table:: *Configuration Files*
71
+ :widths: auto
72
+ :header-rows: 1
73
+
74
+ * - Logging Type
75
+ - Configuration File
76
+ - Description
77
+ * - general
78
+ - log.yml
79
+ - the Python Logger compatible general Configuration file is used to
80
+ define tenant independend logging
81
+ * - tenant
82
+ - log.main.tenant.yml
83
+ - the Python Logger compatible tenant Configuration file is used to
84
+ define tenant dependend logging
85
+
86
+ Modules
87
+ =======
88
+ ``ka_uts_com`` contains the following modules.
89
+
90
+ ------------
91
+ Base Modules
92
+ ------------
93
+
94
+ .. base-modules-label:
95
+ .. table:: *Base Modules*
96
+
97
+ +------+---------------------------------------------------+
98
+ |Module|Description |
99
+ +======+===================================================+
100
+ |com |The com module contains the the Base Communication |
101
+ | |class Com and the Utility Classes: |
102
+ | +---------------------------------------------------+
103
+ | |**Base Communication Class** |
104
+ | +----------+----------------------------------------+
105
+ | |**Class** |**Description** |
106
+ | +----------+----------------------------------------+
107
+ | |*Com* | Base Communication Setup |
108
+ | +----------+----------------------------------------+
109
+ | |**Utility Classes** |
110
+ | +----------+----------------------------------------+
111
+ | |**Class** |**Description** |
112
+ | +----------+----------------------------------------+
113
+ | |*Standard*|Standard Log Configuration |
114
+ | +----------+----------------------------------------+
115
+ | |*Person* |Person based Log Configuration |
116
+ | +----------+----------------------------------------+
117
+ | |*Cfg* |Configuration Management |
118
+ | +----------+----------------------------------------+
119
+ | |*Mgo* |Mongo Db Configuration Management |
120
+ | +----------+----------------------------------------+
121
+ | |*App* |Setup Application Management |
122
+ | +----------+----------------------------------------+
123
+ | |*Exit* |Setup Exit Handling |
124
+ +------+----------+----------------------------------------+
125
+
126
+ ---------------
127
+ Utility Modules
128
+ ---------------
129
+
130
+ .. _utility-modules-label:
131
+
132
+ .. table:: *Utility Modules*
133
+
134
+ +------+-----------------------------------------------------+
135
+ |Module|Description |
136
+ +======+=====================================================+
137
+ |pacmod|The pacmod module contains the Pacmod Class with |
138
+ | |the following Components (Functions and sub classes) |
139
+ | +-------------+---------------------------------------+
140
+ | |**Function** |**Description** |
141
+ | +-------------+---------------------------------------+
142
+ | |sh |show pacmod dictionary entries |
143
+ | +-------------+---------------------------------------+
144
+ | |**Sub-class**|**Description** |
145
+ | +-------------+---------------------------------------+
146
+ | |Yaml |I/O for yaml files |
147
+ | +-------------+---------------------------------------+
148
+ | |Json |I/O for Json files |
149
+ +------+-------------+---------------------------------------+
150
+ |ioc |The ioc module contains I/O Classes for the following|
151
+ | |file types: yaml, json |
152
+ +------+-----------------------------------------------------+
153
+
154
+ .. _utility-modules-function-label:
155
+
156
+ .. table:: *Utility Module Functions*
157
+
158
+ +-------+---------------------------------+
159
+ |Fnction|Description |
160
+ +=======+=================================+
161
+ |sh |pacmod dictionary |
162
+ +-------+---------------------------------+
163
+
164
+ .. _utility-modules-classes-label:
165
+
166
+ .. table:: *Utility Module Classes*
167
+
168
+ +-----+-----------------------------------------------+
169
+ |Class|Description |
170
+ +-----+-----------------------------------------------+
171
+ |Yaml |I/O for yaml files |
172
+ +-----+-----------------------------------------------+
173
+ |Json |I/O for json files |
174
+ +-----+-----------------------------------------------+
175
+
176
+ ---------------
177
+ Special Modules
178
+ ---------------
179
+
180
+ .. special-modules-label:
181
+
182
+ .. table:: *Special Modules*
183
+
184
+ +-----------+---------------------------------------------+
185
+ |Module |Description |
186
+ +===========+=============================================+
187
+ |__init__ |dummy Module: contains no Statements |
188
+ +-----------+---------------------------------------------+
189
+ |__version__|contains Assignment Statements for Version |
190
+ | |System Variables |
191
+ +-----------+-------------------+-------------------------+
192
+
193
+ .. System-Variables-of-Module-__version__:
194
+
195
+ .. table:: *System Variables of Module __version__*
196
+
197
+ +---------------+-----------------------------------------+
198
+ |System Variable|Example |
199
+ +===============+=========================================+
200
+ |__title__ |'ka_uts_com' |
201
+ +---------------+-----------------------------------------+
202
+ |__description__|'Communication Area Utilities.' |
203
+ +---------------+-----------------------------------------+
204
+ |__url__ |'https://ka-com.readthedocs.io/en/latest'|
205
+ +---------------+-----------------------------------------+
206
+ |__version___ |'2023.2.2' |
207
+ +---------------+-----------------------------------------+
208
+ |__build__ |0x022200 |
209
+ +---------------+-----------------------------------------+
210
+ |__author_email_|'Bernd Stroehle' |
211
+ +---------------+-----------------------------------------+
212
+ |__license__ |'Apache-2.0' |
213
+ +---------------+-----------------------------------------+
214
+ |__copyright__ |'Copyright 2023 bs29' |
215
+ +---------------+-----------------------------------------+
216
+ |__cake__ |u'\u2728 \U0001f370 \u2728' |
217
+ +---------------+-----------------------------------------+
218
+
219
+ Appendix
220
+ ========
221
+
222
+ .. contents:: **Table of Content**
@@ -0,0 +1,198 @@
1
+ ##########
2
+ ka_uts_com
3
+ ##########
4
+
5
+ Overview
6
+ ========
7
+
8
+ .. start short_desc
9
+
10
+ **Communication Utilities**
11
+
12
+ .. end short_desc
13
+
14
+ Installation
15
+ ============
16
+ .. start installation
17
+
18
+ ``ka_uts_com`` can be installed from PyPI or Anaconda.
19
+
20
+ To install with ``pip``:
21
+
22
+ .. code-block:: shell
23
+
24
+ $ python -m pip install ka_uts_com
25
+
26
+ To install with ``conda``:
27
+
28
+ .. code-block:: shell
29
+
30
+ $ conda install -c conda-forge ka_uts_com
31
+
32
+ .. end installation
33
+
34
+ This requires that the ``readme`` extra is installed:
35
+
36
+ .. code-block:: bash
37
+
38
+ $ python -m pip install ka_uts_com[readme]
39
+
40
+ Configuration
41
+ =============
42
+
43
+ The Configuration of general or tenant specific Package logging is defined in Yaml Configuration Files in the data directory <Package Name>/data of the Package.
44
+
45
+ .. _configuration-file-label:
46
+ .. list-table:: *Configuration Files*
47
+ :widths: auto
48
+ :header-rows: 1
49
+
50
+ * - Logging Type
51
+ - Configuration File
52
+ - Description
53
+ * - general
54
+ - log.yml
55
+ - the Python Logger compatible general Configuration file is used to
56
+ define tenant independend logging
57
+ * - tenant
58
+ - log.main.tenant.yml
59
+ - the Python Logger compatible tenant Configuration file is used to
60
+ define tenant dependend logging
61
+
62
+ Modules
63
+ =======
64
+ ``ka_uts_com`` contains the following modules.
65
+
66
+ ------------
67
+ Base Modules
68
+ ------------
69
+
70
+ .. base-modules-label:
71
+ .. table:: *Base Modules*
72
+
73
+ +------+---------------------------------------------------+
74
+ |Module|Description |
75
+ +======+===================================================+
76
+ |com |The com module contains the the Base Communication |
77
+ | |class Com and the Utility Classes: |
78
+ | +---------------------------------------------------+
79
+ | |**Base Communication Class** |
80
+ | +----------+----------------------------------------+
81
+ | |**Class** |**Description** |
82
+ | +----------+----------------------------------------+
83
+ | |*Com* | Base Communication Setup |
84
+ | +----------+----------------------------------------+
85
+ | |**Utility Classes** |
86
+ | +----------+----------------------------------------+
87
+ | |**Class** |**Description** |
88
+ | +----------+----------------------------------------+
89
+ | |*Standard*|Standard Log Configuration |
90
+ | +----------+----------------------------------------+
91
+ | |*Person* |Person based Log Configuration |
92
+ | +----------+----------------------------------------+
93
+ | |*Cfg* |Configuration Management |
94
+ | +----------+----------------------------------------+
95
+ | |*Mgo* |Mongo Db Configuration Management |
96
+ | +----------+----------------------------------------+
97
+ | |*App* |Setup Application Management |
98
+ | +----------+----------------------------------------+
99
+ | |*Exit* |Setup Exit Handling |
100
+ +------+----------+----------------------------------------+
101
+
102
+ ---------------
103
+ Utility Modules
104
+ ---------------
105
+
106
+ .. _utility-modules-label:
107
+
108
+ .. table:: *Utility Modules*
109
+
110
+ +------+-----------------------------------------------------+
111
+ |Module|Description |
112
+ +======+=====================================================+
113
+ |pacmod|The pacmod module contains the Pacmod Class with |
114
+ | |the following Components (Functions and sub classes) |
115
+ | +-------------+---------------------------------------+
116
+ | |**Function** |**Description** |
117
+ | +-------------+---------------------------------------+
118
+ | |sh |show pacmod dictionary entries |
119
+ | +-------------+---------------------------------------+
120
+ | |**Sub-class**|**Description** |
121
+ | +-------------+---------------------------------------+
122
+ | |Yaml |I/O for yaml files |
123
+ | +-------------+---------------------------------------+
124
+ | |Json |I/O for Json files |
125
+ +------+-------------+---------------------------------------+
126
+ |ioc |The ioc module contains I/O Classes for the following|
127
+ | |file types: yaml, json |
128
+ +------+-----------------------------------------------------+
129
+
130
+ .. _utility-modules-function-label:
131
+
132
+ .. table:: *Utility Module Functions*
133
+
134
+ +-------+---------------------------------+
135
+ |Fnction|Description |
136
+ +=======+=================================+
137
+ |sh |pacmod dictionary |
138
+ +-------+---------------------------------+
139
+
140
+ .. _utility-modules-classes-label:
141
+
142
+ .. table:: *Utility Module Classes*
143
+
144
+ +-----+-----------------------------------------------+
145
+ |Class|Description |
146
+ +-----+-----------------------------------------------+
147
+ |Yaml |I/O for yaml files |
148
+ +-----+-----------------------------------------------+
149
+ |Json |I/O for json files |
150
+ +-----+-----------------------------------------------+
151
+
152
+ ---------------
153
+ Special Modules
154
+ ---------------
155
+
156
+ .. special-modules-label:
157
+
158
+ .. table:: *Special Modules*
159
+
160
+ +-----------+---------------------------------------------+
161
+ |Module |Description |
162
+ +===========+=============================================+
163
+ |__init__ |dummy Module: contains no Statements |
164
+ +-----------+---------------------------------------------+
165
+ |__version__|contains Assignment Statements for Version |
166
+ | |System Variables |
167
+ +-----------+-------------------+-------------------------+
168
+
169
+ .. System-Variables-of-Module-__version__:
170
+
171
+ .. table:: *System Variables of Module __version__*
172
+
173
+ +---------------+-----------------------------------------+
174
+ |System Variable|Example |
175
+ +===============+=========================================+
176
+ |__title__ |'ka_uts_com' |
177
+ +---------------+-----------------------------------------+
178
+ |__description__|'Communication Area Utilities.' |
179
+ +---------------+-----------------------------------------+
180
+ |__url__ |'https://ka-com.readthedocs.io/en/latest'|
181
+ +---------------+-----------------------------------------+
182
+ |__version___ |'2023.2.2' |
183
+ +---------------+-----------------------------------------+
184
+ |__build__ |0x022200 |
185
+ +---------------+-----------------------------------------+
186
+ |__author_email_|'Bernd Stroehle' |
187
+ +---------------+-----------------------------------------+
188
+ |__license__ |'Apache-2.0' |
189
+ +---------------+-----------------------------------------+
190
+ |__copyright__ |'Copyright 2023 bs29' |
191
+ +---------------+-----------------------------------------+
192
+ |__cake__ |u'\u2728 \U0001f370 \u2728' |
193
+ +---------------+-----------------------------------------+
194
+
195
+ Appendix
196
+ ========
197
+
198
+ .. contents:: **Table of Content**
@@ -0,0 +1,7 @@
1
+ Development Status :: 5 - Production/Stable
2
+ Intended Audience :: Developers
3
+ License :: OSI Approved :: Apache Software License
4
+ Operating System :: OS Independent
5
+ Programming Language :: Python :: 3.10
6
+ Natural Language :: English
7
+ Topic :: Software Development :: Libraries :: Python Modules
File without changes
@@ -0,0 +1,10 @@
1
+ __title__ = 'ka_uts_com'
2
+ __description__ = 'Communication Area Utilities.'
3
+ __url__ = 'https://ka-ut-com.readthedocs.io/en/latest'
4
+ __version__ = '2023.6.0'
5
+ __build__ = 0x022200
6
+ __author__ = 'Bernd Stroehle'
7
+ __author_email__ = 'bernd.stroehle@bs29.com'
8
+ __license__ = 'Apache-2.0'
9
+ __copyright__ = 'Copyright 2023 bs29'
10
+ __cake__ = u'\u2728 \U0001f370 \u2728'
@@ -0,0 +1,196 @@
1
+ # coding=utf-8
2
+
3
+ import calendar
4
+ import logging
5
+ import logging.config
6
+ from logging import Logger
7
+
8
+ import os
9
+ import time
10
+ from datetime import datetime
11
+
12
+ from ka_uts_com.ioc import Yaml
13
+ from ka_uts_com.ioc import Jinja2
14
+ from ka_uts_com.pacmod import Pacmod
15
+
16
+ from typing import Any, Callable, List, Dict
17
+
18
+ T_Arr = List[Any]
19
+ T_Dic = Dict[Any, Any]
20
+
21
+ TN_Arr = None | T_Arr
22
+ TN_Dic = None | T_Dic
23
+
24
+
25
+ class StandardLog:
26
+
27
+ sw_init: bool = False
28
+ cfg: T_Dic = {}
29
+ log: Logger = logging.getLogger('dummy_logger')
30
+
31
+ @staticmethod
32
+ def read(pacmod: T_Dic, filename: str) -> Any:
33
+ path: str = Pacmod.Path.Log.sh_cfg(filename=filename)
34
+ tenant: str = pacmod['tenant']
35
+ package: str = pacmod['package']
36
+ module: str = pacmod['module']
37
+ pid = Com.pid
38
+ ts: None | datetime = Com.ts_start
39
+ log_main = Jinja2.read(
40
+ path, tenant=tenant, package=package, module=module,
41
+ pid=pid, ts=ts)
42
+ return log_main
43
+
44
+ @classmethod
45
+ def set_level(cls, sw_debug: bool) -> None:
46
+ if sw_debug:
47
+ level = logging.DEBUG
48
+ else:
49
+ level = logging.INFO
50
+ cls.cfg['handlers']['main_debug_console']['level'] = level
51
+ cls.cfg['handlers']['main_debug_file']['level'] = level
52
+
53
+ @classmethod
54
+ def init(
55
+ cls, **kwargs) -> None:
56
+ sw_debug: Any = kwargs.get('sw_debug')
57
+ if cls.sw_init:
58
+ return
59
+ cls.sw_init = True
60
+ cls.cfg = cls.read(Com.pacmod_curr, 'log.main.tenant.yml')
61
+ cls.set_level(sw_debug)
62
+ logging.config.dictConfig(cls.cfg)
63
+ cls.log = logging.getLogger('main')
64
+ return cls.log
65
+
66
+
67
+ class PersonLog:
68
+
69
+ sw_init: bool = False
70
+ cfg: T_Dic = {}
71
+ log: Logger = logging.getLogger('dummy_logger')
72
+
73
+ @classmethod
74
+ def read(
75
+ cls, pacmod: T_Dic, person: Any, filename: str) -> Any:
76
+ path: str = Pacmod.Path.Log.sh_cfg(filename=filename)
77
+ package: str = pacmod['package']
78
+ module: str = pacmod['module']
79
+ return Jinja2.read(
80
+ path, package=package, module=module, person=person,
81
+ pid=Com.pid, ts=Com.ts_start)
82
+
83
+ @classmethod
84
+ def set_level(cls, person: str, sw_debug: bool) -> None:
85
+ if sw_debug:
86
+ level = logging.DEBUG
87
+ else:
88
+ level = logging.INFO
89
+ cls.cfg['handlers'][f'{person}_debug_console']['level'] = level
90
+ cls.cfg['handlers'][f'{person}_debug_file']['level'] = level
91
+
92
+ @classmethod
93
+ def init(cls, pacmod: T_Dic, person: str, sw_debug: bool) -> None:
94
+ cls.cfg = cls.read(pacmod, person, 'log.person.yml')
95
+ cls.set_level(person, sw_debug)
96
+ logging.config.dictConfig(cls.cfg)
97
+ cls.log = logging.getLogger(person)
98
+ return cls.log
99
+
100
+
101
+ class Cfg:
102
+
103
+ @classmethod
104
+ def init(cls, pacmod: T_Dic) -> TN_Dic:
105
+ """ the package data directory has to contain a __init__.py
106
+ file otherwise the objects notation {package}.data to
107
+ locate the package data directory is invalid
108
+ """
109
+ _dic: TN_Dic = Yaml.read(Pacmod.Cfg.sh_path(pacmod))
110
+ return _dic
111
+
112
+
113
+ class Mgo:
114
+
115
+ client = None
116
+
117
+
118
+ class App:
119
+
120
+ sw_init: bool = False
121
+ httpmod = None
122
+ sw_replace_keys: None | bool = None
123
+ keys: TN_Arr = None
124
+ reqs: T_Dic = {}
125
+ app: T_Dic = {}
126
+
127
+ @classmethod
128
+ def init(
129
+ cls, **kwargs) -> Any:
130
+ if cls.sw_init:
131
+ return cls
132
+ cls.sw_init = True
133
+
134
+ cls.httpmod = kwargs.get('httpmod')
135
+ cls.sw_replace_keys = kwargs.get('sw_replace_keys', False)
136
+
137
+ try:
138
+ if cls.sw_replace_keys:
139
+ pacmod = kwargs.get('pacmod_curr')
140
+ cls.keys = Yaml.read(Pacmod.Pmd.sh_path_keys(pacmod))
141
+ except Exception as e:
142
+ if Com.Log is not None:
143
+ fnc_error: Callable = Com.Log.error
144
+ fnc_error(e, exc_info=True)
145
+ raise
146
+ return cls
147
+
148
+
149
+ class Exit:
150
+
151
+ sw_critical: bool = False
152
+ sw_stop: bool = False
153
+ sw_interactive: bool = False
154
+
155
+
156
+ class Com:
157
+ """Communication Class
158
+ """
159
+
160
+ sw_init: bool = False
161
+ cfg: TN_Dic = None
162
+ pid = None
163
+ pacmod_curr: T_Dic = {}
164
+
165
+ ts_start: None | datetime = None
166
+ ts_end: None | datetime = None
167
+ ts_etime: None | datetime = None
168
+ d_timer: Dict = {}
169
+
170
+ Log: Logger = logging.getLogger('dummy_logger')
171
+ App = None
172
+ Exit = Exit
173
+
174
+ @classmethod
175
+ def init(cls, **kwargs):
176
+ """ set log and application (module) configuration
177
+ """
178
+ if cls.sw_init:
179
+ return
180
+ cls.sw_init = True
181
+
182
+ cls.pacmod_curr = kwargs.get('pacmod_curr')
183
+ cls.ts_start = calendar.timegm(time.gmtime())
184
+ cls.pid = os.getpid()
185
+
186
+ cls.cfg = Cfg.init(cls.pacmod_curr)
187
+ cls.Log = StandardLog.init(**kwargs)
188
+ cls.App = App.init(**kwargs)
189
+
190
+ # @classmethod
191
+ # def terminate(cls):
192
+ # """ set log and application (module) configuration
193
+ # """
194
+ # cls.Log = StandardLog.log
195
+ # cls.ts_end = calendar.timegm(time.gmtime())
196
+ # cls.ts_etime = cls.ts_end - cls.ts_start
File without changes