douglog 0.2.2__tar.gz → 0.2.3__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.
- {douglog-0.2.2 → douglog-0.2.3}/PKG-INFO +3 -1
- {douglog-0.2.2 → douglog-0.2.3/douglog}/douglog.egg-info/PKG-INFO +3 -1
- douglog-0.2.3/douglog/douglog.egg-info/SOURCES.txt +12 -0
- douglog-0.2.3/douglog/douglog.egg-info/top_level.txt +1 -0
- {douglog-0.2.2 → douglog-0.2.3}/pyproject.toml +17 -3
- douglog-0.2.2/douglog/__init__.py +0 -0
- douglog-0.2.2/douglog/douglog.py +0 -310
- douglog-0.2.2/douglog.egg-info/SOURCES.txt +0 -15
- douglog-0.2.2/douglog.egg-info/top_level.txt +0 -1
- douglog-0.2.2/setup.py +0 -17
- {douglog-0.2.2 → douglog-0.2.3}/LICENSE +0 -0
- {douglog-0.2.2 → douglog-0.2.3}/README.md +0 -0
- {douglog-0.2.2 → douglog-0.2.3/douglog}/douglog.egg-info/dependency_links.txt +0 -0
- {douglog-0.2.2 → douglog-0.2.3/douglog}/douglog.egg-info/entry_points.txt +0 -0
- {douglog-0.2.2 → douglog-0.2.3/douglog}/douglog.egg-info/requires.txt +0 -0
- {douglog-0.2.2 → douglog-0.2.3}/setup.cfg +0 -0
- {douglog-0.2.2 → douglog-0.2.3}/tests/test_delete.py +0 -0
- {douglog-0.2.2 → douglog-0.2.3}/tests/test_git.py +0 -0
- {douglog-0.2.2 → douglog-0.2.3}/tests/test_list.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: douglog
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.3
|
|
4
4
|
Summary: Simple logging CLI tool
|
|
5
5
|
Author-email: Douglas Keller <dg.kllr.jr@gmail.com>
|
|
6
6
|
License: MIT License
|
|
@@ -30,6 +30,8 @@ Project-URL: Repository, https://github.com/dkllrjr/douglog.git
|
|
|
30
30
|
Requires-Python: >=3.12.0
|
|
31
31
|
Description-Content-Type: text/markdown
|
|
32
32
|
License-File: LICENSE
|
|
33
|
+
Requires-Dist: click
|
|
34
|
+
Requires-Dist: numpy
|
|
33
35
|
|
|
34
36
|
# douglog
|
|
35
37
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: douglog
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.3
|
|
4
4
|
Summary: Simple logging CLI tool
|
|
5
5
|
Author-email: Douglas Keller <dg.kllr.jr@gmail.com>
|
|
6
6
|
License: MIT License
|
|
@@ -30,6 +30,8 @@ Project-URL: Repository, https://github.com/dkllrjr/douglog.git
|
|
|
30
30
|
Requires-Python: >=3.12.0
|
|
31
31
|
Description-Content-Type: text/markdown
|
|
32
32
|
License-File: LICENSE
|
|
33
|
+
Requires-Dist: click
|
|
34
|
+
Requires-Dist: numpy
|
|
33
35
|
|
|
34
36
|
# douglog
|
|
35
37
|
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
douglog/douglog.egg-info/PKG-INFO
|
|
5
|
+
douglog/douglog.egg-info/SOURCES.txt
|
|
6
|
+
douglog/douglog.egg-info/dependency_links.txt
|
|
7
|
+
douglog/douglog.egg-info/entry_points.txt
|
|
8
|
+
douglog/douglog.egg-info/requires.txt
|
|
9
|
+
douglog/douglog.egg-info/top_level.txt
|
|
10
|
+
tests/test_delete.py
|
|
11
|
+
tests/test_git.py
|
|
12
|
+
tests/test_list.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -1,17 +1,31 @@
|
|
|
1
1
|
[build-system]
|
|
2
|
-
requires = ["setuptools
|
|
2
|
+
requires = ["setuptools"]
|
|
3
3
|
build-backend = "setuptools.build_meta"
|
|
4
4
|
|
|
5
|
+
|
|
6
|
+
[tool.setuptools.packages.find]
|
|
7
|
+
where = ["douglog"]
|
|
8
|
+
|
|
9
|
+
|
|
5
10
|
[project]
|
|
6
11
|
name = "douglog"
|
|
7
|
-
version = "0.2.
|
|
12
|
+
version = "0.2.3"
|
|
8
13
|
description = "Simple logging CLI tool"
|
|
9
14
|
readme = "README.md"
|
|
10
15
|
authors = [
|
|
11
16
|
{name = "Douglas Keller", email = "dg.kllr.jr@gmail.com"},
|
|
12
17
|
]
|
|
13
18
|
license = {file = "LICENSE"}
|
|
14
|
-
|
|
19
|
+
requires-python = ">=3.12.0"
|
|
20
|
+
dependencies = [
|
|
21
|
+
"click",
|
|
22
|
+
"numpy",
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
[project.scripts]
|
|
27
|
+
dlog = "douglog.douglog:dlog"
|
|
28
|
+
|
|
15
29
|
|
|
16
30
|
[project.urls]
|
|
17
31
|
Homepage = "https://github.com/dkllrjr/douglog"
|
|
File without changes
|
douglog-0.2.2/douglog/douglog.py
DELETED
|
@@ -1,310 +0,0 @@
|
|
|
1
|
-
import click
|
|
2
|
-
from pathlib import Path
|
|
3
|
-
import tomllib
|
|
4
|
-
import os
|
|
5
|
-
import time
|
|
6
|
-
import re
|
|
7
|
-
import numpy as np
|
|
8
|
-
from glob import glob
|
|
9
|
-
import subprocess
|
|
10
|
-
from datetime import datetime
|
|
11
|
-
import importlib.metadata
|
|
12
|
-
|
|
13
|
-
# ──────────────────────────────────────────────────────────────────────────
|
|
14
|
-
# global variables
|
|
15
|
-
|
|
16
|
-
douglog_version = importlib.metadata.version('douglog')
|
|
17
|
-
CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help'])
|
|
18
|
-
|
|
19
|
-
@click.command(context_settings=CONTEXT_SETTINGS)
|
|
20
|
-
|
|
21
|
-
# ──────────────────────────────────────────────────────────────────────────
|
|
22
|
-
# global functions
|
|
23
|
-
|
|
24
|
-
def logbook_not_found(logbook):
|
|
25
|
-
click.echo(logbook + ' logbook not found in config.')
|
|
26
|
-
exit()
|
|
27
|
-
|
|
28
|
-
# ──────────────────────────────────────────────────────────────────────────
|
|
29
|
-
# base command
|
|
30
|
-
|
|
31
|
-
# done for the config
|
|
32
|
-
@click.group(invoke_without_command=True, context_settings=CONTEXT_SETTINGS)
|
|
33
|
-
@click.version_option(douglog_version)
|
|
34
|
-
@click.option('-c', '--config', default='~/.config/dlog.toml', type=str, help="Config file path", show_default=True)
|
|
35
|
-
@click.pass_context
|
|
36
|
-
def dlog(ctx, config):
|
|
37
|
-
"""Simple and quick logging program."""
|
|
38
|
-
|
|
39
|
-
ctx.ensure_object(dict)
|
|
40
|
-
|
|
41
|
-
config = Path(config).expanduser()
|
|
42
|
-
if config.exists():
|
|
43
|
-
|
|
44
|
-
with open(config, 'rb') as file:
|
|
45
|
-
toml = tomllib.load(file)
|
|
46
|
-
|
|
47
|
-
# required config options
|
|
48
|
-
required = ['logbooks']
|
|
49
|
-
for option in required:
|
|
50
|
-
if option not in toml:
|
|
51
|
-
click.echo('Config requires "' + key + '" to be set.')
|
|
52
|
-
exit()
|
|
53
|
-
|
|
54
|
-
# home log directory
|
|
55
|
-
if 'home' in toml:
|
|
56
|
-
ctx.obj['home'] = Path(toml['home']).expanduser()
|
|
57
|
-
else:
|
|
58
|
-
ctx.obj['home'] = Path('~/dlogs').expanduser()
|
|
59
|
-
|
|
60
|
-
# individual logs
|
|
61
|
-
ctx.obj['logbooks'] = []
|
|
62
|
-
for logbook in toml['logbooks']:
|
|
63
|
-
ctx.obj['logbooks'].append(logbook)
|
|
64
|
-
|
|
65
|
-
logbook_path = ctx.obj['home'] / Path(logbook)
|
|
66
|
-
|
|
67
|
-
if not logbook_path.exists():
|
|
68
|
-
os.mkdir(logbook_path)
|
|
69
|
-
|
|
70
|
-
# editor
|
|
71
|
-
if 'editor' in toml:
|
|
72
|
-
ctx.obj['editor'] = toml['editor']
|
|
73
|
-
else:
|
|
74
|
-
ctx.obj['editor'] = 'vim'
|
|
75
|
-
|
|
76
|
-
else:
|
|
77
|
-
click.echo('No config file, exiting.')
|
|
78
|
-
exit()
|
|
79
|
-
|
|
80
|
-
# ──────────────────────────────────────────────────────────────────────────
|
|
81
|
-
# log command to generate single logs
|
|
82
|
-
|
|
83
|
-
@dlog.command('log', short_help='Open a new log in your editor.',context_settings=CONTEXT_SETTINGS)
|
|
84
|
-
@click.argument('logbook', type=str)
|
|
85
|
-
@click.pass_context
|
|
86
|
-
def log(ctx, logbook):
|
|
87
|
-
"""Open a new log in LOGBOOK in your editor."""
|
|
88
|
-
|
|
89
|
-
if logbook in ctx.obj['logbooks']:
|
|
90
|
-
logbook_path = ctx.obj['home'] / Path(logbook)
|
|
91
|
-
|
|
92
|
-
epoch = str(np.floor(time.time()).astype(np.int64))
|
|
93
|
-
date = time.strftime("%a, %d %b %Y %H:%M:%S UTC", time.gmtime())
|
|
94
|
-
|
|
95
|
-
file_path = logbook_path / Path(epoch + '.md')
|
|
96
|
-
with open(file_path, 'a') as file:
|
|
97
|
-
file.write('# ' + date + '\n')
|
|
98
|
-
|
|
99
|
-
# editting
|
|
100
|
-
click.edit(filename=file_path, editor=ctx.obj['editor'])
|
|
101
|
-
|
|
102
|
-
# committing
|
|
103
|
-
git_path = logbook + '/' + file_path.name
|
|
104
|
-
ctx.invoke(git, git_commands=['add', git_path])
|
|
105
|
-
ctx.invoke(git, git_commands=['commit', '-m', '"Added ' + git_path + '"'])
|
|
106
|
-
|
|
107
|
-
else:
|
|
108
|
-
logbook_not_found(logbook)
|
|
109
|
-
|
|
110
|
-
# ──────────────────────────────────────────────────────────────────────────
|
|
111
|
-
# list command to list logs
|
|
112
|
-
|
|
113
|
-
@dlog.command(context_settings=CONTEXT_SETTINGS)
|
|
114
|
-
@click.option('-l', '--logs', default=False, help='List logs as well.', is_flag=True)
|
|
115
|
-
@click.pass_context
|
|
116
|
-
def list(ctx, logs):
|
|
117
|
-
"""Lists all logbooks."""
|
|
118
|
-
|
|
119
|
-
for logbook in ctx.obj['logbooks']:
|
|
120
|
-
click.echo(logbook)
|
|
121
|
-
|
|
122
|
-
if logs:
|
|
123
|
-
logbook_path = ctx.obj['home'] / Path(logbook)
|
|
124
|
-
file_paths = sorted(logbook_path.glob('*.md'))
|
|
125
|
-
|
|
126
|
-
for file_path in file_paths:
|
|
127
|
-
|
|
128
|
-
date = datetime.utcfromtimestamp(int(file_path.stem)).isoformat()
|
|
129
|
-
click.echo(file_path.name + ' : ' + date)
|
|
130
|
-
|
|
131
|
-
click.echo()
|
|
132
|
-
|
|
133
|
-
exit()
|
|
134
|
-
|
|
135
|
-
# ──────────────────────────────────────────────────────────────────────────
|
|
136
|
-
# search command
|
|
137
|
-
|
|
138
|
-
@dlog.command('search', short_help='Searches through your logs.', context_settings=CONTEXT_SETTINGS)
|
|
139
|
-
@click.option('-l', '--logbook', type=str, help="Specified logbook to search.", default=None)
|
|
140
|
-
@click.option('-pm', '--plus-minus', 'plusminus', type=str, help="Lines above (minus) and below (plus) to show: e.g. +plus-minus or -minus+plus.", default=None)
|
|
141
|
-
@click.option('-e', '--edit', type=int, help="Opens the specified file from the result list in the editor: e.g. -e 1", default=0)
|
|
142
|
-
@click.argument('regex', type=str)
|
|
143
|
-
@click.pass_context
|
|
144
|
-
def search(ctx, logbook, plusminus, edit, regex):
|
|
145
|
-
"""
|
|
146
|
-
Searches through your logs for the given REGEX. Searches through all logs unless one is specified. Results are printed as:
|
|
147
|
-
|
|
148
|
-
[result #] logbook: filename: date: line number +plus -minus:
|
|
149
|
-
line(s)
|
|
150
|
-
"""
|
|
151
|
-
|
|
152
|
-
def inbook(ctx, logbook, plusminus, edit, regex, result):
|
|
153
|
-
|
|
154
|
-
logbook_path = ctx.obj['home'] / Path(logbook)
|
|
155
|
-
file_paths = sorted(logbook_path.glob('*.md'))
|
|
156
|
-
|
|
157
|
-
for j, file_path in enumerate(file_paths):
|
|
158
|
-
|
|
159
|
-
date = datetime.utcfromtimestamp(int(file_path.stem)).isoformat()
|
|
160
|
-
|
|
161
|
-
with open(file_path, 'r') as file:
|
|
162
|
-
|
|
163
|
-
lines = file.readlines()
|
|
164
|
-
for i, line in enumerate(lines):
|
|
165
|
-
|
|
166
|
-
if re.search(regex, line):
|
|
167
|
-
|
|
168
|
-
found_line = '[' + str(result) + '] ' + logbook + ': ' + file_path.stem + ': ' + date + ': ' + str(i + 1)
|
|
169
|
-
|
|
170
|
-
if plusminus is not None: # getting lines above and below hit
|
|
171
|
-
|
|
172
|
-
plus, minus = interpret_plusminus(plusminus)
|
|
173
|
-
if plus > 0:
|
|
174
|
-
found_line += '+' + str(plus)
|
|
175
|
-
if minus > 0:
|
|
176
|
-
found_line += '-' + str(minus)
|
|
177
|
-
|
|
178
|
-
found_line += ':'
|
|
179
|
-
click.echo(click.style(found_line, bold=True))
|
|
180
|
-
|
|
181
|
-
for l in lines[i-minus:i+plus+1]:
|
|
182
|
-
|
|
183
|
-
if l is line:
|
|
184
|
-
click.echo(click.style(l.strip('\n'), italic=True))
|
|
185
|
-
else:
|
|
186
|
-
click.echo(l.strip('\n'))
|
|
187
|
-
|
|
188
|
-
else:
|
|
189
|
-
|
|
190
|
-
click.echo(click.style(found_line, bold=True))
|
|
191
|
-
click.echo(line.strip('\n'))
|
|
192
|
-
|
|
193
|
-
if edit == result: # opening specified result in editor
|
|
194
|
-
click.edit(filename=file_path, editor=ctx.obj['editor'])
|
|
195
|
-
|
|
196
|
-
result += 1
|
|
197
|
-
|
|
198
|
-
return result
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
def interpret_plusminus(plusminus):
|
|
202
|
-
|
|
203
|
-
def _get_indices(plusminus, plus=True):
|
|
204
|
-
|
|
205
|
-
symbols = ['+', '-']
|
|
206
|
-
|
|
207
|
-
if not plus:
|
|
208
|
-
symbols = symbols[::-1]
|
|
209
|
-
|
|
210
|
-
if symbols[0] in plusminus:
|
|
211
|
-
|
|
212
|
-
if symbols[1] in plusminus:
|
|
213
|
-
|
|
214
|
-
if plusminus.find(symbols[0]) < plusminus.find(symbols[1]):
|
|
215
|
-
return slice(plusminus.find(symbols[0]), plusminus.find(symbols[1]))
|
|
216
|
-
else:
|
|
217
|
-
return slice(plusminus.find(symbols[0]), None)
|
|
218
|
-
|
|
219
|
-
else:
|
|
220
|
-
return slice(plusminus.find(symbols[0]), None)
|
|
221
|
-
|
|
222
|
-
elif symbols[1] not in plusminus and plus: # assuming plus if no symbols are given
|
|
223
|
-
return slice(None, None)
|
|
224
|
-
|
|
225
|
-
else:
|
|
226
|
-
return None
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
plus_slice = _get_indices(plusminus)
|
|
230
|
-
minus_slice = _get_indices(plusminus, plus=False)
|
|
231
|
-
|
|
232
|
-
if plus_slice is not None:
|
|
233
|
-
plus = abs(int(plusminus[plus_slice]))
|
|
234
|
-
else:
|
|
235
|
-
plus = 0
|
|
236
|
-
|
|
237
|
-
if minus_slice is not None:
|
|
238
|
-
minus = abs(int(plusminus[minus_slice]))
|
|
239
|
-
else:
|
|
240
|
-
minus = 0
|
|
241
|
-
|
|
242
|
-
return plus, minus
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
result = 1 # result hit counter
|
|
246
|
-
|
|
247
|
-
if logbook:
|
|
248
|
-
if logbook in ctx.obj['logbooks']:
|
|
249
|
-
inbook(ctx, logbook, plusminus, edit, regex, result)
|
|
250
|
-
else:
|
|
251
|
-
logbook_not_found(logbook)
|
|
252
|
-
|
|
253
|
-
else:
|
|
254
|
-
for logbook in ctx.obj['logbooks']:
|
|
255
|
-
result = inbook(ctx, logbook, plusminus, edit, regex, result)
|
|
256
|
-
|
|
257
|
-
# ──────────────────────────────────────────────────────────────────────────
|
|
258
|
-
# git command
|
|
259
|
-
|
|
260
|
-
CONTEXT_SETTINGS_git = CONTEXT_SETTINGS.copy()
|
|
261
|
-
CONTEXT_SETTINGS_git['ignore_unknown_options'] = True
|
|
262
|
-
|
|
263
|
-
@dlog.command('git', short_help='Git manage the logbooks.', context_settings=CONTEXT_SETTINGS_git)
|
|
264
|
-
@click.argument('git_commands', type=click.UNPROCESSED, nargs=-1)
|
|
265
|
-
@click.pass_context
|
|
266
|
-
def git(ctx, git_commands):
|
|
267
|
-
"""Git command to manage the douglog git repository."""
|
|
268
|
-
|
|
269
|
-
command = ['git', '-C', ctx.obj['home']]
|
|
270
|
-
|
|
271
|
-
for arg in git_commands:
|
|
272
|
-
command.append(arg)
|
|
273
|
-
|
|
274
|
-
subprocess.run(command)
|
|
275
|
-
|
|
276
|
-
# ──────────────────────────────────────────────────────────────────────────
|
|
277
|
-
# delete command
|
|
278
|
-
|
|
279
|
-
@dlog.command('delete', short_help='Delete a log.', context_settings=CONTEXT_SETTINGS)
|
|
280
|
-
@click.argument('logbook', type=str)
|
|
281
|
-
@click.option('-l', '--log', type=str, default=None, help='Delete specified log.')
|
|
282
|
-
@click.pass_context
|
|
283
|
-
def delete(ctx, logbook, log):
|
|
284
|
-
"""Delete a log from the LOGBOOK. Deletes the most recent log if none is specified."""
|
|
285
|
-
|
|
286
|
-
if logbook in ctx.obj['logbooks']:
|
|
287
|
-
logbook_path = ctx.obj['home'] / Path(logbook)
|
|
288
|
-
file_paths = sorted(logbook_path.glob('*.md'))
|
|
289
|
-
|
|
290
|
-
if log:
|
|
291
|
-
log_path = logbook_path / Path(log)
|
|
292
|
-
if log_path in file_paths:
|
|
293
|
-
delete_log = log_path
|
|
294
|
-
else:
|
|
295
|
-
click.echo('Log specified but not found.')
|
|
296
|
-
exit()
|
|
297
|
-
else:
|
|
298
|
-
delete_log = file_paths[-1]
|
|
299
|
-
|
|
300
|
-
if click.confirm('Do you want to delete: ' + logbook + '/' + delete_log.name + '?'):
|
|
301
|
-
click.echo('Deleting ' + delete_log.name + ' in ' + logbook)
|
|
302
|
-
subprocess.run(['rm', delete_log])
|
|
303
|
-
|
|
304
|
-
# committing
|
|
305
|
-
git_path = logbook + '/' + delete_log.name
|
|
306
|
-
ctx.invoke(git, git_commands=['add', git_path])
|
|
307
|
-
ctx.invoke(git, git_commands=['commit', '-m', '"Deleted ' + git_path + '"'])
|
|
308
|
-
|
|
309
|
-
else:
|
|
310
|
-
logbook_not_found(logbook)
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
LICENSE
|
|
2
|
-
README.md
|
|
3
|
-
pyproject.toml
|
|
4
|
-
setup.py
|
|
5
|
-
douglog/__init__.py
|
|
6
|
-
douglog/douglog.py
|
|
7
|
-
douglog.egg-info/PKG-INFO
|
|
8
|
-
douglog.egg-info/SOURCES.txt
|
|
9
|
-
douglog.egg-info/dependency_links.txt
|
|
10
|
-
douglog.egg-info/entry_points.txt
|
|
11
|
-
douglog.egg-info/requires.txt
|
|
12
|
-
douglog.egg-info/top_level.txt
|
|
13
|
-
tests/test_delete.py
|
|
14
|
-
tests/test_git.py
|
|
15
|
-
tests/test_list.py
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
douglog
|
douglog-0.2.2/setup.py
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
from setuptools import setup, find_packages
|
|
2
|
-
|
|
3
|
-
setup(
|
|
4
|
-
packages=find_packages(),
|
|
5
|
-
python_requires='>=3.12.0',
|
|
6
|
-
install_requires=[
|
|
7
|
-
'click',
|
|
8
|
-
'numpy',
|
|
9
|
-
],
|
|
10
|
-
entry_points={
|
|
11
|
-
'console_scripts': [
|
|
12
|
-
'dlog = douglog.douglog:dlog',
|
|
13
|
-
]
|
|
14
|
-
}
|
|
15
|
-
)
|
|
16
|
-
|
|
17
|
-
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|