skilleter-modules 0.0.1__py3-none-any.whl
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.
- skilleter_modules/__init__.py +0 -0
- skilleter_modules/colour.py +328 -0
- skilleter_modules/dc_curses.py +278 -0
- skilleter_modules/dc_defaults.py +221 -0
- skilleter_modules/dc_util.py +50 -0
- skilleter_modules/dircolors.py +310 -0
- skilleter_modules/files.py +154 -0
- skilleter_modules/git.py +1502 -0
- skilleter_modules/gitlab.py +193 -0
- skilleter_modules/path.py +153 -0
- skilleter_modules/popup.py +88 -0
- skilleter_modules/run.py +306 -0
- skilleter_modules/tfm_pane.py +593 -0
- skilleter_modules/tidy.py +177 -0
- skilleter_modules/venv_template.py +47 -0
- skilleter_modules-0.0.1.dist-info/METADATA +61 -0
- skilleter_modules-0.0.1.dist-info/RECORD +20 -0
- skilleter_modules-0.0.1.dist-info/WHEEL +5 -0
- skilleter_modules-0.0.1.dist-info/licenses/LICENSE +619 -0
- skilleter_modules-0.0.1.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
#! /usr/bin/env python3
|
|
2
|
+
|
|
3
|
+
################################################################################
|
|
4
|
+
""" Functions for making log files and similar more easily viewed and/or compared
|
|
5
|
+
|
|
6
|
+
Defaults to making things readable on a light background but has the
|
|
7
|
+
option to make things readable on a dark background or for removing
|
|
8
|
+
colours altogether.
|
|
9
|
+
|
|
10
|
+
Has functions for removing times, AWS ID values, colours, SHA1 values,
|
|
11
|
+
Also function for making ANSI codes more readable on light or dark backgrounds
|
|
12
|
+
|
|
13
|
+
Currently this is very cude and needs to be a lot more cleverer.
|
|
14
|
+
|
|
15
|
+
TODO: Handle multiple colour changes in a single ANSI sequence
|
|
16
|
+
TODO: Take account of the background colour when determining how to change the foreground colour
|
|
17
|
+
TODO: More colour conversions (currently only converts bright yellow on white to dark yellow)
|
|
18
|
+
TODO: Handle 256 colour codes
|
|
19
|
+
TODO: More time formats
|
|
20
|
+
"""
|
|
21
|
+
################################################################################
|
|
22
|
+
|
|
23
|
+
import re
|
|
24
|
+
|
|
25
|
+
################################################################################
|
|
26
|
+
# Regular expressions
|
|
27
|
+
|
|
28
|
+
# Match an ANSI colour control sequence
|
|
29
|
+
|
|
30
|
+
ANSI_REGEXES = [
|
|
31
|
+
re.compile(r'\x1b\[([0-9][0-9;]*)*m'),
|
|
32
|
+
re.compile(r'\x1b\[m'),
|
|
33
|
+
re.compile(r'\x1b\[[0-9][A-Z]'),
|
|
34
|
+
]
|
|
35
|
+
|
|
36
|
+
# Match and ANSI colour control sequence and capture the colour bit
|
|
37
|
+
|
|
38
|
+
RE_DEBUG = re.compile(r'\x1b(\[[0-9][0-9;]*m)')
|
|
39
|
+
|
|
40
|
+
# Colour conversions for light backgrounds
|
|
41
|
+
|
|
42
|
+
LIGHT_TABLE = [['1;33', '0;33']]
|
|
43
|
+
|
|
44
|
+
# Colour conversions for dark backgrounds
|
|
45
|
+
|
|
46
|
+
DARK_TABLE = []
|
|
47
|
+
|
|
48
|
+
# Common time formats found in log files
|
|
49
|
+
|
|
50
|
+
RE_TIME = [
|
|
51
|
+
{'regex': re.compile(r'[1-9][0-9]{3}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}[.][0-9]+Z?'), 'replace': '{DATE+TIME}'},
|
|
52
|
+
{'regex': re.compile(r'[0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2}(Z|,[0-9]+)'), 'replace': '{TIME}'},
|
|
53
|
+
{'regex': re.compile(r'[0-9]{1,2}:[0-9]{2}:[0-9]{2}(\.[0-9]{1,6})?([+][0-9]{2}:[0-9]{2})?'), 'replace': '{TIME}'},
|
|
54
|
+
|
|
55
|
+
{'regex': re.compile(r'[1-9][0-9]{3}/[0-9][0-9]?/[1-9][0-9]'), 'replace': '{DATE}'},
|
|
56
|
+
{'regex': re.compile(r'[1-9][0-9]/[0-9][0-9]?/[1-9][0-9]{3}'), 'replace': '{DATE}'},
|
|
57
|
+
{'regex': re.compile(r'[0-9]{4}-[0-9]{2}-[0-9]{2}'), 'replace': '{DATE}'},
|
|
58
|
+
{'regex': re.compile(r'[0-9]{2}-[0-9]{2}-[0-9]{4}'), 'replace': '{DATE}'},
|
|
59
|
+
|
|
60
|
+
{'regex': re.compile(r'[0-9]([.][0-9]*)*\s*(second[s]?)'), 'replace': '{ELAPSED}'},
|
|
61
|
+
|
|
62
|
+
{'find': '{DATE} {TIME}', 'replace': '{DATE+TIME}'},
|
|
63
|
+
{'regex': re.compile(r'[0-9]+m *[0-9]+s'), 'replace': '{ELAPSED}'},
|
|
64
|
+
]
|
|
65
|
+
|
|
66
|
+
# SHA values
|
|
67
|
+
|
|
68
|
+
RE_SHA256 = [
|
|
69
|
+
{'regex': re.compile(r'[0-9a-f]{64}'), 'replace': '{SHA256}'},
|
|
70
|
+
]
|
|
71
|
+
|
|
72
|
+
RE_SHA1 = [
|
|
73
|
+
{'regex': re.compile(r'[0-9a-f]{40}'), 'replace': '{SHA1}'},
|
|
74
|
+
]
|
|
75
|
+
|
|
76
|
+
# AWS ids
|
|
77
|
+
|
|
78
|
+
RE_AWS = \
|
|
79
|
+
[
|
|
80
|
+
{'regex': re.compile(r'eni-0[0-9a-f]{16}'), 'replace': '{ENI-ID}'},
|
|
81
|
+
{'regex': re.compile(r'ami-0[0-9a-f]{16}'), 'replace': '{AMI-ID}'},
|
|
82
|
+
{'regex': re.compile(r'snap-0[0-9a-f]{16}'), 'replace': '{AMI-SNAP}'},
|
|
83
|
+
{'regex': re.compile(r'vol-0[0-9a-f]{16}'), 'replace': '{AMI-VOL}'},
|
|
84
|
+
{'regex': re.compile(r'sir-[0-9a-z]{8}'), 'replace': '{SPOT-INSTANCE}'},
|
|
85
|
+
{'regex': re.compile(r'i-0[0-9a-f]{16}'), 'replace': '{EC2-ID}'},
|
|
86
|
+
{'regex': re.compile(r'request id: [0-0a-f]{8}-[0-0a-f]{4}-[0-0a-f]{4}-[0-0a-f]{4}-[0-0a-f]{12}'),
|
|
87
|
+
'replace': 'request id: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'},
|
|
88
|
+
]
|
|
89
|
+
|
|
90
|
+
# Data transfer speeds
|
|
91
|
+
|
|
92
|
+
RE_SPEED = \
|
|
93
|
+
[
|
|
94
|
+
{'regex': re.compile(r'[0-9.]+ *MB/s'), 'replace': '{SPEED}'},
|
|
95
|
+
{'regex': re.compile(r'[0-9.]+ *MiB/s'), 'replace': '{SPEED}'},
|
|
96
|
+
]
|
|
97
|
+
|
|
98
|
+
################################################################################
|
|
99
|
+
|
|
100
|
+
def regex_replace(data, regexes):
|
|
101
|
+
""" Do a set of regex replacements """
|
|
102
|
+
|
|
103
|
+
for regex in regexes:
|
|
104
|
+
if 'find' in regex:
|
|
105
|
+
data = data.replace(regex['find'], regex['replace'])
|
|
106
|
+
elif 'regex' in regex:
|
|
107
|
+
data = regex['regex'].sub(regex['replace'], data)
|
|
108
|
+
else:
|
|
109
|
+
assert False
|
|
110
|
+
|
|
111
|
+
return data
|
|
112
|
+
|
|
113
|
+
################################################################################
|
|
114
|
+
|
|
115
|
+
def debug_format(data):
|
|
116
|
+
""" Make the ANSI colour codes in the specified string human-readable """
|
|
117
|
+
|
|
118
|
+
return RE_DEBUG.sub('{ESC\\1}', data)
|
|
119
|
+
|
|
120
|
+
################################################################################
|
|
121
|
+
|
|
122
|
+
def convert_ansi(data, light=True):
|
|
123
|
+
""" Use the conversion table to convert ANSI codes in the string for display
|
|
124
|
+
on a light or dark background """
|
|
125
|
+
|
|
126
|
+
table = LIGHT_TABLE if light else DARK_TABLE
|
|
127
|
+
|
|
128
|
+
for entry in table:
|
|
129
|
+
data = data.replace('\x1b[%s' % entry[0], '\x1b[%s' % entry[1])
|
|
130
|
+
|
|
131
|
+
return data
|
|
132
|
+
|
|
133
|
+
################################################################################
|
|
134
|
+
|
|
135
|
+
def remove_times(data):
|
|
136
|
+
""" Attempt to remove obvious time and duration references from a string """
|
|
137
|
+
|
|
138
|
+
return regex_replace(data, RE_TIME)
|
|
139
|
+
|
|
140
|
+
################################################################################
|
|
141
|
+
|
|
142
|
+
def remove_sha1(data):
|
|
143
|
+
""" Attempt to remove SHA1 references from a string """
|
|
144
|
+
|
|
145
|
+
return regex_replace(data, RE_SHA1)
|
|
146
|
+
|
|
147
|
+
################################################################################
|
|
148
|
+
|
|
149
|
+
def remove_sha256(data):
|
|
150
|
+
""" Attempt to remove SHA256 references from a string """
|
|
151
|
+
|
|
152
|
+
return regex_replace(data, RE_SHA256)
|
|
153
|
+
|
|
154
|
+
################################################################################
|
|
155
|
+
|
|
156
|
+
def remove_aws_ids(data):
|
|
157
|
+
""" Attempt to remove a variety of AWS ID references from a string """
|
|
158
|
+
|
|
159
|
+
return regex_replace(data, RE_AWS)
|
|
160
|
+
|
|
161
|
+
################################################################################
|
|
162
|
+
|
|
163
|
+
def remove_speeds(data):
|
|
164
|
+
""" Attempt to remove data transfer speed references from a string """
|
|
165
|
+
|
|
166
|
+
return regex_replace(data, RE_SPEED)
|
|
167
|
+
|
|
168
|
+
################################################################################
|
|
169
|
+
|
|
170
|
+
def remove_ansi(text):
|
|
171
|
+
""" Remove ANSI codes from a string """
|
|
172
|
+
|
|
173
|
+
if '\x1b' in text:
|
|
174
|
+
for regex in ANSI_REGEXES:
|
|
175
|
+
text = regex.sub('', text)
|
|
176
|
+
|
|
177
|
+
return text
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
TEMPLATE = \
|
|
2
|
+
r"""#!/usr/bin/env bash
|
|
3
|
+
|
|
4
|
+
set -e
|
|
5
|
+
|
|
6
|
+
################################################################################
|
|
7
|
+
|
|
8
|
+
VENV_NAME=$(basename "$0")
|
|
9
|
+
VENV_DIR=__venv__
|
|
10
|
+
|
|
11
|
+
GREEN="\e[42m"
|
|
12
|
+
NORMAL="\e[0m"
|
|
13
|
+
|
|
14
|
+
################################################################################
|
|
15
|
+
|
|
16
|
+
function box()
|
|
17
|
+
{
|
|
18
|
+
echo -e "${GREEN}################################################################################${NORMAL}"
|
|
19
|
+
echo -e "${GREEN}# $@${NORMAL}"
|
|
20
|
+
echo -e "${GREEN}################################################################################${NORMAL}"
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
################################################################################
|
|
24
|
+
|
|
25
|
+
box "Creating & activating $VENV_NAME virtual environment"
|
|
26
|
+
|
|
27
|
+
python3 -m venv $VENV_DIR
|
|
28
|
+
|
|
29
|
+
source $VENV_DIR/bin/activate
|
|
30
|
+
|
|
31
|
+
if [[ -f requirements.txt ]]
|
|
32
|
+
then
|
|
33
|
+
box "Installing/Upgrading packages"
|
|
34
|
+
|
|
35
|
+
python3 -m pip install -r requirements.txt
|
|
36
|
+
fi
|
|
37
|
+
|
|
38
|
+
if [[ -f ${VENV_NAME} ]]
|
|
39
|
+
then
|
|
40
|
+
box "Running ${VENV_NAME} script"
|
|
41
|
+
|
|
42
|
+
python3 ./${VENV_NAME}.py "$@"
|
|
43
|
+
|
|
44
|
+
deactivate
|
|
45
|
+
fi
|
|
46
|
+
"""
|
|
47
|
+
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: skilleter_modules
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: Modules used by my various Python projects (and hopefully useful to other people)
|
|
5
|
+
Author-email: John Skilleter <john@skilleter.org.uk>
|
|
6
|
+
Project-URL: Home, https://skilleter.org.uk
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Requires-Python: >=3.8
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Requires-Dist: requests
|
|
14
|
+
Requires-Dist: pygit2
|
|
15
|
+
Dynamic: license-file
|
|
16
|
+
|
|
17
|
+
# skilleter-modules
|
|
18
|
+
|
|
19
|
+
A collection of Python modules used in my various other Python projects (readable, skilleter-thingy, skilleter-extras)
|
|
20
|
+
|
|
21
|
+
## colour.py
|
|
22
|
+
|
|
23
|
+
Functions for writing coloured text using ANSI control code sequences
|
|
24
|
+
|
|
25
|
+
## dc_curses.py, dc_defaults.py, dc_util.py, dircolors.py
|
|
26
|
+
|
|
27
|
+
Colour filesystem objects similar to ls.
|
|
28
|
+
|
|
29
|
+
Large parts of this code are Copyright 2019 Allen Wild <allenwild93@gmail.com> released under the Apache-2.0 licence.
|
|
30
|
+
|
|
31
|
+
## files.py
|
|
32
|
+
|
|
33
|
+
Miscellaneous file-related functions - backup creation, file-type detection, etc.
|
|
34
|
+
|
|
35
|
+
## git.py
|
|
36
|
+
|
|
37
|
+
A git library
|
|
38
|
+
|
|
39
|
+
## gitlab.py
|
|
40
|
+
|
|
41
|
+
GitLab access module - due to be deprecated as I no longer support GitLab
|
|
42
|
+
|
|
43
|
+
## path.py
|
|
44
|
+
|
|
45
|
+
Filesystem path-related functions
|
|
46
|
+
|
|
47
|
+
## popup.py
|
|
48
|
+
|
|
49
|
+
Popup window class for curses
|
|
50
|
+
|
|
51
|
+
## run.py
|
|
52
|
+
|
|
53
|
+
Wrapper around the subprocess module, providing additional functionality
|
|
54
|
+
|
|
55
|
+
## tfm_pane.py
|
|
56
|
+
|
|
57
|
+
Console-pane-handling code for TFM - will probably be moved into the TFM project when that is split out from skilleter-thingy
|
|
58
|
+
|
|
59
|
+
## tidy.py
|
|
60
|
+
|
|
61
|
+
Functions for tidying log files - this may be moved into the skilleter-readable project at some point
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
skilleter_modules/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
skilleter_modules/colour.py,sha256=8fWsuMvqUrC8IUOj1e4x7xt_4WFAgq_gzcc5CXorydo,11201
|
|
3
|
+
skilleter_modules/dc_curses.py,sha256=fuuQPR11zV_akAhygL_cAhVLC5YAgKgowzlITVbETE8,8539
|
|
4
|
+
skilleter_modules/dc_defaults.py,sha256=ahcteQvoWZrO5iTU68zkIY1Zex6iX5uR5ubwI4CCYBk,6170
|
|
5
|
+
skilleter_modules/dc_util.py,sha256=Df73imXhHx3HzcPHiRcHAoea0e3HURdLcrolUsMhOFs,1783
|
|
6
|
+
skilleter_modules/dircolors.py,sha256=oGj08wJ512q8c08KSaTbahbtW01HYDDpBnsXUGwLGMQ,12252
|
|
7
|
+
skilleter_modules/files.py,sha256=YmmYgUoG3G1ZPrHmTuuTJqedLdVxyVsKvpFllLMVjdc,4703
|
|
8
|
+
skilleter_modules/git.py,sha256=wPov5Q6p-17gD5yi2olz43RV1GNqpa4HaCwraHnD_iQ,43284
|
|
9
|
+
skilleter_modules/gitlab.py,sha256=uXAF918xnPk6qQyiwPQDbMZfqtJzhiRqDS7yEtJEIAg,6079
|
|
10
|
+
skilleter_modules/path.py,sha256=8uM2Q9zFRWv_SaVOX49PeecQXttl7J6lsmBuRXWsXKY,4732
|
|
11
|
+
skilleter_modules/popup.py,sha256=TY9rpj4q8uZxerSt641LGUTy0TZgUjgfEX-CkRMuyek,2540
|
|
12
|
+
skilleter_modules/run.py,sha256=yFFUNqVHOMFvs8bIZSufYQhW1nukOuB0FGH5xFW6GzE,10578
|
|
13
|
+
skilleter_modules/tfm_pane.py,sha256=p-F_P7NObRni9MGB1RcEhcOG0NhnXM9yEf_VY9HHKBI,19741
|
|
14
|
+
skilleter_modules/tidy.py,sha256=AQ2RawsZJg6WHrgayi_ZptFL9occ7suSdCHbU3P-cys,5971
|
|
15
|
+
skilleter_modules/venv_template.py,sha256=ZfUvi8qFNGrk7J030Zy57xjwMtfIArJyqa-MqafyjVk,1016
|
|
16
|
+
skilleter_modules-0.0.1.dist-info/licenses/LICENSE,sha256=ljOS4DjXvqEo5VzGfdaRwgRZPbNScGBmfwyC8PChvmQ,32422
|
|
17
|
+
skilleter_modules-0.0.1.dist-info/METADATA,sha256=yS3_SIUpT7n3sOM39FwnuGZQ1illk2xDRG3OSJ0czks,1675
|
|
18
|
+
skilleter_modules-0.0.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
19
|
+
skilleter_modules-0.0.1.dist-info/top_level.txt,sha256=DMa0AkGOjoDHiHDG6Nw1jtdUylaMm5WkF6uODT9yxJc,18
|
|
20
|
+
skilleter_modules-0.0.1.dist-info/RECORD,,
|