archae 2026.1.0__tar.gz → 2026.2.0__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.
- {archae-2026.1.0 → archae-2026.2.0}/PKG-INFO +44 -30
- {archae-2026.1.0 → archae-2026.2.0}/README.md +38 -27
- {archae-2026.1.0 → archae-2026.2.0}/pyproject.toml +6 -3
- archae-2026.2.0/src/archae/__init__.py +5 -0
- archae-2026.2.0/src/archae/cli.py +176 -0
- archae-2026.2.0/src/archae/config.py +107 -0
- archae-2026.2.0/src/archae/default_settings.toml +9 -0
- archae-2026.2.0/src/archae/extractor.py +249 -0
- archae-2026.2.0/src/archae/options.yaml +39 -0
- {archae-2026.1.0 → archae-2026.2.0}/src/archae/util/archiver/base_archiver.py +2 -2
- archae-2026.2.0/src/archae/util/converter/file_size.py +77 -0
- {archae-2026.1.0 → archae-2026.2.0}/src/archae/util/enum/byte_scale.py +9 -0
- archae-2026.2.0/src/archae/util/file_tracker.py +93 -0
- archae-2026.2.0/src/archae/util/tool_manager.py +112 -0
- archae-2026.1.0/src/archae/__init__.py +0 -1
- archae-2026.1.0/src/archae/cli.py +0 -374
- {archae-2026.1.0 → archae-2026.2.0}/LICENSE +0 -0
- {archae-2026.1.0 → archae-2026.2.0}/src/archae/__main__.py +0 -0
- {archae-2026.1.0 → archae-2026.2.0}/src/archae/py.typed +0 -0
- {archae-2026.1.0 → archae-2026.2.0}/src/archae/util/__init__.py +0 -0
- {archae-2026.1.0 → archae-2026.2.0}/src/archae/util/archiver/__init__.py +0 -0
- {archae-2026.1.0 → archae-2026.2.0}/src/archae/util/archiver/peazip.py +0 -0
- {archae-2026.1.0 → archae-2026.2.0}/src/archae/util/archiver/seven_zip.py +0 -0
- {archae-2026.1.0 → archae-2026.2.0}/src/archae/util/archiver/unar.py +0 -0
- {archae-2026.1.0 → archae-2026.2.0}/src/archae/util/enum/__init__.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: archae
|
|
3
|
-
Version: 2026.
|
|
3
|
+
Version: 2026.2.0
|
|
4
4
|
Summary: Archae explodes archives.
|
|
5
5
|
Keywords:
|
|
6
6
|
Author: Shawn McNaughton
|
|
@@ -32,16 +32,19 @@ Classifier: Intended Audience :: Developers
|
|
|
32
32
|
Classifier: License :: OSI Approved :: MIT License
|
|
33
33
|
Classifier: Programming Language :: Python
|
|
34
34
|
Classifier: Programming Language :: Python :: 3
|
|
35
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
36
35
|
Classifier: Programming Language :: Python :: 3.12
|
|
37
36
|
Classifier: Programming Language :: Python :: 3.13
|
|
38
37
|
Classifier: Programming Language :: Python :: 3.14
|
|
39
38
|
Classifier: Programming Language :: Python :: 3 :: Only
|
|
40
39
|
Classifier: Typing :: Typed
|
|
41
40
|
Requires-Dist: click
|
|
41
|
+
Requires-Dist: dynaconf>=3.2.12
|
|
42
|
+
Requires-Dist: platformdirs>=4.5.1
|
|
42
43
|
Requires-Dist: python-magic
|
|
44
|
+
Requires-Dist: pyyaml>=6.0.3
|
|
43
45
|
Requires-Dist: rich-click
|
|
44
|
-
Requires-
|
|
46
|
+
Requires-Dist: types-pyyaml>=6
|
|
47
|
+
Requires-Python: >=3.12
|
|
45
48
|
Project-URL: Documentation, https://archae.readthedocs.io/en/stable/
|
|
46
49
|
Project-URL: Changelog, https://archae.readthedocs.io/en/stable/changelog.html
|
|
47
50
|
Project-URL: Source Code, https://github.com/shawngmc/archae
|
|
@@ -65,6 +68,27 @@ Archae explodes archives.
|
|
|
65
68
|
|
|
66
69
|
<!-- end docs-include-index -->
|
|
67
70
|
|
|
71
|
+
## Why
|
|
72
|
+
|
|
73
|
+
Every once and a while, I run into an issue: multiple layers of archives. The reasons vary, but examples would include:
|
|
74
|
+
|
|
75
|
+
- Searching for something in a ZIP of folders that contained a ZIP with a CD image in it
|
|
76
|
+
- Running a malware scan and finding an obscure archive format was missed and not even flagged
|
|
77
|
+
Meanwhile, I want to make sure I don't fill my disk, especially if an archive bomb (more commonly known as a ZIP bomb) has been jammed in somewhere. They're only funny the first time. :D
|
|
78
|
+
|
|
79
|
+
## Features
|
|
80
|
+
|
|
81
|
+
- Uses 7z/peazip/unar (not 7za/7zr) to try to extract archives
|
|
82
|
+
- No substantial limit on the number of archive layers
|
|
83
|
+
- Identifies file types via libmagic
|
|
84
|
+
- Detects duplicate archives
|
|
85
|
+
- Basic archive bomb protections
|
|
86
|
+
- MAX_ARCHIVE_SIZE_BYTES - ensures the uncompressed size of an archive is limited
|
|
87
|
+
- MAX_TOTAL_SIZE_BYTES - ensures the total extracted footprint isn't above a certain size
|
|
88
|
+
- MIN_ARCHIVE_RATIO - ensures very-high-compression-ratio archives are stopped
|
|
89
|
+
- MIN_DISK_FREE_SPACE - minimum free space at the extraction location
|
|
90
|
+
- MAX_DEPTH - allow setting a maximum archive depth to traverse
|
|
91
|
+
|
|
68
92
|
## Installation
|
|
69
93
|
|
|
70
94
|
<!-- start docs-include-installation -->
|
|
@@ -83,6 +107,13 @@ Check out the [Archae documentation](https://archae.readthedocs.io/en/stable/) f
|
|
|
83
107
|
|
|
84
108
|
## Usage
|
|
85
109
|
|
|
110
|
+
Configuration values are supplied one of four ways, and any item lower in this list will overwrite a prior one:
|
|
111
|
+
|
|
112
|
+
- Default values are stored in the app
|
|
113
|
+
- A TOML file at ~/.config/archae/ will be created on first run and can override those values (ex. MIN_ARCHIVE_RATIO = 0.005)
|
|
114
|
+
- Env vars starts starting with "ARCHAE\_" are parsed (ex. ARCHAE_MIN_ARCHIVE_RATIO=0.005)
|
|
115
|
+
- Values can be passed in as flags (ex. --min_archive_ratio=0.005)
|
|
116
|
+
|
|
86
117
|
<!-- start docs-include-usage -->
|
|
87
118
|
|
|
88
119
|
Running `archae --help` or `python -m archae --help` shows a list of all of the available options and arguments:
|
|
@@ -100,28 +131,18 @@ cog.outl(f"\n```sh\narchae --help\n{help.rstrip()}\n```\n")
|
|
|
100
131
|
```sh
|
|
101
132
|
archae --help
|
|
102
133
|
|
|
103
|
-
Usage: archae [OPTIONS]
|
|
134
|
+
Usage: archae [OPTIONS] COMMAND [ARGS]...
|
|
104
135
|
|
|
105
136
|
Archae explodes archives.
|
|
106
137
|
|
|
107
|
-
╭─ Arguments ──────────────────────────────────────────────────────────────────────────╮
|
|
108
|
-
│ * ARCHIVE_PATH FILE Archive to examine [required] │
|
|
109
|
-
╰──────────────────────────────────────────────────────────────────────────────────────╯
|
|
110
138
|
╭─ Options ────────────────────────────────────────────────────────────────────────────╮
|
|
111
|
-
│ --
|
|
112
|
-
│
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
│
|
|
116
|
-
│
|
|
117
|
-
│
|
|
118
|
-
│ --min_archive_ratio FLOAT RANGE [0<=x<=1] Minimum allowed compression │
|
|
119
|
-
│ ratio for an archive. A │
|
|
120
|
-
│ floating-point value between │
|
|
121
|
-
│ 0.0 and 1.0, inclusive. Default │
|
|
122
|
-
│ is 0.005 [default: 0.005] │
|
|
123
|
-
│ --version -v Show the version and exit. │
|
|
124
|
-
│ --help -h Show this message and exit. │
|
|
139
|
+
│ --version -v Show the version and exit. │
|
|
140
|
+
│ --help -h Show this message and exit. │
|
|
141
|
+
╰──────────────────────────────────────────────────────────────────────────────────────╯
|
|
142
|
+
╭─ Commands ───────────────────────────────────────────────────────────────────────────╮
|
|
143
|
+
│ extract Extract and analyze an archive. │
|
|
144
|
+
│ listopts List all available configuration options. │
|
|
145
|
+
│ status Show archae status and available tools. │
|
|
125
146
|
╰──────────────────────────────────────────────────────────────────────────────────────╯
|
|
126
147
|
```
|
|
127
148
|
|
|
@@ -129,19 +150,12 @@ archae --help
|
|
|
129
150
|
|
|
130
151
|
<!-- end docs-include-usage -->
|
|
131
152
|
|
|
132
|
-
## Features
|
|
133
|
-
|
|
134
|
-
- Uses 7z/peazip/unar (not 7za/7zr) to try to extract archives
|
|
135
|
-
- No substantial limit on the number of archive layers
|
|
136
|
-
- Identifies file types via libmagic
|
|
137
|
-
- Basic archive bomb protections
|
|
138
|
-
|
|
139
153
|
## TODOs
|
|
140
154
|
|
|
141
|
-
-
|
|
155
|
+
- More archive bomb protections
|
|
156
|
+
- delete_archives_as_exploded - remove archive files to reduce duplication (boolean)
|
|
142
157
|
- Improve archive type detection
|
|
143
158
|
- Separate between extractable and non-extractable archive types
|
|
144
|
-
- Protect against/detect depth attacks (excessively nested archives)
|
|
145
159
|
- Detect password-protected archives
|
|
146
160
|
- Allow supplying archive passwords by hash
|
|
147
161
|
- Add custom magic to detect obscure archive formats
|
|
@@ -15,6 +15,27 @@ Archae explodes archives.
|
|
|
15
15
|
|
|
16
16
|
<!-- end docs-include-index -->
|
|
17
17
|
|
|
18
|
+
## Why
|
|
19
|
+
|
|
20
|
+
Every once and a while, I run into an issue: multiple layers of archives. The reasons vary, but examples would include:
|
|
21
|
+
|
|
22
|
+
- Searching for something in a ZIP of folders that contained a ZIP with a CD image in it
|
|
23
|
+
- Running a malware scan and finding an obscure archive format was missed and not even flagged
|
|
24
|
+
Meanwhile, I want to make sure I don't fill my disk, especially if an archive bomb (more commonly known as a ZIP bomb) has been jammed in somewhere. They're only funny the first time. :D
|
|
25
|
+
|
|
26
|
+
## Features
|
|
27
|
+
|
|
28
|
+
- Uses 7z/peazip/unar (not 7za/7zr) to try to extract archives
|
|
29
|
+
- No substantial limit on the number of archive layers
|
|
30
|
+
- Identifies file types via libmagic
|
|
31
|
+
- Detects duplicate archives
|
|
32
|
+
- Basic archive bomb protections
|
|
33
|
+
- MAX_ARCHIVE_SIZE_BYTES - ensures the uncompressed size of an archive is limited
|
|
34
|
+
- MAX_TOTAL_SIZE_BYTES - ensures the total extracted footprint isn't above a certain size
|
|
35
|
+
- MIN_ARCHIVE_RATIO - ensures very-high-compression-ratio archives are stopped
|
|
36
|
+
- MIN_DISK_FREE_SPACE - minimum free space at the extraction location
|
|
37
|
+
- MAX_DEPTH - allow setting a maximum archive depth to traverse
|
|
38
|
+
|
|
18
39
|
## Installation
|
|
19
40
|
|
|
20
41
|
<!-- start docs-include-installation -->
|
|
@@ -33,6 +54,13 @@ Check out the [Archae documentation](https://archae.readthedocs.io/en/stable/) f
|
|
|
33
54
|
|
|
34
55
|
## Usage
|
|
35
56
|
|
|
57
|
+
Configuration values are supplied one of four ways, and any item lower in this list will overwrite a prior one:
|
|
58
|
+
|
|
59
|
+
- Default values are stored in the app
|
|
60
|
+
- A TOML file at ~/.config/archae/ will be created on first run and can override those values (ex. MIN_ARCHIVE_RATIO = 0.005)
|
|
61
|
+
- Env vars starts starting with "ARCHAE\_" are parsed (ex. ARCHAE_MIN_ARCHIVE_RATIO=0.005)
|
|
62
|
+
- Values can be passed in as flags (ex. --min_archive_ratio=0.005)
|
|
63
|
+
|
|
36
64
|
<!-- start docs-include-usage -->
|
|
37
65
|
|
|
38
66
|
Running `archae --help` or `python -m archae --help` shows a list of all of the available options and arguments:
|
|
@@ -50,28 +78,18 @@ cog.outl(f"\n```sh\narchae --help\n{help.rstrip()}\n```\n")
|
|
|
50
78
|
```sh
|
|
51
79
|
archae --help
|
|
52
80
|
|
|
53
|
-
Usage: archae [OPTIONS]
|
|
81
|
+
Usage: archae [OPTIONS] COMMAND [ARGS]...
|
|
54
82
|
|
|
55
83
|
Archae explodes archives.
|
|
56
84
|
|
|
57
|
-
╭─ Arguments ──────────────────────────────────────────────────────────────────────────╮
|
|
58
|
-
│ * ARCHIVE_PATH FILE Archive to examine [required] │
|
|
59
|
-
╰──────────────────────────────────────────────────────────────────────────────────────╯
|
|
60
85
|
╭─ Options ────────────────────────────────────────────────────────────────────────────╮
|
|
61
|
-
│ --
|
|
62
|
-
│
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
│
|
|
66
|
-
│
|
|
67
|
-
│
|
|
68
|
-
│ --min_archive_ratio FLOAT RANGE [0<=x<=1] Minimum allowed compression │
|
|
69
|
-
│ ratio for an archive. A │
|
|
70
|
-
│ floating-point value between │
|
|
71
|
-
│ 0.0 and 1.0, inclusive. Default │
|
|
72
|
-
│ is 0.005 [default: 0.005] │
|
|
73
|
-
│ --version -v Show the version and exit. │
|
|
74
|
-
│ --help -h Show this message and exit. │
|
|
86
|
+
│ --version -v Show the version and exit. │
|
|
87
|
+
│ --help -h Show this message and exit. │
|
|
88
|
+
╰──────────────────────────────────────────────────────────────────────────────────────╯
|
|
89
|
+
╭─ Commands ───────────────────────────────────────────────────────────────────────────╮
|
|
90
|
+
│ extract Extract and analyze an archive. │
|
|
91
|
+
│ listopts List all available configuration options. │
|
|
92
|
+
│ status Show archae status and available tools. │
|
|
75
93
|
╰──────────────────────────────────────────────────────────────────────────────────────╯
|
|
76
94
|
```
|
|
77
95
|
|
|
@@ -79,19 +97,12 @@ archae --help
|
|
|
79
97
|
|
|
80
98
|
<!-- end docs-include-usage -->
|
|
81
99
|
|
|
82
|
-
## Features
|
|
83
|
-
|
|
84
|
-
- Uses 7z/peazip/unar (not 7za/7zr) to try to extract archives
|
|
85
|
-
- No substantial limit on the number of archive layers
|
|
86
|
-
- Identifies file types via libmagic
|
|
87
|
-
- Basic archive bomb protections
|
|
88
|
-
|
|
89
100
|
## TODOs
|
|
90
101
|
|
|
91
|
-
-
|
|
102
|
+
- More archive bomb protections
|
|
103
|
+
- delete_archives_as_exploded - remove archive files to reduce duplication (boolean)
|
|
92
104
|
- Improve archive type detection
|
|
93
105
|
- Separate between extractable and non-extractable archive types
|
|
94
|
-
- Protect against/detect depth attacks (excessively nested archives)
|
|
95
106
|
- Detect password-protected archives
|
|
96
107
|
- Allow supplying archive passwords by hash
|
|
97
108
|
- Add custom magic to detect obscure archive formats
|
|
@@ -4,7 +4,7 @@ build-backend = "uv_build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "archae"
|
|
7
|
-
version = "2026.
|
|
7
|
+
version = "2026.2.0"
|
|
8
8
|
description = "Archae explodes archives."
|
|
9
9
|
authors = [{name = "Shawn McNaughton", email = "shawngmc@gmail.com"}]
|
|
10
10
|
readme = "README.md"
|
|
@@ -17,18 +17,21 @@ classifiers = [
|
|
|
17
17
|
"License :: OSI Approved :: MIT License",
|
|
18
18
|
"Programming Language :: Python",
|
|
19
19
|
"Programming Language :: Python :: 3",
|
|
20
|
-
"Programming Language :: Python :: 3.11",
|
|
21
20
|
"Programming Language :: Python :: 3.12",
|
|
22
21
|
"Programming Language :: Python :: 3.13",
|
|
23
22
|
"Programming Language :: Python :: 3.14",
|
|
24
23
|
"Programming Language :: Python :: 3 :: Only",
|
|
25
24
|
"Typing :: Typed",
|
|
26
25
|
]
|
|
27
|
-
requires-python = "
|
|
26
|
+
requires-python = ">=3.12"
|
|
28
27
|
dependencies = [
|
|
29
28
|
"click",
|
|
29
|
+
"dynaconf>=3.2.12",
|
|
30
|
+
"platformdirs>=4.5.1",
|
|
30
31
|
"python-magic",
|
|
32
|
+
"PyYAML>=6.0.3",
|
|
31
33
|
"rich_click",
|
|
34
|
+
"types-PyYAML>=6",
|
|
32
35
|
]
|
|
33
36
|
|
|
34
37
|
[dependency-groups]
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
"""Main CLI for archae."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import logging
|
|
6
|
+
import pathlib
|
|
7
|
+
from importlib import metadata
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
import rich_click as click
|
|
11
|
+
|
|
12
|
+
from archae.config import apply_options, convert_settings, get_options
|
|
13
|
+
from archae.extractor import ArchiveExtractor
|
|
14
|
+
from archae.util.tool_manager import ToolManager
|
|
15
|
+
|
|
16
|
+
logger = logging.getLogger("archae")
|
|
17
|
+
logger.setLevel(logging.INFO)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@click.group(
|
|
21
|
+
context_settings={"help_option_names": ["-h", "--help"], "show_default": True}
|
|
22
|
+
)
|
|
23
|
+
@click.rich_config(
|
|
24
|
+
help_config=click.RichHelpConfiguration(
|
|
25
|
+
width=88,
|
|
26
|
+
show_arguments=True,
|
|
27
|
+
text_markup=True,
|
|
28
|
+
),
|
|
29
|
+
)
|
|
30
|
+
@click.version_option(metadata.version("archae"), "-v", "--version")
|
|
31
|
+
def cli() -> None:
|
|
32
|
+
"""Archae explodes archives."""
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@cli.command()
|
|
36
|
+
@click.argument(
|
|
37
|
+
"archive_path",
|
|
38
|
+
type=click.Path(exists=True, dir_okay=False, readable=True, path_type=pathlib.Path),
|
|
39
|
+
default=Path.cwd() / "extracted",
|
|
40
|
+
help="Archive to examine",
|
|
41
|
+
)
|
|
42
|
+
@click.option(
|
|
43
|
+
"-o",
|
|
44
|
+
"--opt",
|
|
45
|
+
"options",
|
|
46
|
+
nargs=2,
|
|
47
|
+
type=click.Tuple([str, str]),
|
|
48
|
+
multiple=True,
|
|
49
|
+
help="Set config options as key value pairs. Use 'archae listopts' to see available options.",
|
|
50
|
+
)
|
|
51
|
+
@click.option(
|
|
52
|
+
"-e",
|
|
53
|
+
"--extract-dir",
|
|
54
|
+
"extract_dir",
|
|
55
|
+
nargs=1,
|
|
56
|
+
type=click.Path(
|
|
57
|
+
dir_okay=True,
|
|
58
|
+
file_okay=False,
|
|
59
|
+
readable=True,
|
|
60
|
+
writable=True,
|
|
61
|
+
path_type=pathlib.Path,
|
|
62
|
+
),
|
|
63
|
+
default=Path.cwd() / "extracted",
|
|
64
|
+
help="Set config options as key value pairs. Use 'archae listopts' to see available options.",
|
|
65
|
+
)
|
|
66
|
+
def extract(
|
|
67
|
+
archive_path: pathlib.Path,
|
|
68
|
+
options: list[tuple[str, str]] | None,
|
|
69
|
+
extract_dir: pathlib.Path,
|
|
70
|
+
) -> None:
|
|
71
|
+
"""Extract and analyze an archive."""
|
|
72
|
+
# Apply any options from the command line, then convert any convertible settings
|
|
73
|
+
if options:
|
|
74
|
+
apply_options(options)
|
|
75
|
+
convert_settings()
|
|
76
|
+
|
|
77
|
+
# Locate external tools
|
|
78
|
+
ToolManager.locate_tools()
|
|
79
|
+
extractor = ArchiveExtractor(extract_dir=extract_dir)
|
|
80
|
+
extractor.handle_file(archive_path)
|
|
81
|
+
print_tracked_files(extractor.get_tracked_files())
|
|
82
|
+
print_warnings(extractor.get_warnings())
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
@cli.command()
|
|
86
|
+
def listopts() -> None:
|
|
87
|
+
"""List all available configuration options."""
|
|
88
|
+
options = get_options()
|
|
89
|
+
|
|
90
|
+
# Load default settings
|
|
91
|
+
defaults_path = Path(__file__).parent / "default_settings.toml"
|
|
92
|
+
defaults_content = defaults_path.read_text()
|
|
93
|
+
defaults = {}
|
|
94
|
+
in_default_section = False
|
|
95
|
+
for line in defaults_content.split("\n"):
|
|
96
|
+
if line.strip() == "[default]":
|
|
97
|
+
in_default_section = True
|
|
98
|
+
continue
|
|
99
|
+
if in_default_section and line.startswith("["):
|
|
100
|
+
break
|
|
101
|
+
if in_default_section and "=" in line:
|
|
102
|
+
key, value = line.split("=", 1)
|
|
103
|
+
defaults[key.strip()] = value.strip().strip('"')
|
|
104
|
+
|
|
105
|
+
logger.info("Available configuration options:")
|
|
106
|
+
logger.info("------------------------------------------------")
|
|
107
|
+
for option_name, option_def in sorted(options.items()):
|
|
108
|
+
logger.info("%s (%s)", option_name, option_def.get("type", "unknown"))
|
|
109
|
+
logger.info(" %s", option_def.get("help", "No description available"))
|
|
110
|
+
if option_name in defaults:
|
|
111
|
+
logger.info(" Default: %s", defaults[option_name])
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
@cli.command()
|
|
115
|
+
def status() -> None:
|
|
116
|
+
"""Show archae status and available tools."""
|
|
117
|
+
logger.info("Archae status:")
|
|
118
|
+
logger.info("Version: %s", metadata.version("archae"))
|
|
119
|
+
ToolManager.locate_tools()
|
|
120
|
+
logger.info("Tools located and ready to use.")
|
|
121
|
+
logger.info("------------------------------------------------")
|
|
122
|
+
|
|
123
|
+
# Show supported extensions
|
|
124
|
+
supported_ext = ToolManager.get_supported_extensions()
|
|
125
|
+
logger.info("Supported file extensions (%d):", len(supported_ext))
|
|
126
|
+
if supported_ext:
|
|
127
|
+
logger.info(" %s", ", ".join(supported_ext))
|
|
128
|
+
else:
|
|
129
|
+
logger.info(" (none)")
|
|
130
|
+
|
|
131
|
+
# Show unsupported extensions
|
|
132
|
+
unsupported_ext = ToolManager.get_unsupported_extensions()
|
|
133
|
+
logger.info("Unsupported file extensions (%d):", len(unsupported_ext))
|
|
134
|
+
if unsupported_ext:
|
|
135
|
+
logger.info(" %s", ", ".join(unsupported_ext))
|
|
136
|
+
else:
|
|
137
|
+
logger.info(" (none)")
|
|
138
|
+
|
|
139
|
+
logger.info("------------------------------------------------")
|
|
140
|
+
|
|
141
|
+
# Show supported MIME types
|
|
142
|
+
supported_mime = ToolManager.get_supported_mime_types()
|
|
143
|
+
logger.info("Supported MIME types (%d):", len(supported_mime))
|
|
144
|
+
if supported_mime:
|
|
145
|
+
logger.info(" %s", ", ".join(supported_mime))
|
|
146
|
+
else:
|
|
147
|
+
logger.info(" (none)")
|
|
148
|
+
|
|
149
|
+
# Show unsupported MIME types
|
|
150
|
+
unsupported_mime = ToolManager.get_unsupported_mime_types()
|
|
151
|
+
logger.info("Unsupported MIME types (%d):", len(unsupported_mime))
|
|
152
|
+
if unsupported_mime:
|
|
153
|
+
logger.info(" %s", ", ".join(unsupported_mime))
|
|
154
|
+
else:
|
|
155
|
+
logger.info(" (none)")
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
def print_tracked_files(tracked_files: dict[str, dict]) -> None:
|
|
159
|
+
"""Print the tracked files for debugging purposes."""
|
|
160
|
+
logger.info("------------------------------------------------")
|
|
161
|
+
for hash, info in tracked_files.items():
|
|
162
|
+
logger.info("Hash: %s", hash)
|
|
163
|
+
logger.info(" Size: %s bytes", info.get("size", "Unknown"))
|
|
164
|
+
for path in info.get("paths", []):
|
|
165
|
+
logger.info(" Path: %s", path)
|
|
166
|
+
logger.info(" Metadata:")
|
|
167
|
+
for key, value in info.get("metadata", {}).items():
|
|
168
|
+
logger.info(" %s: %s", key, value)
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
def print_warnings(warnings: list[str]) -> None:
|
|
172
|
+
"""Print accumulated warnings for debugging purposes."""
|
|
173
|
+
logger.info("------------------------------------------------")
|
|
174
|
+
logger.info("Accumulated Warnings:")
|
|
175
|
+
for warning in warnings: # type: ignore[attr-defined]
|
|
176
|
+
logger.info(warning)
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"""Runtime config management (default, userconfig and envvars)."""
|
|
2
|
+
|
|
3
|
+
import importlib
|
|
4
|
+
import typing
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
import platformdirs
|
|
8
|
+
import yaml
|
|
9
|
+
from dynaconf import Dynaconf
|
|
10
|
+
|
|
11
|
+
# Get the package directory for default settings
|
|
12
|
+
package_dir = Path(__file__).parent
|
|
13
|
+
default_settings_file = package_dir / "default_settings.toml"
|
|
14
|
+
|
|
15
|
+
# Get the config directory following XDG standards
|
|
16
|
+
config_dir = Path(platformdirs.user_config_dir("archae"))
|
|
17
|
+
config_dir.mkdir(parents=True, exist_ok=True)
|
|
18
|
+
|
|
19
|
+
# Define the user config file path
|
|
20
|
+
user_config_file = config_dir / "settings.toml"
|
|
21
|
+
|
|
22
|
+
# Create a default settings.toml if it doesn't exist
|
|
23
|
+
if not user_config_file.exists():
|
|
24
|
+
user_config_file.write_text("""# Archae configuration
|
|
25
|
+
# Override defaults from the package here
|
|
26
|
+
""")
|
|
27
|
+
|
|
28
|
+
settings = Dynaconf(
|
|
29
|
+
envvar_prefix="ARCHAE",
|
|
30
|
+
settings_files=[
|
|
31
|
+
str(default_settings_file), # Load package defaults first
|
|
32
|
+
str(user_config_file), # User settings override defaults
|
|
33
|
+
],
|
|
34
|
+
environments=True,
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
default_settings = Dynaconf(
|
|
38
|
+
envvar_prefix="ARCHAE",
|
|
39
|
+
settings_files=[
|
|
40
|
+
str(default_settings_file), # Load package defaults first
|
|
41
|
+
],
|
|
42
|
+
environments=True,
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
options_file = package_dir / "options.yaml"
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def get_options() -> dict:
|
|
50
|
+
"""Return the contents of options.yaml."""
|
|
51
|
+
with Path.open(options_file) as f:
|
|
52
|
+
return yaml.safe_load(f)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def get_converter(converter_def: str) -> typing.Callable:
|
|
56
|
+
"""Dynamically import and instantiate a converter class.
|
|
57
|
+
|
|
58
|
+
Args:
|
|
59
|
+
converter_def (str): Converter definition in format "module.path:ClassName" or a builtin type like "float" or "int".
|
|
60
|
+
|
|
61
|
+
Returns:
|
|
62
|
+
Converter function.
|
|
63
|
+
"""
|
|
64
|
+
# Handle built-in types
|
|
65
|
+
if converter_def == "float":
|
|
66
|
+
return float
|
|
67
|
+
if converter_def == "int":
|
|
68
|
+
return int
|
|
69
|
+
|
|
70
|
+
# Split the definition into module path and class name
|
|
71
|
+
module_name, class_name = converter_def.split(":")
|
|
72
|
+
|
|
73
|
+
# Import the module
|
|
74
|
+
module = importlib.import_module(module_name)
|
|
75
|
+
|
|
76
|
+
# Get the class from the module
|
|
77
|
+
return getattr(module, class_name)
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def apply_options(option_list: list[tuple[str, str]]) -> None:
|
|
81
|
+
"""Apply a list of options to the settings.
|
|
82
|
+
|
|
83
|
+
Args:
|
|
84
|
+
option_list (list[tuple[str, str]]): List of key-value pairs to apply.
|
|
85
|
+
|
|
86
|
+
"""
|
|
87
|
+
options = get_options()
|
|
88
|
+
for key, value in option_list:
|
|
89
|
+
# Find the option definition by matching the key
|
|
90
|
+
option_def = None
|
|
91
|
+
for def_key in options:
|
|
92
|
+
option_def = options[def_key]
|
|
93
|
+
break
|
|
94
|
+
if option_def:
|
|
95
|
+
settings[key] = value
|
|
96
|
+
else:
|
|
97
|
+
pass
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def convert_settings() -> None:
|
|
101
|
+
"""Convert settings using their defined converters."""
|
|
102
|
+
options = get_options()
|
|
103
|
+
for key in options:
|
|
104
|
+
option_def = options[key]
|
|
105
|
+
if "converter" in option_def:
|
|
106
|
+
converter = get_converter(option_def["converter"])
|
|
107
|
+
settings[key] = converter(settings[key])
|