atk-common 0.2.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,29 @@
1
+ Metadata-Version: 2.1
2
+ Name: atk_common
3
+ Version: 0.2.0
4
+ Summary: ATK common methods
5
+ Home-page: https://github.com/pypa/atk_common
6
+ Author: Roger
7
+ Author-email: roger@perspic.tech
8
+ Project-URL: Bug Reports, https://github.com/pypa/atk_common/issues
9
+ Project-URL: Funding, https://donate.pypi.org
10
+ Project-URL: Say Thanks!, http://saythanks.io/to/example
11
+ Project-URL: Source, https://github.com/pypa/atk_common/
12
+ Keywords: sample,setuptools,development
13
+ Classifier: Development Status :: 3 - Alpha
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Topic :: Software Development :: Build Tools
16
+ Classifier: License :: OSI Approved :: MIT License
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.7
19
+ Classifier: Programming Language :: Python :: 3.8
20
+ Classifier: Programming Language :: Python :: 3.9
21
+ Classifier: Programming Language :: Python :: 3.10
22
+ Classifier: Programming Language :: Python :: 3 :: Only
23
+ Requires-Python: >=3.11
24
+ Description-Content-Type: text/markdown
25
+ License-File: license.txt
26
+ Requires-Dist: kombu>=5.4.2
27
+ Requires-Dist: requests>=2.32.3
28
+
29
+ This package contains atk enforcement common entities and components
@@ -0,0 +1 @@
1
+ This package contains atk enforcement common entities and components
@@ -0,0 +1,7 @@
1
+ Copyright 2023 Perspic AS
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,4 @@
1
+ # pyproject.toml file specified at the root of the directory
2
+ [build-system]
3
+ requires = ["setuptools>=42", "wheel"] # PEP 508 specifications.
4
+ build-backend = "setuptools.build_meta"
@@ -0,0 +1,30 @@
1
+ [metadata]
2
+ name = atk_common
3
+ version = 1.0.0
4
+ author = Roger Jakobsen
5
+ author_email = roger@rogerjakobsen.no
6
+ description = Atk enforcement common entities and components
7
+ long_description = file: README.md, LICENSE.txt
8
+ long_description_content_type = text/markdown
9
+ url = https://github.com/perspictech/bo-atk-common
10
+ project_urls =
11
+ Bug Tracker = https://github.com/perspictech/bo-atk-common/-/issues
12
+ repository = https://github.com/perspictech/bo-atk-common
13
+ classifiers =
14
+ Programming Language :: Python :: 3
15
+ License :: OSI Approved :: MIT License
16
+ Operating System :: OS Independent
17
+
18
+ [options]
19
+ package_dir =
20
+ = src
21
+ packages = find:
22
+ python_requires = >=3.6
23
+
24
+ [options.packages.find]
25
+ where = src
26
+
27
+ [egg_info]
28
+ tag_build =
29
+ tag_date = 0
30
+
@@ -0,0 +1,173 @@
1
+ """A setuptools based setup module.
2
+
3
+ See:
4
+ https://packaging.python.org/guides/distributing-packages-using-setuptools/
5
+ https://github.com/pypa/atk_common
6
+ """
7
+
8
+ # Always prefer setuptools over distutils
9
+ from setuptools import setup, find_packages
10
+ import pathlib
11
+
12
+ here = pathlib.Path(__file__).parent.resolve()
13
+
14
+ # Get the long description from the README file
15
+ long_description = (here / "README.md").read_text(encoding="utf-8")
16
+
17
+ # Arguments marked as "Required" below must be included for upload to PyPI.
18
+ # Fields marked as "Optional" may be commented out.
19
+
20
+ setup(
21
+ # This is the name of your project. The first time you publish this
22
+ # package, this name will be registered for you. It will determine how
23
+ # users can install this project, e.g.:
24
+ #
25
+ # $ pip install atk_common
26
+ #
27
+ # And where it will live on PyPI: https://pypi.org/project/atk_common/
28
+ #
29
+ # There are some restrictions on what makes a valid project name
30
+ # specification here:
31
+ # https://packaging.python.org/specifications/core-metadata/#name
32
+ name="atk_common", # Required
33
+ # Versions should comply with PEP 440:
34
+ # https://www.python.org/dev/peps/pep-0440/
35
+ #
36
+ # For a discussion on single-sourcing the version across setup.py and the
37
+ # project code, see
38
+ # https://packaging.python.org/guides/single-sourcing-package-version/
39
+ version="0.2.0", # Required
40
+ # This is a one-line description or tagline of what your project does. This
41
+ # corresponds to the "Summary" metadata field:
42
+ # https://packaging.python.org/specifications/core-metadata/#summary
43
+ description="ATK common methods", # Optional
44
+ # This is an optional longer description of your project that represents
45
+ # the body of text which users will see when they visit PyPI.
46
+ #
47
+ # Often, this is the same as your README, so you can just read it in from
48
+ # that file directly (as we have already done above)
49
+ #
50
+ # This field corresponds to the "Description" metadata field:
51
+ # https://packaging.python.org/specifications/core-metadata/#description-optional
52
+ long_description=long_description, # Optional
53
+ # Denotes that our long_description is in Markdown; valid values are
54
+ # text/plain, text/x-rst, and text/markdown
55
+ #
56
+ # Optional if long_description is written in reStructuredText (rst) but
57
+ # required for plain-text or Markdown; if unspecified, "applications should
58
+ # attempt to render [the long_description] as text/x-rst; charset=UTF-8 and
59
+ # fall back to text/plain if it is not valid rst" (see link below)
60
+ #
61
+ # This field corresponds to the "Description-Content-Type" metadata field:
62
+ # https://packaging.python.org/specifications/core-metadata/#description-content-type-optional
63
+ long_description_content_type="text/markdown", # Optional (see note above)
64
+ # This should be a valid link to your project's main homepage.
65
+ #
66
+ # This field corresponds to the "Home-Page" metadata field:
67
+ # https://packaging.python.org/specifications/core-metadata/#home-page-optional
68
+ url="https://github.com/pypa/atk_common", # Optional
69
+ # This should be your name or the name of the organization which owns the
70
+ # project.
71
+ author="Roger", # Optional
72
+ # This should be a valid email address corresponding to the author listed
73
+ # above.
74
+ author_email="roger@perspic.tech", # Optional
75
+ # Classifiers help users find your project by categorizing it.
76
+ #
77
+ # For a list of valid classifiers, see https://pypi.org/classifiers/
78
+ classifiers=[ # Optional
79
+ # How mature is this project? Common values are
80
+ # 3 - Alpha
81
+ # 4 - Beta
82
+ # 5 - Production/Stable
83
+ "Development Status :: 3 - Alpha",
84
+ # Indicate who your project is intended for
85
+ "Intended Audience :: Developers",
86
+ "Topic :: Software Development :: Build Tools",
87
+ # Pick your license as you wish
88
+ "License :: OSI Approved :: MIT License",
89
+ # Specify the Python versions you support here. In particular, ensure
90
+ # that you indicate you support Python 3. These classifiers are *not*
91
+ # checked by 'pip install'. See instead 'python_requires' below.
92
+ "Programming Language :: Python :: 3",
93
+ "Programming Language :: Python :: 3.7",
94
+ "Programming Language :: Python :: 3.8",
95
+ "Programming Language :: Python :: 3.9",
96
+ "Programming Language :: Python :: 3.10",
97
+ "Programming Language :: Python :: 3 :: Only",
98
+ ],
99
+ # This field adds keywords for your project which will appear on the
100
+ # project page. What does your project relate to?
101
+ #
102
+ # Note that this is a list of additional keywords, separated
103
+ # by commas, to be used to assist searching for the distribution in a
104
+ # larger catalog.
105
+ keywords="sample, setuptools, development", # Optional
106
+ # When your source code is in a subdirectory under the project root, e.g.
107
+ # `src/`, it is necessary to specify the `package_dir` argument.
108
+ package_dir={"": "src"}, # Optional
109
+ # You can just specify package directories manually here if your project is
110
+ # simple. Or you can use find_packages().
111
+ #
112
+ # Alternatively, if you just want to distribute a single Python file, use
113
+ # the `py_modules` argument instead as follows, which will expect a file
114
+ # called `my_module.py` to exist:
115
+ #
116
+ # py_modules=["my_module"],
117
+ #
118
+ packages=find_packages(where="src"), # Required
119
+ # Specify which Python versions you support. In contrast to the
120
+ # 'Programming Language' classifiers above, 'pip install' will check this
121
+ # and refuse to install the project if the version does not match. See
122
+ # https://packaging.python.org/guides/distributing-packages-using-setuptools/#python-requires
123
+ python_requires='>=3.11',
124
+ # This field lists other packages that your project depends on to run.
125
+ # Any package you put here will be installed by pip when your project is
126
+ # installed, so they must be valid existing projects.
127
+ #
128
+ # For an analysis of "install_requires" vs pip's requirements files see:
129
+ # https://packaging.python.org/discussions/install-requires-vs-requirements/
130
+ install_requires=[ # List external dependencies here
131
+ 'kombu>=5.4.2',
132
+ 'requests>=2.32.3'
133
+ ],
134
+ # List additional groups of dependencies here (e.g. development
135
+ # dependencies). Users will be able to install these using the "extras"
136
+ # syntax, for example:
137
+ #
138
+ # $ pip install atk_common[dev]
139
+ #
140
+ # Similar to `install_requires` above, these must be valid existing
141
+ # projects.
142
+ # extras_require={ # Optional
143
+ # "dev": ["check-manifest"],
144
+ # "test": ["coverage"],
145
+ # },
146
+ # If there are data files included in your packages that need to be
147
+ # installed, specify them here.
148
+ # package_data={ # Optional
149
+ # "sample": ["package_data.dat"],
150
+ # },
151
+ # Entry points. The following would provide a command called `sample` which
152
+ # executes the function `main` from this package when invoked:
153
+ # entry_points={ # Optional
154
+ # "console_scripts": [
155
+ # "sample=sample:main",
156
+ # ],
157
+ # },
158
+ # List additional URLs that are relevant to your project as a dict.
159
+ #
160
+ # This field corresponds to the "Project-URL" metadata fields:
161
+ # https://packaging.python.org/specifications/core-metadata/#project-url-multiple-use
162
+ #
163
+ # Examples listed include a pattern for specifying where the package tracks
164
+ # issues, where the source is hosted, where to say thanks to the package
165
+ # maintainers, and where to support the project financially. The key is
166
+ # what's used to render the link text on PyPI.
167
+ project_urls={ # Optional
168
+ "Bug Reports": "https://github.com/pypa/atk_common/issues",
169
+ "Funding": "https://donate.pypi.org",
170
+ "Say Thanks!": "http://saythanks.io/to/example",
171
+ "Source": "https://github.com/pypa/atk_common/",
172
+ },
173
+ )
@@ -0,0 +1,29 @@
1
+ Metadata-Version: 2.1
2
+ Name: atk_common
3
+ Version: 0.2.0
4
+ Summary: ATK common methods
5
+ Home-page: https://github.com/pypa/atk_common
6
+ Author: Roger
7
+ Author-email: roger@perspic.tech
8
+ Project-URL: Bug Reports, https://github.com/pypa/atk_common/issues
9
+ Project-URL: Funding, https://donate.pypi.org
10
+ Project-URL: Say Thanks!, http://saythanks.io/to/example
11
+ Project-URL: Source, https://github.com/pypa/atk_common/
12
+ Keywords: sample,setuptools,development
13
+ Classifier: Development Status :: 3 - Alpha
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Topic :: Software Development :: Build Tools
16
+ Classifier: License :: OSI Approved :: MIT License
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.7
19
+ Classifier: Programming Language :: Python :: 3.8
20
+ Classifier: Programming Language :: Python :: 3.9
21
+ Classifier: Programming Language :: Python :: 3.10
22
+ Classifier: Programming Language :: Python :: 3 :: Only
23
+ Requires-Python: >=3.11
24
+ Description-Content-Type: text/markdown
25
+ License-File: license.txt
26
+ Requires-Dist: kombu>=5.4.2
27
+ Requires-Dist: requests>=2.32.3
28
+
29
+ This package contains atk enforcement common entities and components
@@ -0,0 +1,15 @@
1
+ README.md
2
+ license.txt
3
+ pyproject.toml
4
+ setup.cfg
5
+ setup.py
6
+ src/atk_common.egg-info/PKG-INFO
7
+ src/atk_common.egg-info/SOURCES.txt
8
+ src/atk_common.egg-info/dependency_links.txt
9
+ src/atk_common.egg-info/requires.txt
10
+ src/atk_common.egg-info/top_level.txt
11
+ src/atk_package/__init__.py
12
+ src/atk_package/datetime_utils.py
13
+ src/atk_package/log_utils.py
14
+ src/atk_package/rabbitmq_consumer.py
15
+ src/shared_python_atk_enforcement/__init__.py
@@ -0,0 +1,2 @@
1
+ kombu>=5.4.2
2
+ requests>=2.32.3
@@ -0,0 +1,2 @@
1
+ atk_package
2
+ shared_python_atk_enforcement
@@ -0,0 +1,4 @@
1
+ # __init__.py
2
+ from .rabbitmq_consumer import RabbitMQConsumer
3
+ from .datetime_utils import date_time_utc, get_utc_date_time
4
+ from .log_utils import add_log_item, add_log_item_http
@@ -0,0 +1,7 @@
1
+ from datetime import datetime, timezone
2
+
3
+ def date_time_utc(column):
4
+ return 'TO_CHAR({0} at time zone \'UTC\', \'yyyy-mm-dd hh24:mi:ss.ms"Z"\')'.format(column)
5
+
6
+ def get_utc_date_time():
7
+ return str(datetime.now(timezone.utc))
@@ -0,0 +1,16 @@
1
+ from datetime import datetime
2
+ from datetime_utils import get_utc_date_time
3
+
4
+ def create_date_time():
5
+ date_time = get_utc_date_time()
6
+ return '[' + date_time + '] '
7
+
8
+ def add_log_item(text):
9
+ print(create_date_time() + text)
10
+
11
+ def add_log_item_http(resp):
12
+ if resp.status_code == 500:
13
+ err_resp_json = resp.json().get('message')
14
+ add_log_item(err_resp_json)
15
+ else:
16
+ add_log_item(resp.text)
@@ -0,0 +1,49 @@
1
+ from kombu import Connection, Exchange, Queue, Consumer
2
+ import socket
3
+ import time
4
+
5
+ class RabbitMQConsumer:
6
+ def __init__(self, queue_name, user, pwd, host, vhost, dlx, dlq, encoding, message_handler, log):
7
+
8
+ rabbit_url = 'amqp://' + user + ':' + pwd + '@' + host + '/' + vhost
9
+
10
+ self.connection = Connection(rabbit_url, heartbeat=10)
11
+ queue = None
12
+ if dlx is not None and dlq is not None:
13
+ queue = Queue(name=queue_name,
14
+ queue_arguments={
15
+ 'x-dead-letter-exchange': dlx,
16
+ 'x-dead-letter-routing-key': dlq},
17
+ )
18
+ else:
19
+ queue = Queue(name=queue_name)
20
+ self.consumer = Consumer(self.connection, queues=queue, callbacks=[message_handler], accept=[encoding])
21
+ self.consumer.consume()
22
+
23
+ self.message_handler = message_handler # Custom message handler
24
+ self.log = log
25
+
26
+ def consume(self):
27
+ new_conn = self.establish_connection()
28
+ while True:
29
+ try:
30
+ new_conn.drain_events(timeout=2)
31
+ except socket.timeout:
32
+ new_conn.heartbeat_check()
33
+
34
+ def establish_connection(self):
35
+ revived_connection = self.connection.clone()
36
+ revived_connection.ensure_connection(max_retries=3)
37
+ channel = revived_connection.channel()
38
+ self.consumer.revive(channel)
39
+ self.consumer.consume()
40
+ self.log("Connection revived!")
41
+ return revived_connection
42
+
43
+ def run(self):
44
+ while True:
45
+ try:
46
+ self.consume()
47
+ except self.connection.connection_errors:
48
+ pass
49
+