offgrep 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.
- offgrep/__init__.py +0 -0
- offgrep/__main__.py +107 -0
- offgrep-0.0.1.dist-info/METADATA +70 -0
- offgrep-0.0.1.dist-info/RECORD +6 -0
- offgrep-0.0.1.dist-info/WHEEL +4 -0
- offgrep-0.0.1.dist-info/entry_points.txt +4 -0
offgrep/__init__.py
ADDED
|
File without changes
|
offgrep/__main__.py
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
|
|
3
|
+
"""
|
|
4
|
+
Call as script
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import sys
|
|
8
|
+
|
|
9
|
+
from argparse import ArgumentParser, Namespace
|
|
10
|
+
from importlib.metadata import PackageNotFoundError, version as metadata_version
|
|
11
|
+
from logging import WARNING
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
from tomllib import loads as tomli_loads
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
PACKAGE_NAME = "offgrep"
|
|
17
|
+
"""The package name for metadata inspection"""
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def get_file_contents(file_name: str, up_dirs: int = 0) -> str:
|
|
21
|
+
"""get contents of a file in an ancestor directory
|
|
22
|
+
of the current file
|
|
23
|
+
|
|
24
|
+
...
|
|
25
|
+
"""
|
|
26
|
+
file_dir_path = Path(__file__).resolve()
|
|
27
|
+
for _ in range(up_dirs):
|
|
28
|
+
file_dir_path = file_dir_path.parent
|
|
29
|
+
#
|
|
30
|
+
file_path = file_dir_path / file_name
|
|
31
|
+
return file_path.read_text(encoding="utf-8")
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def get_metadata_version(
|
|
35
|
+
metadata_file_name: str = "pyproject.toml", up_dirs: int = 3
|
|
36
|
+
) -> str:
|
|
37
|
+
"""get version information from _metadata_file_name_ in an ancestor directory
|
|
38
|
+
|
|
39
|
+
...
|
|
40
|
+
"""
|
|
41
|
+
try:
|
|
42
|
+
metadata_file_contents = get_file_contents(metadata_file_name, up_dirs=up_dirs)
|
|
43
|
+
except IOError as error:
|
|
44
|
+
return str(error)
|
|
45
|
+
#
|
|
46
|
+
metadata = tomli_loads(metadata_file_contents)
|
|
47
|
+
try:
|
|
48
|
+
# logging.warning(str(metadata.items()))
|
|
49
|
+
version = metadata["project"]["version"]
|
|
50
|
+
except KeyError:
|
|
51
|
+
return f"Error: no version information in metadata from {metadata_file_name}"
|
|
52
|
+
#
|
|
53
|
+
return f"{version} (read directly from {metadata_file_name})"
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
# pylint: disable=unused-argument ; functions not implemented yet
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def grep_files(arguments: Namespace) -> int:
|
|
60
|
+
"""Search for text in files"""
|
|
61
|
+
return 0
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def list_files(arguments: Namespace) -> int:
|
|
65
|
+
"""List files that would be searched"""
|
|
66
|
+
return 0
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
# pylint: enable=unused-argument
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def main() -> int:
|
|
73
|
+
"""Main script interface
|
|
74
|
+
|
|
75
|
+
Returns:
|
|
76
|
+
the script rteurncode
|
|
77
|
+
"""
|
|
78
|
+
try:
|
|
79
|
+
version = metadata_version(PACKAGE_NAME)
|
|
80
|
+
except PackageNotFoundError:
|
|
81
|
+
version = get_metadata_version()
|
|
82
|
+
#
|
|
83
|
+
main_parser = ArgumentParser(
|
|
84
|
+
prog="offgrep", description="searches text in (text) files recursively"
|
|
85
|
+
)
|
|
86
|
+
main_parser.set_defaults(loglevel=WARNING, extra_ignore=".git/")
|
|
87
|
+
main_parser.add_argument("-V", "--version", action="version", version=version)
|
|
88
|
+
main_parser.add_argument(
|
|
89
|
+
"--extra-ignore",
|
|
90
|
+
help="extra ignore rules separated by comma (default: %(default)s)",
|
|
91
|
+
)
|
|
92
|
+
main_parser.add_argument(
|
|
93
|
+
"--files",
|
|
94
|
+
action="store_true",
|
|
95
|
+
help="list the files that would be searched",
|
|
96
|
+
)
|
|
97
|
+
arguments = main_parser.parse_args()
|
|
98
|
+
if arguments.files:
|
|
99
|
+
return list_files(arguments)
|
|
100
|
+
#
|
|
101
|
+
return grep_files(arguments)
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
if __name__ == "__main__":
|
|
105
|
+
sys.exit(main()) # pragma: no cover
|
|
106
|
+
|
|
107
|
+
# vim: fileencoding=utf-8 ts=4 sts=4 sw=4 autoindent expandtab syntax=python:
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: offgrep
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: A lousy ripgrep rip-off in pure Python
|
|
5
|
+
Keywords: grep,recursive
|
|
6
|
+
Author: Rainer Schwarzbach
|
|
7
|
+
Author-email: Rainer Schwarzbach <rainer@blackstream.de>
|
|
8
|
+
License: MIT License
|
|
9
|
+
|
|
10
|
+
Copyright (c) 2026 Rainer Schwarzbach
|
|
11
|
+
|
|
12
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
13
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
14
|
+
in the Software without restriction, including without limitation the rights
|
|
15
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
16
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
17
|
+
furnished to do so, subject to the following conditions:
|
|
18
|
+
|
|
19
|
+
The above copyright notice and this permission notice shall be included in all
|
|
20
|
+
copies or substantial portions of the Software.
|
|
21
|
+
|
|
22
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
23
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
24
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
25
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
26
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
27
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
28
|
+
SOFTWARE.
|
|
29
|
+
Classifier: Development Status :: 3 - Alpha
|
|
30
|
+
Classifier: Operating System :: OS Independent
|
|
31
|
+
Classifier: Programming Language :: Python :: 3
|
|
32
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
33
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
34
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
35
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
36
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
37
|
+
Classifier: Environment :: Console
|
|
38
|
+
Classifier: Topic :: Utilities
|
|
39
|
+
Classifier: Intended Audience :: Developers
|
|
40
|
+
Classifier: Intended Audience :: System Administrators
|
|
41
|
+
Requires-Python: >=3.11
|
|
42
|
+
Project-URL: Homepage, https://gitlab.com/blackstream-x/offgrep
|
|
43
|
+
Project-URL: CI, https://gitlab.com/blackstream-x/offgrep/-/pipelines
|
|
44
|
+
Project-URL: Bug Tracker, https://gitlab.com/blackstream-x/offgrep/-/issues
|
|
45
|
+
Project-URL: Repository, https://gitlab.com/blackstream-x/offgrep.git
|
|
46
|
+
Project-URL: Documentation, https://blackstream-x.gitlab.io/offgrep/
|
|
47
|
+
Description-Content-Type: text/markdown
|
|
48
|
+
|
|
49
|
+
# offgrep
|
|
50
|
+
|
|
51
|
+
_A lousy **[ripgrep]** rip-off in pure Python_
|
|
52
|
+
|
|
53
|
+
[ripgrep]: https://github.com/burntsushi/ripgrep
|
|
54
|
+
|
|
55
|
+
Searches text in a grep-like manner in text files,
|
|
56
|
+
recursively searching for files from the provided starting-point
|
|
57
|
+
or from the current working directory.
|
|
58
|
+
|
|
59
|
+
When doing so, **offgrep** respects ignore rules in a **.gitignore** file.
|
|
60
|
+
|
|
61
|
+
This behavior is a small fraction of **ripgrep’s** capabilities,
|
|
62
|
+
combined with a ridiculously low execution speed.
|
|
63
|
+
|
|
64
|
+
So if you have any chance to run the original, please use **ripgrep**
|
|
65
|
+
instead of **offgrep**.
|
|
66
|
+
|
|
67
|
+
If you – however – are in a super restricted network (eg. government)
|
|
68
|
+
without a chance to install **ripgrep**,
|
|
69
|
+
but are able to install Python packages, **offgrep** might be an interesting
|
|
70
|
+
alterative.
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
offgrep/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
offgrep/__main__.py,sha256=xW0Obfu-dWh5DOrqtZewkFyo0Kh3-yJnLYSSbb1zNaQ,2813
|
|
3
|
+
offgrep-0.0.1.dist-info/WHEEL,sha256=jK0lbM7sVtq70msNoYotEXYS3OJMDdns2CRgyjhimnE,81
|
|
4
|
+
offgrep-0.0.1.dist-info/entry_points.txt,sha256=VxvvRRqIHquOqFhJ9CgDzrKmVIaz-GdkaYQx3hChfX0,78
|
|
5
|
+
offgrep-0.0.1.dist-info/METADATA,sha256=OdTjvWHg29XusPOyIRQScs1vVtrEqr6uJ6F8-6kNYUo,3208
|
|
6
|
+
offgrep-0.0.1.dist-info/RECORD,,
|