devopsdriver 0.1.35__tar.gz → 0.1.37__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.
Files changed (31) hide show
  1. devopsdriver-0.1.37/PKG-INFO +230 -0
  2. devopsdriver-0.1.37/README.md +176 -0
  3. devopsdriver-0.1.37/devopsdriver/__init__.py +10 -0
  4. {devopsdriver-0.1.35/devopsdriver/azure → devopsdriver-0.1.37/devopsdriver/azdo}/clients.py +1 -1
  5. {devopsdriver-0.1.35/devopsdriver/azure → devopsdriver-0.1.37/devopsdriver/azdo}/workitem/client.py +2 -2
  6. {devopsdriver-0.1.35/devopsdriver/azure → devopsdriver-0.1.37/devopsdriver/azdo}/workitem/wiql.py +2 -2
  7. devopsdriver-0.1.37/devopsdriver/sendmail.py +88 -0
  8. {devopsdriver-0.1.35 → devopsdriver-0.1.37}/devopsdriver/settings.py +10 -3
  9. devopsdriver-0.1.37/devopsdriver/template.py +40 -0
  10. devopsdriver-0.1.37/devopsdriver.egg-info/PKG-INFO +230 -0
  11. {devopsdriver-0.1.35 → devopsdriver-0.1.37}/devopsdriver.egg-info/SOURCES.txt +11 -7
  12. {devopsdriver-0.1.35 → devopsdriver-0.1.37}/devopsdriver.egg-info/requires.txt +1 -0
  13. {devopsdriver-0.1.35 → devopsdriver-0.1.37}/pyproject.toml +1 -0
  14. {devopsdriver-0.1.35 → devopsdriver-0.1.37}/tests/test_azure_clients.py +1 -1
  15. {devopsdriver-0.1.35 → devopsdriver-0.1.37}/tests/test_azure_workitem.py +1 -1
  16. {devopsdriver-0.1.35 → devopsdriver-0.1.37}/tests/test_azure_workitem_client.py +2 -2
  17. {devopsdriver-0.1.35 → devopsdriver-0.1.37}/tests/test_azure_workitem_wiql.py +8 -8
  18. devopsdriver-0.1.37/tests/test_sendmail.py +151 -0
  19. {devopsdriver-0.1.35 → devopsdriver-0.1.37}/tests/test_settings.py +18 -20
  20. devopsdriver-0.1.37/tests/test_template.py +29 -0
  21. devopsdriver-0.1.35/PKG-INFO +0 -76
  22. devopsdriver-0.1.35/README.md +0 -23
  23. devopsdriver-0.1.35/devopsdriver/__init__.py +0 -7
  24. devopsdriver-0.1.35/devopsdriver.egg-info/PKG-INFO +0 -76
  25. {devopsdriver-0.1.35 → devopsdriver-0.1.37}/LICENSE +0 -0
  26. {devopsdriver-0.1.35/devopsdriver/azure → devopsdriver-0.1.37/devopsdriver/azdo}/__init__.py +0 -0
  27. {devopsdriver-0.1.35/devopsdriver/azure → devopsdriver-0.1.37/devopsdriver/azdo}/workitem/__init__.py +0 -0
  28. {devopsdriver-0.1.35/devopsdriver/azure → devopsdriver-0.1.37/devopsdriver/azdo}/workitem/workitem.py +0 -0
  29. {devopsdriver-0.1.35 → devopsdriver-0.1.37}/devopsdriver.egg-info/dependency_links.txt +0 -0
  30. {devopsdriver-0.1.35 → devopsdriver-0.1.37}/devopsdriver.egg-info/top_level.txt +0 -0
  31. {devopsdriver-0.1.35 → devopsdriver-0.1.37}/setup.cfg +0 -0
@@ -0,0 +1,230 @@
1
+ Metadata-Version: 2.1
2
+ Name: devopsdriver
3
+ Version: 0.1.37
4
+ Summary: DevOps tools
5
+ Author-email: Marc Page <marcallenpage@gmail.com>
6
+ License: This is free and unencumbered software released into the public domain.
7
+
8
+ Anyone is free to copy, modify, publish, use, compile, sell, or
9
+ distribute this software, either in source code form or as a compiled
10
+ binary, for any purpose, commercial or non-commercial, and by any
11
+ means.
12
+
13
+ In jurisdictions that recognize copyright laws, the author or authors
14
+ of this software dedicate any and all copyright interest in the
15
+ software to the public domain. We make this dedication for the benefit
16
+ of the public at large and to the detriment of our heirs and
17
+ successors. We intend this dedication to be an overt act of
18
+ relinquishment in perpetuity of all present and future rights to this
19
+ software under copyright law.
20
+
21
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24
+ IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
25
+ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
26
+ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27
+ OTHER DEALINGS IN THE SOFTWARE.
28
+
29
+ For more information, please refer to <https://unlicense.org>
30
+
31
+ Project-URL: Homepage, https://github.com/marcpage/devops-driver
32
+ Project-URL: Documentation, https://github.com/marcpage/devops-driver
33
+ Project-URL: Repository, https://github.com/marcpage/devops-driver.git
34
+ Project-URL: Issues, https://github.com/marcpage/devops-driver/issues
35
+ Project-URL: Changelog, https://github.com/marcpage/devops-driver
36
+ Keywords: azure,devops,jira,confluence,email,pipelines,tools
37
+ Classifier: Development Status :: 1 - Planning
38
+ Classifier: Environment :: Console
39
+ Classifier: Intended Audience :: Developers
40
+ Classifier: Programming Language :: Python
41
+ Classifier: Programming Language :: Python :: 3
42
+ Classifier: License :: OSI Approved :: The Unlicense (Unlicense)
43
+ Classifier: Programming Language :: Python :: 3.12
44
+ Classifier: Topic :: Utilities
45
+ Classifier: Topic :: Software Development
46
+ Requires-Python: >=3.10
47
+ Description-Content-Type: text/markdown
48
+ License-File: LICENSE
49
+ Requires-Dist: PyYAML==6.0.1
50
+ Requires-Dist: keyring==25.0.0
51
+ Requires-Dist: setuptools==69.0.2
52
+ Requires-Dist: azure-devops==7.1.0b4
53
+ Requires-Dist: Mako==1.3.2
54
+
55
+ ![status sheild](https://img.shields.io/static/v1?label=status&message=beta&color=blue&style=plastic)
56
+ [![status sheild](https://img.shields.io/static/v1?label=released&message=v0.1.37&color=active&style=plastic)](https://pypi.org/project/devopsdriver/0.1.37/)
57
+ [![GitHub](https://img.shields.io/github/license/marcpage/devops-driver?style=plastic)](https://github.com/marcpage/devops-driver?tab=Unlicense-1-ov-file#readme)
58
+ [![GitHub contributors](https://img.shields.io/github/contributors/marcpage/devops-driver?style=flat)](https://github.com/marcpage/devops-driver/graphs/contributors)
59
+ [![PR's Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat)](http://makeapullrequest.com)
60
+
61
+ [![commit sheild](https://img.shields.io/github/last-commit/marcpage/devops-driver?style=plastic)](https://github.com/marcpage/devops-driver/commits)
62
+ [![activity sheild](https://img.shields.io/github/commit-activity/m/marcpage/devops-driver?style=plastic)](https://github.com/marcpage/devops-driver/commits)
63
+ [![GitHub top language](https://img.shields.io/github/languages/top/marcpage/devops-driver?style=plastic)](https://github.com/marcpage/devops-driver)
64
+ [![size sheild](https://img.shields.io/github/languages/code-size/marcpage/devops-driver?style=plastic)](https://github.com/marcpage/devops-driver)
65
+
66
+ [![example workflow](https://github.com/marcpage/devops-driver/actions/workflows/pr.yml/badge.svg)](https://github.com/marcpage/devops-driver/actions/workflows/pr.yml)
67
+ [![status sheild](https://img.shields.io/static/v1?label=test+coverage&message=99%&color=active&style=plastic)](https://github.com/marcpage/devops-driver/blob/main/Makefile#L4)
68
+ [![issues sheild](https://img.shields.io/github/issues-raw/marcpage/devops-driver?style=plastic)](https://github.com/marcpage/devops-driver/issues)
69
+ [![GitHub pull requests](https://img.shields.io/github/issues-pr/marcpage/devops-driver?style=flat)](https://github.com/marcpage/devops-driver/pulls)
70
+
71
+ [![follow sheild](https://img.shields.io/github/followers/marcpage?label=Follow&style=social)](https://github.com/marcpage?tab=followers)
72
+ [![watch sheild](https://img.shields.io/github/watchers/marcpage/devops-driver?label=Watch&style=social)](https://github.com/marcpage/devops-driver/watchers)
73
+
74
+ [![Python](https://img.shields.io/static/v1?label=&message=Pure%20Python&color=ffde57&style=plastic&logo=python)](https://python.org/)
75
+ [![Azure](https://img.shields.io/static/v1?label=&message=Supports%20Microsoft%20Azure&color=blue&style=plastic&logo=microsoftazure)](https://azure.microsoft.com/)
76
+ [![Gmail](https://img.shields.io/static/v1?label=&message=Supports%20Google%20Gmail&color=white&style=plastic&logo=gmail)](https://gmail.com/)
77
+
78
+ OS:
79
+ [![Windows](https://img.shields.io/static/v1?label=&message=Windows&color=blue&style=plastic&logo=windows)](https://microsoft.com/)
80
+ [![macOS](https://img.shields.io/static/v1?label=&message=macOS&color=white&logoColor=black&style=plastic&logo=apple)](https://apple.com/)
81
+ [![Linux](https://img.shields.io/static/v1?label=&message=Linux&color=seashell&logoColor=black&style=plastic&logo=linux)](https://linux.org/)
82
+
83
+ # devops-driver
84
+
85
+ Devops-driver is a collection of tools to help streamline developer's experience and gain insights into various processes.
86
+
87
+ ## Access to secrets
88
+
89
+ To allow seamless work in both pipelines as well as in the development environment, the `Settings` object gives you access to common settings among multiple scripts, secrets, and configuration constants in a way the helps keep secrets out of the repository but runs just as well in the pipeline as your machine.
90
+
91
+ Say you want a pipeline that looks for User Stories that are newer than 3 days and send out an email.
92
+
93
+ ### \<platform dependent path\>/devopsdriver.yml
94
+ ```yaml
95
+ smtp:
96
+ sender: JohnDoe@company.com
97
+
98
+ secrets:
99
+ azure.token: azure/token
100
+ smtp.password: smtp/password
101
+ ```
102
+
103
+ This file is in a global place (location varies by OS) and stores information that you may not want in your repository or is specific to development.
104
+ The `secrets` are extra sensative and are stored in the OS keychain.
105
+
106
+ | Platform | Global Directory |
107
+ |----------|------------------------|
108
+ | Windows | %APPDATA%\ |
109
+ | Linux | ~/.devopsdriver/ |
110
+ | macOS | ~/Library/Preferences/ |
111
+
112
+ ### Set secrets in the keychain
113
+ ```bash
114
+ $ python3 -m venv .venv
115
+ $ source .venv/bin/activate
116
+ $ pip install devopsdriver
117
+ $ python -m devopsdriver.settings --secrets
118
+ secret: smtp.password key: smtp/password
119
+ smtp.password (smtp/password): ****
120
+ secret: azure.token key: azure/token
121
+ smtp.password (azure/token): ****
122
+ $ python -m devopsdriver.settings --secrets
123
+ secret: azure.token key: azure/token
124
+ Value set
125
+ secret: smtp.password key: smtp/password
126
+ Value set
127
+ $
128
+ ```
129
+ The first call to `devopsdriver.settings` will look for every secret and check if they are already set in the keychain.
130
+ For any secret that has not been set in the keychain, you will be prompted to enter the password to store.
131
+ The second call to `devopsdriver.settings` will verify that all the values have been set in the keychain.
132
+
133
+ ### devopsdriver.yml
134
+ ```yaml
135
+ azure:
136
+ url: https://dev.azure.com/MyCompany
137
+
138
+ smtp:
139
+ server: smtp.company.com
140
+ port: 465
141
+
142
+ cli:
143
+ azure.token: --azure-token
144
+ smtp.password: --smtp-password
145
+ smtp.sender: --smtp-sender
146
+
147
+ env:
148
+ azure.token: AZURE_TOKEN
149
+ smtp.sender: SMTP_SENDER
150
+ smtp.password: SMTP_PASSWORD
151
+ ```
152
+
153
+ This file lives next to your scripts in your repository.
154
+ These are settings that would be used by everyone, including the pipeline.
155
+ The `cli` and `env` map command line switches and environment variables to those keys.
156
+ This allows for many options for setting values depending on your needs.
157
+
158
+ ### new_stories.yml
159
+ ```yaml
160
+ scrum masters:
161
+ - JohnDoe@company.com
162
+ - JaneDoe@company.com
163
+ ```
164
+ This file is specific to your script and not shared.
165
+ These are values that you want to use in your script but have them here for easy adjustment.
166
+
167
+ ### new_stories.html.mako
168
+ ```html
169
+ <h1>Stories created in the last ${days} days</h1>
170
+ <ul>
171
+ % for story in stories:
172
+ <li>${story.id} ${story.title}</li>
173
+ % endfor
174
+ </ul>
175
+ ```
176
+
177
+ ### new_stories.py
178
+ ```python
179
+ from datetime import date, timedelta
180
+
181
+ from devopsdriver import Settings, Azure, send_email, Template
182
+ from devopsdriver.azdo import Wiql, GreaterThan
183
+
184
+ # Parse all the settings from files, command line, environment, and keychain
185
+ settings = Settings(__file__).key("secrets").cli("cli").env("env")
186
+
187
+ # Create connection to Azure Devops
188
+ azure = Azure(settings)
189
+
190
+ # Get User Stories created in the last three days
191
+ three_days_ago = date.today() - timedelta(days=settings["days of recent stories"])
192
+ new_stories = azure.workitem.find(
193
+ Wiql().where(GreaterThan("CreatedDate", three_days_ago))
194
+ )
195
+
196
+ # Generate html body of the email
197
+ message = Template(__file__).render(
198
+ days=settings["days of recent stories"],
199
+ stories=new_stories,
200
+ )
201
+
202
+ # Send the email
203
+ send_email(
204
+ recipients=settings["scrum masters"],
205
+ subject=f'Stories created in the last {settings["days of recent stories"]} days',
206
+ html_body=message,
207
+ settings=settings,
208
+ )
209
+ ```
210
+
211
+ ### The email sent
212
+
213
+ **From**: JohnDoe@company.com
214
+
215
+ **To**: JohnDoe@company.com, JaneDoe@company.com
216
+
217
+ **Subject**: Stories created in the last 3 days
218
+
219
+ #### Stories created in the last 3 days
220
+
221
+ - 745 Needs a preprocessing step that makes it case insensitive
222
+ - 749 Create GitHub action to automate process
223
+ - 750 Create GitHub action to automate process
224
+ - 751 Test
225
+ - 752 Feedback Capture
226
+ - 753 draft doc history retrieval method
227
+ - 754 frontend - store to schema
228
+ - 755 Transfer job to production. Setup migrations to move to production
229
+ - 756 Query subscription status from App
230
+
@@ -0,0 +1,176 @@
1
+ ![status sheild](https://img.shields.io/static/v1?label=status&message=beta&color=blue&style=plastic)
2
+ [![status sheild](https://img.shields.io/static/v1?label=released&message=v0.1.37&color=active&style=plastic)](https://pypi.org/project/devopsdriver/0.1.37/)
3
+ [![GitHub](https://img.shields.io/github/license/marcpage/devops-driver?style=plastic)](https://github.com/marcpage/devops-driver?tab=Unlicense-1-ov-file#readme)
4
+ [![GitHub contributors](https://img.shields.io/github/contributors/marcpage/devops-driver?style=flat)](https://github.com/marcpage/devops-driver/graphs/contributors)
5
+ [![PR's Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat)](http://makeapullrequest.com)
6
+
7
+ [![commit sheild](https://img.shields.io/github/last-commit/marcpage/devops-driver?style=plastic)](https://github.com/marcpage/devops-driver/commits)
8
+ [![activity sheild](https://img.shields.io/github/commit-activity/m/marcpage/devops-driver?style=plastic)](https://github.com/marcpage/devops-driver/commits)
9
+ [![GitHub top language](https://img.shields.io/github/languages/top/marcpage/devops-driver?style=plastic)](https://github.com/marcpage/devops-driver)
10
+ [![size sheild](https://img.shields.io/github/languages/code-size/marcpage/devops-driver?style=plastic)](https://github.com/marcpage/devops-driver)
11
+
12
+ [![example workflow](https://github.com/marcpage/devops-driver/actions/workflows/pr.yml/badge.svg)](https://github.com/marcpage/devops-driver/actions/workflows/pr.yml)
13
+ [![status sheild](https://img.shields.io/static/v1?label=test+coverage&message=99%&color=active&style=plastic)](https://github.com/marcpage/devops-driver/blob/main/Makefile#L4)
14
+ [![issues sheild](https://img.shields.io/github/issues-raw/marcpage/devops-driver?style=plastic)](https://github.com/marcpage/devops-driver/issues)
15
+ [![GitHub pull requests](https://img.shields.io/github/issues-pr/marcpage/devops-driver?style=flat)](https://github.com/marcpage/devops-driver/pulls)
16
+
17
+ [![follow sheild](https://img.shields.io/github/followers/marcpage?label=Follow&style=social)](https://github.com/marcpage?tab=followers)
18
+ [![watch sheild](https://img.shields.io/github/watchers/marcpage/devops-driver?label=Watch&style=social)](https://github.com/marcpage/devops-driver/watchers)
19
+
20
+ [![Python](https://img.shields.io/static/v1?label=&message=Pure%20Python&color=ffde57&style=plastic&logo=python)](https://python.org/)
21
+ [![Azure](https://img.shields.io/static/v1?label=&message=Supports%20Microsoft%20Azure&color=blue&style=plastic&logo=microsoftazure)](https://azure.microsoft.com/)
22
+ [![Gmail](https://img.shields.io/static/v1?label=&message=Supports%20Google%20Gmail&color=white&style=plastic&logo=gmail)](https://gmail.com/)
23
+
24
+ OS:
25
+ [![Windows](https://img.shields.io/static/v1?label=&message=Windows&color=blue&style=plastic&logo=windows)](https://microsoft.com/)
26
+ [![macOS](https://img.shields.io/static/v1?label=&message=macOS&color=white&logoColor=black&style=plastic&logo=apple)](https://apple.com/)
27
+ [![Linux](https://img.shields.io/static/v1?label=&message=Linux&color=seashell&logoColor=black&style=plastic&logo=linux)](https://linux.org/)
28
+
29
+ # devops-driver
30
+
31
+ Devops-driver is a collection of tools to help streamline developer's experience and gain insights into various processes.
32
+
33
+ ## Access to secrets
34
+
35
+ To allow seamless work in both pipelines as well as in the development environment, the `Settings` object gives you access to common settings among multiple scripts, secrets, and configuration constants in a way the helps keep secrets out of the repository but runs just as well in the pipeline as your machine.
36
+
37
+ Say you want a pipeline that looks for User Stories that are newer than 3 days and send out an email.
38
+
39
+ ### \<platform dependent path\>/devopsdriver.yml
40
+ ```yaml
41
+ smtp:
42
+ sender: JohnDoe@company.com
43
+
44
+ secrets:
45
+ azure.token: azure/token
46
+ smtp.password: smtp/password
47
+ ```
48
+
49
+ This file is in a global place (location varies by OS) and stores information that you may not want in your repository or is specific to development.
50
+ The `secrets` are extra sensative and are stored in the OS keychain.
51
+
52
+ | Platform | Global Directory |
53
+ |----------|------------------------|
54
+ | Windows | %APPDATA%\ |
55
+ | Linux | ~/.devopsdriver/ |
56
+ | macOS | ~/Library/Preferences/ |
57
+
58
+ ### Set secrets in the keychain
59
+ ```bash
60
+ $ python3 -m venv .venv
61
+ $ source .venv/bin/activate
62
+ $ pip install devopsdriver
63
+ $ python -m devopsdriver.settings --secrets
64
+ secret: smtp.password key: smtp/password
65
+ smtp.password (smtp/password): ****
66
+ secret: azure.token key: azure/token
67
+ smtp.password (azure/token): ****
68
+ $ python -m devopsdriver.settings --secrets
69
+ secret: azure.token key: azure/token
70
+ Value set
71
+ secret: smtp.password key: smtp/password
72
+ Value set
73
+ $
74
+ ```
75
+ The first call to `devopsdriver.settings` will look for every secret and check if they are already set in the keychain.
76
+ For any secret that has not been set in the keychain, you will be prompted to enter the password to store.
77
+ The second call to `devopsdriver.settings` will verify that all the values have been set in the keychain.
78
+
79
+ ### devopsdriver.yml
80
+ ```yaml
81
+ azure:
82
+ url: https://dev.azure.com/MyCompany
83
+
84
+ smtp:
85
+ server: smtp.company.com
86
+ port: 465
87
+
88
+ cli:
89
+ azure.token: --azure-token
90
+ smtp.password: --smtp-password
91
+ smtp.sender: --smtp-sender
92
+
93
+ env:
94
+ azure.token: AZURE_TOKEN
95
+ smtp.sender: SMTP_SENDER
96
+ smtp.password: SMTP_PASSWORD
97
+ ```
98
+
99
+ This file lives next to your scripts in your repository.
100
+ These are settings that would be used by everyone, including the pipeline.
101
+ The `cli` and `env` map command line switches and environment variables to those keys.
102
+ This allows for many options for setting values depending on your needs.
103
+
104
+ ### new_stories.yml
105
+ ```yaml
106
+ scrum masters:
107
+ - JohnDoe@company.com
108
+ - JaneDoe@company.com
109
+ ```
110
+ This file is specific to your script and not shared.
111
+ These are values that you want to use in your script but have them here for easy adjustment.
112
+
113
+ ### new_stories.html.mako
114
+ ```html
115
+ <h1>Stories created in the last ${days} days</h1>
116
+ <ul>
117
+ % for story in stories:
118
+ <li>${story.id} ${story.title}</li>
119
+ % endfor
120
+ </ul>
121
+ ```
122
+
123
+ ### new_stories.py
124
+ ```python
125
+ from datetime import date, timedelta
126
+
127
+ from devopsdriver import Settings, Azure, send_email, Template
128
+ from devopsdriver.azdo import Wiql, GreaterThan
129
+
130
+ # Parse all the settings from files, command line, environment, and keychain
131
+ settings = Settings(__file__).key("secrets").cli("cli").env("env")
132
+
133
+ # Create connection to Azure Devops
134
+ azure = Azure(settings)
135
+
136
+ # Get User Stories created in the last three days
137
+ three_days_ago = date.today() - timedelta(days=settings["days of recent stories"])
138
+ new_stories = azure.workitem.find(
139
+ Wiql().where(GreaterThan("CreatedDate", three_days_ago))
140
+ )
141
+
142
+ # Generate html body of the email
143
+ message = Template(__file__).render(
144
+ days=settings["days of recent stories"],
145
+ stories=new_stories,
146
+ )
147
+
148
+ # Send the email
149
+ send_email(
150
+ recipients=settings["scrum masters"],
151
+ subject=f'Stories created in the last {settings["days of recent stories"]} days',
152
+ html_body=message,
153
+ settings=settings,
154
+ )
155
+ ```
156
+
157
+ ### The email sent
158
+
159
+ **From**: JohnDoe@company.com
160
+
161
+ **To**: JohnDoe@company.com, JaneDoe@company.com
162
+
163
+ **Subject**: Stories created in the last 3 days
164
+
165
+ #### Stories created in the last 3 days
166
+
167
+ - 745 Needs a preprocessing step that makes it case insensitive
168
+ - 749 Create GitHub action to automate process
169
+ - 750 Create GitHub action to automate process
170
+ - 751 Test
171
+ - 752 Feedback Capture
172
+ - 753 draft doc history retrieval method
173
+ - 754 frontend - store to schema
174
+ - 755 Transfer job to production. Setup migrations to move to production
175
+ - 756 Query subscription status from App
176
+
@@ -0,0 +1,10 @@
1
+ """ DevOps tools """
2
+
3
+ from .azdo import Azure
4
+ from .settings import Settings
5
+ from .sendmail import send_email
6
+ from .template import Template
7
+
8
+ __version__ = "0.1.37"
9
+ __author__ = "Marc Page"
10
+ __credits__ = ""
@@ -11,7 +11,7 @@ from azure.devops.connection import Connection as AzureConnection
11
11
  from msrest.authentication import BasicAuthentication as MSBasicAuthentication
12
12
 
13
13
  from devopsdriver.settings import Settings
14
- from devopsdriver.azure.workitem.client import Client as WIClient
14
+ from devopsdriver.azdo.workitem.client import Client as WIClient
15
15
 
16
16
  CONNECTION = AzureConnection
17
17
  AUTHENTICATION = MSBasicAuthentication
@@ -6,8 +6,8 @@ from azure.devops.v7_1.work_item_tracking.models import Wiql as AzureWiql
6
6
  from azure.devops.v7_1.work_item_tracking.models import WorkItem as AzureWorkItem
7
7
  from azure.devops.v7_1.work_item_tracking.models import TeamContext
8
8
  from azure.devops.v7_1.work_item_tracking.models import WorkItemQueryResult
9
- from devopsdriver.azure.workitem import WorkItem
10
- from devopsdriver.azure.workitem.wiql import Wiql
9
+ from devopsdriver.azdo.workitem import WorkItem
10
+ from devopsdriver.azdo.workitem.wiql import Wiql
11
11
 
12
12
 
13
13
  class Client:
@@ -87,10 +87,10 @@ class Value: # pylint: disable=too-few-public-methods
87
87
 
88
88
  def __str__(self) -> str:
89
89
  if isinstance(self.value, datetime):
90
- return self.value.strftime("%Y-%m-%d %H:%M:%S")
90
+ return f'"{self.value.strftime("%m/%d/%Y %H:%M:%S")}"'
91
91
 
92
92
  if isinstance(self.value, date):
93
- return self.value.strftime("%Y-%m-%d")
93
+ return f'"{self.value.strftime("%m/%d/%Y")}"'
94
94
 
95
95
  if isinstance(self.value, int):
96
96
  return str(self.value)
@@ -0,0 +1,88 @@
1
+ #!/usr/bin/env python3
2
+
3
+ """ Ability to send emails with embedded images """
4
+ from smtplib import SMTP as OS_SMTP, SMTP_SSL as OS_SMTP_SSL
5
+ from email.mime.multipart import MIMEMultipart as OS_MIMEMultipart
6
+ from email.mime.text import MIMEText as OS_MIMEText
7
+ from email.mime.image import MIMEImage as OS_MIMEImage
8
+
9
+ from devopsdriver.settings import Settings
10
+
11
+ IMAGE_HEADERS = {".png": b"\x89PNG\r\n\x1a\n", ".jpg": b"\xff\xd8\xff"}
12
+
13
+ # for testing
14
+ MIMEMULTIPART = OS_MIMEMultipart
15
+ MIMETEXT = OS_MIMEText
16
+ MIMEIMAGE = OS_MIMEImage
17
+ SMTP = OS_SMTP
18
+ SMTPSSL = OS_SMTP_SSL
19
+
20
+
21
+ def image_extension(data: bytes) -> str:
22
+ """Given image data, determine the file extension
23
+
24
+ Args:
25
+ data (bytes): The image binary data
26
+
27
+ Raises:
28
+ AttributeError: If the data type is not recognized
29
+
30
+ Returns:
31
+ str: The extension, like ".png"
32
+ """
33
+ for extension, header in IMAGE_HEADERS.items():
34
+ if data.startswith(header):
35
+ return extension
36
+
37
+ raise AttributeError("Image not a known format: " + ",".join(IMAGE_HEADERS))
38
+
39
+
40
+ def send_email(
41
+ recipients: str | list[str],
42
+ subject: str,
43
+ html_body: str,
44
+ settings: Settings = None,
45
+ **image_data,
46
+ ):
47
+ """Sends an email with embedded images
48
+
49
+ Args:
50
+ recipients (str | list[str]): A single email address or a list of them
51
+ subject (str): Subject line
52
+ html_body (str): html formatted body. To reference an image in your
53
+ body, <img src="cid:image1"> if you pass image1=png.read()
54
+ settings (Settings, optional): The settings object. Defaults to None.
55
+ image_data (dict, optional): keyword image names to binary image data
56
+ """
57
+ settings = Settings(__file__).key("secrets") if settings is None else settings
58
+ required = {"smtp.sender", "smtp.server", "smtp.port", "smtp.password"}
59
+ missing = {r for r in required if r not in settings}
60
+ assert not missing, (
61
+ ", ".join(missing) + " not found in:\n" + "\n".join(settings.search_files)
62
+ )
63
+ sender = settings["smtp.sender"]
64
+ username = settings.get("smtp.username", sender)
65
+ message = MIMEMULTIPART()
66
+ message["Subject"] = subject
67
+ message["From"] = sender
68
+ message["To"] = ", ".join(
69
+ [recipients] if isinstance(recipients, str) else recipients
70
+ )
71
+ message.attach(MIMETEXT(html_body, "html"))
72
+ connection_type = SMTPSSL if settings.get("smtp.ssl", True) else SMTP
73
+
74
+ for name, binary_data in image_data.items():
75
+ image = MIMEIMAGE(binary_data)
76
+ image.add_header("Content-ID", f"<{name}>")
77
+ image.add_header(
78
+ "Content-Disposition",
79
+ "inline",
80
+ filename=name + image_extension(binary_data),
81
+ )
82
+ message.attach(image)
83
+
84
+ with connection_type(settings["smtp.server"], settings["smtp.port"]) as smtp:
85
+ smtp.set_debuglevel(False)
86
+ smtp.login(username, settings["smtp.password"])
87
+ smtp.sendmail(sender, recipients, message.as_string())
88
+ smtp.quit()
@@ -361,10 +361,17 @@ class Settings:
361
361
 
362
362
  def main() -> None:
363
363
  """Get settings values"""
364
- settings = Settings(__file__, dirname(dirname(__file__))).key("secrets")
365
-
366
364
  args = list(ARGV[1:])
367
365
 
366
+ if not args or "--help" in args or "-h" in args:
367
+ PRINT("pass in settings to see if they are set and to what value")
368
+ PRINT("You can pass dotted names to get inner values, like smpt.server")
369
+ PRINT("You can pass --secrets to set keychain values that have not been set")
370
+ PRINT("You can also pass --help or -h to get this message")
371
+ return
372
+
373
+ settings = Settings(__file__, dirname(dirname(__file__))).key("secrets")
374
+
368
375
  if "--secrets" in args:
369
376
  args.remove("--secrets")
370
377
 
@@ -380,7 +387,7 @@ def main() -> None:
380
387
  PRINT("\tValue set")
381
388
 
382
389
  for arg in args:
383
- PRINT(settings.get(arg))
390
+ PRINT(f"{settings.get(arg)}")
384
391
 
385
392
 
386
393
  if __name__ == "__main__":
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env python3
2
+
3
+ """ Module Doc """
4
+
5
+ from os.path import dirname, basename, splitext
6
+
7
+ from mako.lookup import TemplateLookup
8
+
9
+
10
+ class Template: # pylint: disable=too-few-public-methods
11
+ """render template files"""
12
+
13
+ def __init__(self, file: str, *search_dirs, extension=None):
14
+ self.template = file
15
+ self.extension = extension
16
+ self.lookup = TemplateLookup(
17
+ directories=[dirname(file), *search_dirs],
18
+ output_encoding="utf-8",
19
+ module_directory="/tmp/mako_modules",
20
+ )
21
+
22
+ def render(self, **args) -> str:
23
+ """Given a set of arguments, render the template
24
+
25
+ Args:
26
+ args (dict): variables and their values
27
+
28
+ Returns:
29
+ str: The rendered template
30
+ """
31
+ name = basename(self.template)
32
+ base, extension = splitext(name)
33
+
34
+ if self.extension:
35
+ name = base + self.extension
36
+
37
+ elif extension == ".py":
38
+ name = base + ".html.mako"
39
+
40
+ return self.lookup.get_template(name).render(**args).decode("utf-8")