cabinet 0.8.1__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.
cabinet-0.8.1/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright © 2023 Tyler Woodfin (https://www.tyler.cloud)
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.
cabinet-0.8.1/PKG-INFO ADDED
@@ -0,0 +1,320 @@
1
+ Metadata-Version: 2.1
2
+ Name: cabinet
3
+ Version: 0.8.1
4
+ Summary: Easily manage data storage and logging across repos
5
+ Home-page: https://github.com/tylerjwoodfin/cabinet
6
+ Author: Tyler Woodfin
7
+ Author-email: feedback@tyler.cloud
8
+ License: : OSI Approved :: MIT License
9
+ Requires-Python: >=3.6
10
+ Description-Content-Type: text/markdown
11
+ License-File: LICENSE
12
+
13
+ # cabinet
14
+ A Python library to easily manage data with MongoDB and across other files.
15
+ Supports a cli, email, and event logging.
16
+
17
+ ## Features
18
+
19
+ - Read and write data in MongoDB and/or the JSON files of your choice
20
+ - Provides easy shortcuts to MongoDB actions
21
+ - Log to a file/directory of your choice without having to configure `logger` each time
22
+ - Send/receive mail using `cabinet.Cabinet().mail()`
23
+
24
+ ## Dependencies
25
+
26
+ - Python >= 3.6
27
+ - MongoDB
28
+ - Pymongo (`pip install pymongo`)
29
+ - smtplib
30
+
31
+ ## Structure
32
+
33
+ - Data is stored in MongoDB; simply plug in your credentials.
34
+ - cache is written when retrieving data.
35
+ - if cache is older than 1 hour, it is refreshed; otherwise, data is pulled from cache by default
36
+ - Logs are written to `~/.cabinet/log/LOG_DAILY_YYYY-MM-DD` by default
37
+ - this can be changed as needed (per log or otherwise)
38
+
39
+ ## Installation and Setup
40
+
41
+ ```bash
42
+ python3 -m pip install cabinet
43
+ python3 -m pip install pymongo
44
+ cabinet --config
45
+ ```
46
+
47
+ ## CLI usage
48
+ ```
49
+ Usage: cabinet [OPTIONS]
50
+
51
+ Options:
52
+ -h, --help Show this help message and exit
53
+ --configure, -config Configure
54
+ --export Export the data in MongoDB to a JSON file
55
+ --edit, -e Edit MongoDB in the default editor as a JSON file
56
+ --edit-file, -ef Edit a specific file
57
+ --no-create (for -ef) Do not create file if it does not exist
58
+ --get, -g Get a property from MongoDB (nesting supported)
59
+ --put, -p Put a property into MongoDB (nesting supported)
60
+ --remove, -rm Removes a property from MongoDB
61
+ --get-file Returns the file specified
62
+ --strip (for --get-file) Whether to strip file content whitespace
63
+ --log, -l Log a message to the default location
64
+ --level (for -l) Log level [debug, info, warn, error, critical]
65
+ -v, --version show version number and exit
66
+
67
+ Mail:
68
+ --mail Sends an email
69
+ --subject SUBJECT, -s SUBJECT
70
+ Email subject
71
+ --body BODY, -b BODY Email body
72
+ --to TO_ADDR, -t TO_ADDR
73
+ ```
74
+
75
+ ## Configuration
76
+
77
+ - Upon first launch, the tool will prompt you to enter your MongoDB credentials, as well as
78
+ the cluster name and Database name. These are stored in `~/.config/cabinet/config.json`.
79
+
80
+ - You will be asked to configure your default editor from the list of available editors on
81
+ your system. If this step is skipped, or an error occurs, `nano` will be used.
82
+
83
+ You can change this with `cabinet --config` and modifying the `editor` attribute.
84
+
85
+ ### edit_file() shortcuts
86
+ - see example below to enable something like
87
+ - `cabinet -ef shopping` from the terminal
88
+ - rather than `cabinet -ef "/home/{username}/path/to/shopping_list.md"`
89
+ - or `cabinet.Cabinet().edit("shopping")`
90
+ - rather than `cabinet.Cabinet().edit("/home/{username}/path/to/whatever.md")`
91
+
92
+ file:
93
+ ```
94
+ # example only; these commands will be unique to your setup
95
+
96
+ {
97
+ "path": {
98
+ "edit": {
99
+ "shopping": {
100
+ "value": "/home/{username}/path/to/whatever.md",
101
+ },
102
+ "todo": {
103
+ "value": "/home/{username}/path/to/whatever.md",
104
+ }
105
+ }
106
+ }
107
+ }
108
+ ```
109
+
110
+ set from terminal:
111
+ ```
112
+ cabinet -p edit shopping value "/home/{username}/path/to/whatever.md"
113
+ cabinet -p edit todo value "/home/{username}/path/to/whatever.md"
114
+ ```
115
+
116
+ ### mail
117
+
118
+ - It is NEVER a good idea to store your password in plaintext; for this reason, I strongly recommend a "throwaway" account that is only used for sending emails
119
+ - Gmail (as of May 2022) and most other mainstream email providers won't work with this; for support, search for sending mail from your email provider with `smtplib`.
120
+ - In MongoDB, add the `email` object to make your settings file look like this example:
121
+
122
+ file:
123
+ ```
124
+ {
125
+ "email": {
126
+ "from": "throwaway@example.com",
127
+ "from_pw": "example",
128
+ "from_name": "Cabinet (or other name of your choice)",
129
+ "to": "destination@protonmail.com",
130
+ "smtp_server": "example.com",
131
+ "imap_server": "example.com",
132
+ "port": 123
133
+ }
134
+ }
135
+ ```
136
+
137
+ set from terminal:
138
+ ```
139
+ cabinet -p email from throwaway@example.com
140
+ cabinet -p email from_pw example
141
+ ...
142
+ ```
143
+
144
+ ## Examples
145
+
146
+ ### `put`
147
+
148
+ python:
149
+ ```
150
+ from cabinet import Cabinet
151
+
152
+ cab = Cabinet()
153
+
154
+ cab.put("employee", "Tyler", "salary", 7.25)
155
+ ```
156
+
157
+ or terminal:
158
+ ```
159
+ cabinet -p employee Tyler salary 7.25
160
+ ```
161
+
162
+ results in this structure in MongoDB:
163
+ ```
164
+ {
165
+ "employee": {
166
+ "Tyler": {
167
+ "salary": 7.25 # or "7.25" if done from terminal
168
+ }
169
+ }
170
+ }
171
+ ```
172
+
173
+ ### `get`
174
+
175
+ python:
176
+ ```
177
+ from cabinet import Cabinet
178
+
179
+ cab = Cabinet()
180
+
181
+ print(cab.get("employee", "Tyler", "salary"))
182
+
183
+ # or cab.get("employee", "Tyler", "salary", is_print = True)
184
+ ```
185
+
186
+ or terminal:
187
+ ```
188
+ cabinet -g employee Tyler salary
189
+ ```
190
+ - optional: `--no-cache` to force cache refresh
191
+
192
+ results in:
193
+ ```
194
+ 7.25
195
+ ```
196
+
197
+ ### `remove`
198
+
199
+ python:
200
+ ```
201
+ from cabinet import Cabinet
202
+
203
+ cab = Cabinet()
204
+
205
+ cab.remove("employee", "Tyler", "salary")
206
+ ```
207
+
208
+ or terminal:
209
+ ```
210
+ cabinet -rm employee Tyler salary
211
+ ```
212
+
213
+ results in this structure in MongoDB:
214
+ ```
215
+ {
216
+ "employee": {
217
+ "tyler": {}
218
+ }
219
+ }
220
+ ```
221
+
222
+ ### `edit_file`
223
+
224
+ python:
225
+ ```
226
+ from cabinet import Cabinet
227
+
228
+ cab = Cabinet()
229
+
230
+ # if put("path", "edit", "shopping", "/path/to/shopping.md") has been called, this will edit the file assigned to that shortcut.
231
+
232
+ # opens file in the default editor (`cabinet --config` -> 'editor'), saves upon exit
233
+ cab.edit("shopping")
234
+
235
+ # or you can edit a file directly...
236
+ cab.edit("/path/to/shopping.md")
237
+ ```
238
+
239
+ terminal:
240
+ ```
241
+ # assumes path -> edit -> shopping -> path/to/shopping.md has been set
242
+ cabinet -ef shoppping
243
+
244
+ or
245
+
246
+ cabinet -ef "/path/to/shopping.md"
247
+ ```
248
+
249
+ ### `mail`
250
+
251
+ python:
252
+ ```
253
+
254
+ from cabinet import Mail
255
+
256
+ mail = Mail()
257
+
258
+ mail.send('Test Subject', 'Test Body')
259
+
260
+ ```
261
+
262
+ terminal:
263
+ ```
264
+ cabinet --mail --subject "Test Subject" --body "Test Body"
265
+
266
+ # or
267
+
268
+ cabinet --mail -s "Test Subject" -b "Test Body"
269
+ ```
270
+
271
+ ### `log`
272
+
273
+ python:
274
+ ```
275
+ from cabinet import Cabinet
276
+
277
+ cab = Cabinet()
278
+
279
+ # writes to a file named LOG_DAILY_YYYY-MM-DD in the default log folder (or cab.get('path', 'log')) inside a YYYY-MM-DD folder
280
+ cab.log("Connection timed out") # defaults to 'info' if no level is set
281
+ cab.log("This function hit a breakpoint", level="debug")
282
+ cab.log("Looks like the server is on fire", level="critical")
283
+ cab.log("This is fine", level="info")
284
+
285
+ # writes to a file named LOG_TEMPERATURE
286
+ cab.log("30", log_name="LOG_TEMPERATURE")
287
+
288
+ # writes to a file named LOG_TEMPERATURE in /home/{username}/weather
289
+ cab.log("30", log_name="LOG_TEMPERATURE", log_folder_path="/home/{username}/weather")
290
+
291
+ # format
292
+ # 2021-12-29 19:29:27,896 — INFO — 30
293
+
294
+ ```
295
+
296
+ terminal:
297
+ ```
298
+ # defaults to 'info' if no level is set
299
+ cabinet -l "Connection timed out"
300
+
301
+ # -l and --log are interchangeable
302
+ cabinet --log "Connection timed out"
303
+
304
+ # change levels with --level
305
+ cabinet --log "Server is on fire" --level "critical"
306
+ ```
307
+
308
+ ## Disclaimers
309
+
310
+ - Although I've done quite a bit of testing, I can't guarantee everything that works on my machine will work on yours. Always back up your data to multiple places to avoid data loss.
311
+ - If you find any issues, please contact me... or get your hands dirty and raise a PR!
312
+
313
+ ## Unit Tests
314
+ - Unit tests are available in `test/`; use `pytest test/` to run them.
315
+
316
+ ## Author
317
+
318
+ - Tyler Woodfin
319
+ - [GitHub](https://www.github.com/tylerjwoodfin)
320
+ - [Website](http://tyler.cloud)
@@ -0,0 +1,308 @@
1
+ # cabinet
2
+ A Python library to easily manage data with MongoDB and across other files.
3
+ Supports a cli, email, and event logging.
4
+
5
+ ## Features
6
+
7
+ - Read and write data in MongoDB and/or the JSON files of your choice
8
+ - Provides easy shortcuts to MongoDB actions
9
+ - Log to a file/directory of your choice without having to configure `logger` each time
10
+ - Send/receive mail using `cabinet.Cabinet().mail()`
11
+
12
+ ## Dependencies
13
+
14
+ - Python >= 3.6
15
+ - MongoDB
16
+ - Pymongo (`pip install pymongo`)
17
+ - smtplib
18
+
19
+ ## Structure
20
+
21
+ - Data is stored in MongoDB; simply plug in your credentials.
22
+ - cache is written when retrieving data.
23
+ - if cache is older than 1 hour, it is refreshed; otherwise, data is pulled from cache by default
24
+ - Logs are written to `~/.cabinet/log/LOG_DAILY_YYYY-MM-DD` by default
25
+ - this can be changed as needed (per log or otherwise)
26
+
27
+ ## Installation and Setup
28
+
29
+ ```bash
30
+ python3 -m pip install cabinet
31
+ python3 -m pip install pymongo
32
+ cabinet --config
33
+ ```
34
+
35
+ ## CLI usage
36
+ ```
37
+ Usage: cabinet [OPTIONS]
38
+
39
+ Options:
40
+ -h, --help Show this help message and exit
41
+ --configure, -config Configure
42
+ --export Export the data in MongoDB to a JSON file
43
+ --edit, -e Edit MongoDB in the default editor as a JSON file
44
+ --edit-file, -ef Edit a specific file
45
+ --no-create (for -ef) Do not create file if it does not exist
46
+ --get, -g Get a property from MongoDB (nesting supported)
47
+ --put, -p Put a property into MongoDB (nesting supported)
48
+ --remove, -rm Removes a property from MongoDB
49
+ --get-file Returns the file specified
50
+ --strip (for --get-file) Whether to strip file content whitespace
51
+ --log, -l Log a message to the default location
52
+ --level (for -l) Log level [debug, info, warn, error, critical]
53
+ -v, --version show version number and exit
54
+
55
+ Mail:
56
+ --mail Sends an email
57
+ --subject SUBJECT, -s SUBJECT
58
+ Email subject
59
+ --body BODY, -b BODY Email body
60
+ --to TO_ADDR, -t TO_ADDR
61
+ ```
62
+
63
+ ## Configuration
64
+
65
+ - Upon first launch, the tool will prompt you to enter your MongoDB credentials, as well as
66
+ the cluster name and Database name. These are stored in `~/.config/cabinet/config.json`.
67
+
68
+ - You will be asked to configure your default editor from the list of available editors on
69
+ your system. If this step is skipped, or an error occurs, `nano` will be used.
70
+
71
+ You can change this with `cabinet --config` and modifying the `editor` attribute.
72
+
73
+ ### edit_file() shortcuts
74
+ - see example below to enable something like
75
+ - `cabinet -ef shopping` from the terminal
76
+ - rather than `cabinet -ef "/home/{username}/path/to/shopping_list.md"`
77
+ - or `cabinet.Cabinet().edit("shopping")`
78
+ - rather than `cabinet.Cabinet().edit("/home/{username}/path/to/whatever.md")`
79
+
80
+ file:
81
+ ```
82
+ # example only; these commands will be unique to your setup
83
+
84
+ {
85
+ "path": {
86
+ "edit": {
87
+ "shopping": {
88
+ "value": "/home/{username}/path/to/whatever.md",
89
+ },
90
+ "todo": {
91
+ "value": "/home/{username}/path/to/whatever.md",
92
+ }
93
+ }
94
+ }
95
+ }
96
+ ```
97
+
98
+ set from terminal:
99
+ ```
100
+ cabinet -p edit shopping value "/home/{username}/path/to/whatever.md"
101
+ cabinet -p edit todo value "/home/{username}/path/to/whatever.md"
102
+ ```
103
+
104
+ ### mail
105
+
106
+ - It is NEVER a good idea to store your password in plaintext; for this reason, I strongly recommend a "throwaway" account that is only used for sending emails
107
+ - Gmail (as of May 2022) and most other mainstream email providers won't work with this; for support, search for sending mail from your email provider with `smtplib`.
108
+ - In MongoDB, add the `email` object to make your settings file look like this example:
109
+
110
+ file:
111
+ ```
112
+ {
113
+ "email": {
114
+ "from": "throwaway@example.com",
115
+ "from_pw": "example",
116
+ "from_name": "Cabinet (or other name of your choice)",
117
+ "to": "destination@protonmail.com",
118
+ "smtp_server": "example.com",
119
+ "imap_server": "example.com",
120
+ "port": 123
121
+ }
122
+ }
123
+ ```
124
+
125
+ set from terminal:
126
+ ```
127
+ cabinet -p email from throwaway@example.com
128
+ cabinet -p email from_pw example
129
+ ...
130
+ ```
131
+
132
+ ## Examples
133
+
134
+ ### `put`
135
+
136
+ python:
137
+ ```
138
+ from cabinet import Cabinet
139
+
140
+ cab = Cabinet()
141
+
142
+ cab.put("employee", "Tyler", "salary", 7.25)
143
+ ```
144
+
145
+ or terminal:
146
+ ```
147
+ cabinet -p employee Tyler salary 7.25
148
+ ```
149
+
150
+ results in this structure in MongoDB:
151
+ ```
152
+ {
153
+ "employee": {
154
+ "Tyler": {
155
+ "salary": 7.25 # or "7.25" if done from terminal
156
+ }
157
+ }
158
+ }
159
+ ```
160
+
161
+ ### `get`
162
+
163
+ python:
164
+ ```
165
+ from cabinet import Cabinet
166
+
167
+ cab = Cabinet()
168
+
169
+ print(cab.get("employee", "Tyler", "salary"))
170
+
171
+ # or cab.get("employee", "Tyler", "salary", is_print = True)
172
+ ```
173
+
174
+ or terminal:
175
+ ```
176
+ cabinet -g employee Tyler salary
177
+ ```
178
+ - optional: `--no-cache` to force cache refresh
179
+
180
+ results in:
181
+ ```
182
+ 7.25
183
+ ```
184
+
185
+ ### `remove`
186
+
187
+ python:
188
+ ```
189
+ from cabinet import Cabinet
190
+
191
+ cab = Cabinet()
192
+
193
+ cab.remove("employee", "Tyler", "salary")
194
+ ```
195
+
196
+ or terminal:
197
+ ```
198
+ cabinet -rm employee Tyler salary
199
+ ```
200
+
201
+ results in this structure in MongoDB:
202
+ ```
203
+ {
204
+ "employee": {
205
+ "tyler": {}
206
+ }
207
+ }
208
+ ```
209
+
210
+ ### `edit_file`
211
+
212
+ python:
213
+ ```
214
+ from cabinet import Cabinet
215
+
216
+ cab = Cabinet()
217
+
218
+ # if put("path", "edit", "shopping", "/path/to/shopping.md") has been called, this will edit the file assigned to that shortcut.
219
+
220
+ # opens file in the default editor (`cabinet --config` -> 'editor'), saves upon exit
221
+ cab.edit("shopping")
222
+
223
+ # or you can edit a file directly...
224
+ cab.edit("/path/to/shopping.md")
225
+ ```
226
+
227
+ terminal:
228
+ ```
229
+ # assumes path -> edit -> shopping -> path/to/shopping.md has been set
230
+ cabinet -ef shoppping
231
+
232
+ or
233
+
234
+ cabinet -ef "/path/to/shopping.md"
235
+ ```
236
+
237
+ ### `mail`
238
+
239
+ python:
240
+ ```
241
+
242
+ from cabinet import Mail
243
+
244
+ mail = Mail()
245
+
246
+ mail.send('Test Subject', 'Test Body')
247
+
248
+ ```
249
+
250
+ terminal:
251
+ ```
252
+ cabinet --mail --subject "Test Subject" --body "Test Body"
253
+
254
+ # or
255
+
256
+ cabinet --mail -s "Test Subject" -b "Test Body"
257
+ ```
258
+
259
+ ### `log`
260
+
261
+ python:
262
+ ```
263
+ from cabinet import Cabinet
264
+
265
+ cab = Cabinet()
266
+
267
+ # writes to a file named LOG_DAILY_YYYY-MM-DD in the default log folder (or cab.get('path', 'log')) inside a YYYY-MM-DD folder
268
+ cab.log("Connection timed out") # defaults to 'info' if no level is set
269
+ cab.log("This function hit a breakpoint", level="debug")
270
+ cab.log("Looks like the server is on fire", level="critical")
271
+ cab.log("This is fine", level="info")
272
+
273
+ # writes to a file named LOG_TEMPERATURE
274
+ cab.log("30", log_name="LOG_TEMPERATURE")
275
+
276
+ # writes to a file named LOG_TEMPERATURE in /home/{username}/weather
277
+ cab.log("30", log_name="LOG_TEMPERATURE", log_folder_path="/home/{username}/weather")
278
+
279
+ # format
280
+ # 2021-12-29 19:29:27,896 — INFO — 30
281
+
282
+ ```
283
+
284
+ terminal:
285
+ ```
286
+ # defaults to 'info' if no level is set
287
+ cabinet -l "Connection timed out"
288
+
289
+ # -l and --log are interchangeable
290
+ cabinet --log "Connection timed out"
291
+
292
+ # change levels with --level
293
+ cabinet --log "Server is on fire" --level "critical"
294
+ ```
295
+
296
+ ## Disclaimers
297
+
298
+ - Although I've done quite a bit of testing, I can't guarantee everything that works on my machine will work on yours. Always back up your data to multiple places to avoid data loss.
299
+ - If you find any issues, please contact me... or get your hands dirty and raise a PR!
300
+
301
+ ## Unit Tests
302
+ - Unit tests are available in `test/`; use `pytest test/` to run them.
303
+
304
+ ## Author
305
+
306
+ - Tyler Woodfin
307
+ - [GitHub](https://www.github.com/tylerjwoodfin)
308
+ - [Website](http://tyler.cloud)
@@ -0,0 +1,6 @@
1
+ [build-system]
2
+ requires = [
3
+ "setuptools",
4
+ "wheel"
5
+ ]
6
+ build-backend = "setuptools.build_meta"
@@ -0,0 +1,34 @@
1
+ [metadata]
2
+ name = cabinet
3
+ version = 0.8.1
4
+ author = Tyler Woodfin
5
+ author_email = feedback@tyler.cloud
6
+ description = Easily manage data storage and logging across repos
7
+ long_description = file: README.md
8
+ long_description_content_type = text/markdown
9
+ url = https://github.com/tylerjwoodfin/cabinet
10
+ project_urls =
11
+ bug tracker = https://github.com/tylerjwoodfin/cabinet/issues
12
+ py_modules = ["cabinet"]
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
+ [options.entry_points]
28
+ console_scripts =
29
+ cabinet = cabinet:main
30
+
31
+ [egg_info]
32
+ tag_build =
33
+ tag_date = 0
34
+
@@ -0,0 +1,4 @@
1
+ """
2
+ Allows for easy Cabinet import
3
+ """
4
+ from .cabinet import Cabinet, Mail, main
@@ -0,0 +1,6 @@
1
+ """
2
+ main entrypoint
3
+ """
4
+ from cabinet import Cabinet
5
+
6
+ cab = Cabinet()