flat-packager 0.4.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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Thomas
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,244 @@
1
+ Metadata-Version: 2.4
2
+ Name: flat-packager
3
+ Version: 0.4.0
4
+ Summary: Pack a repository into one flat text archive and restore it later.
5
+ Author: Thomas
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/tomanizer/flat-packager
8
+ Project-URL: Repository, https://github.com/tomanizer/flat-packager
9
+ Project-URL: Documentation, https://github.com/tomanizer/flat-packager#readme
10
+ Project-URL: Changelog, https://github.com/tomanizer/flat-packager/blob/main/CHANGELOG.md
11
+ Keywords: archive,repository,github,packaging,restore
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Environment :: Console
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3 :: Only
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Programming Language :: Python :: 3.13
21
+ Classifier: Programming Language :: Python :: 3.14
22
+ Classifier: Topic :: Software Development :: Version Control :: Git
23
+ Classifier: Topic :: System :: Archiving
24
+ Requires-Python: >=3.10
25
+ Description-Content-Type: text/markdown
26
+ License-File: LICENSE
27
+ Provides-Extra: dev
28
+ Requires-Dist: build>=1.2; extra == "dev"
29
+ Requires-Dist: twine>=5.0; extra == "dev"
30
+ Dynamic: license-file
31
+
32
+ # Flat Packager
33
+
34
+ Flat Packager turns a repository into one flat text archive, then rebuilds the
35
+ original folder structure from that archive.
36
+
37
+ The default archive format is newline-delimited JSON with chunked base64 file
38
+ payloads. Text files, binary files, empty directories, and symlinks survive the
39
+ round trip. Restores validate archive paths, duplicate entries, symlink
40
+ ancestry, chunk ordering, and recorded SHA-256 hashes before writing file
41
+ contents.
42
+
43
+ ## Install
44
+
45
+ From PyPI:
46
+
47
+ ```bash
48
+ python3 -m pip install flat-packager
49
+ ```
50
+
51
+ From a checkout:
52
+
53
+ ```bash
54
+ python3 -m pip install .
55
+ ```
56
+
57
+ For development:
58
+
59
+ ```bash
60
+ python3 -m pip install -e ".[dev]"
61
+ make test
62
+ ```
63
+
64
+ This installs four console commands:
65
+
66
+ ```bash
67
+ flat-pack --help
68
+ flat-unpack --help
69
+ flat-inspect --help
70
+ flat-verify --help
71
+ ```
72
+
73
+ The repository also keeps compatibility wrappers:
74
+
75
+ ```bash
76
+ python3 pack_repo.py --help
77
+ python3 unpack_repo.py --help
78
+ ```
79
+
80
+ ## Pack a Repository
81
+
82
+ Pack a local repository:
83
+
84
+ ```bash
85
+ flat-pack /path/to/repo repo.flat.txt
86
+ ```
87
+
88
+ Pack a public GitHub repository by shorthand or Git URL:
89
+
90
+ ```bash
91
+ flat-pack owner/repo repo.flat.txt
92
+ flat-pack https://github.com/owner/repo.git repo.flat.txt
93
+ ```
94
+
95
+ Remote repositories are cloned with `--depth 1` by default. You can select a
96
+ branch or tag, include submodules, or request a full clone:
97
+
98
+ ```bash
99
+ flat-pack owner/repo repo.flat.txt --branch main
100
+ flat-pack owner/repo repo.flat.txt --recurse-submodules
101
+ flat-pack owner/repo repo.flat.txt --no-shallow
102
+ ```
103
+
104
+ By default, local directory scans include all files and directories except
105
+ `.git`. To include only tracked git files:
106
+
107
+ ```bash
108
+ flat-pack /path/to/repo repo.flat.txt --tracked-only
109
+ ```
110
+
111
+ Useful options:
112
+
113
+ ```bash
114
+ flat-pack /path/to/repo repo.flat.txt --exclude "node_modules/*"
115
+ flat-pack /path/to/repo repo.flat.txt --max-file-bytes 10485760
116
+ flat-pack /path/to/repo repo.flat.txt --include-git
117
+ ```
118
+
119
+ ## Format and Compression
120
+
121
+ New archives use format version 2 by default. Version 2 stores each regular
122
+ file as metadata plus one or more base64 chunk records, which keeps memory usage
123
+ bounded while packing and restoring large files.
124
+
125
+ ```bash
126
+ flat-pack /path/to/repo repo.flat.txt --chunk-size 1048576
127
+ ```
128
+
129
+ To write the legacy inline format:
130
+
131
+ ```bash
132
+ flat-pack /path/to/repo repo.v1.flat.txt --format-version 1
133
+ ```
134
+
135
+ To gzip-compress an archive:
136
+
137
+ ```bash
138
+ flat-pack /path/to/repo repo.flat.txt.gz --compress gzip
139
+ ```
140
+
141
+ `--compress auto` is the default and writes gzip when the output path ends in
142
+ `.gz`. Restore, inspect, and verify commands auto-detect gzip archives.
143
+
144
+ ## Restore a Repository
145
+
146
+ ```bash
147
+ flat-unpack repo.flat.txt restored-repo
148
+ ```
149
+
150
+ If the output directory already contains files:
151
+
152
+ ```bash
153
+ flat-unpack repo.flat.txt restored-repo --overwrite
154
+ ```
155
+
156
+ Restores are staged in a temporary sibling directory and moved into place only
157
+ after the full archive validates and writes successfully. If validation fails,
158
+ the existing output directory is left unchanged.
159
+
160
+ Validate an archive without writing files:
161
+
162
+ ```bash
163
+ flat-unpack repo.flat.txt restored-repo --verify-only
164
+ ```
165
+
166
+ You can also validate without naming an output directory:
167
+
168
+ ```bash
169
+ flat-verify repo.flat.txt
170
+ ```
171
+
172
+ On systems where symlink creation is unavailable:
173
+
174
+ ```bash
175
+ flat-unpack repo.flat.txt restored-repo --no-symlinks
176
+ ```
177
+
178
+ ## Inspect an Archive
179
+
180
+ ```bash
181
+ flat-inspect repo.flat.txt
182
+ flat-inspect repo.flat.txt --json
183
+ flat-inspect repo.flat.txt --limit 20
184
+ ```
185
+
186
+ Inspection validates the archive first, then reports version, compression,
187
+ source metadata, entry counts, total file bytes, chunk count, largest files, and
188
+ symlinks.
189
+
190
+ ## Safety Model
191
+
192
+ Flat Packager is intended for moving repository snapshots, not for executing or
193
+ trusting their contents. Treat archives from untrusted sources the same way you
194
+ would treat a zip file from an untrusted source.
195
+
196
+ The restore step rejects:
197
+
198
+ - absolute archive paths
199
+ - `..`, `.`, empty, or backslash path segments
200
+ - duplicate archive paths
201
+ - file or directory records nested underneath an archived symlink
202
+ - chunk records that are missing, out of order, corrupt, or attached to the
203
+ wrong file
204
+ - corrupt base64, size, or SHA-256 data
205
+
206
+ Restored symlinks may still point outside the restored repository, because that
207
+ is valid repository content. Use `--no-symlinks` if you want symlink targets
208
+ written as text files instead.
209
+
210
+ ## Limitations
211
+
212
+ - File contents are base64 encoded, so archives are larger than raw file bytes.
213
+ Use gzip compression when archive size matters.
214
+ - Legacy format version 1 stores each file as one JSON record and is
215
+ memory-heavy for large files. Version 2 is chunked and is the default.
216
+ - Remote GitHub packing depends on local `git` and whatever authentication your
217
+ git installation already has configured.
218
+ - Git LFS files are captured as whatever exists in the cloned checkout. If LFS
219
+ smudge is disabled or unavailable, pointer files may be archived instead of
220
+ large objects.
221
+ - This stores file bytes, directory modes, file modes, and symlink targets. It
222
+ does not preserve owners, groups, extended attributes, ACLs, hard links,
223
+ timestamps, git history, or ignored remote refs.
224
+
225
+ ## Test
226
+
227
+ ```bash
228
+ python3 -m unittest discover -s tests
229
+ ```
230
+
231
+ Build a wheel:
232
+
233
+ ```bash
234
+ python3 -m pip install ".[dev]"
235
+ python3 -m build
236
+ ```
237
+
238
+ ## Release
239
+
240
+ See [CHANGELOG.md](CHANGELOG.md) and [docs/RELEASING.md](docs/RELEASING.md).
241
+
242
+ ```bash
243
+ make release-check
244
+ ```
@@ -0,0 +1,213 @@
1
+ # Flat Packager
2
+
3
+ Flat Packager turns a repository into one flat text archive, then rebuilds the
4
+ original folder structure from that archive.
5
+
6
+ The default archive format is newline-delimited JSON with chunked base64 file
7
+ payloads. Text files, binary files, empty directories, and symlinks survive the
8
+ round trip. Restores validate archive paths, duplicate entries, symlink
9
+ ancestry, chunk ordering, and recorded SHA-256 hashes before writing file
10
+ contents.
11
+
12
+ ## Install
13
+
14
+ From PyPI:
15
+
16
+ ```bash
17
+ python3 -m pip install flat-packager
18
+ ```
19
+
20
+ From a checkout:
21
+
22
+ ```bash
23
+ python3 -m pip install .
24
+ ```
25
+
26
+ For development:
27
+
28
+ ```bash
29
+ python3 -m pip install -e ".[dev]"
30
+ make test
31
+ ```
32
+
33
+ This installs four console commands:
34
+
35
+ ```bash
36
+ flat-pack --help
37
+ flat-unpack --help
38
+ flat-inspect --help
39
+ flat-verify --help
40
+ ```
41
+
42
+ The repository also keeps compatibility wrappers:
43
+
44
+ ```bash
45
+ python3 pack_repo.py --help
46
+ python3 unpack_repo.py --help
47
+ ```
48
+
49
+ ## Pack a Repository
50
+
51
+ Pack a local repository:
52
+
53
+ ```bash
54
+ flat-pack /path/to/repo repo.flat.txt
55
+ ```
56
+
57
+ Pack a public GitHub repository by shorthand or Git URL:
58
+
59
+ ```bash
60
+ flat-pack owner/repo repo.flat.txt
61
+ flat-pack https://github.com/owner/repo.git repo.flat.txt
62
+ ```
63
+
64
+ Remote repositories are cloned with `--depth 1` by default. You can select a
65
+ branch or tag, include submodules, or request a full clone:
66
+
67
+ ```bash
68
+ flat-pack owner/repo repo.flat.txt --branch main
69
+ flat-pack owner/repo repo.flat.txt --recurse-submodules
70
+ flat-pack owner/repo repo.flat.txt --no-shallow
71
+ ```
72
+
73
+ By default, local directory scans include all files and directories except
74
+ `.git`. To include only tracked git files:
75
+
76
+ ```bash
77
+ flat-pack /path/to/repo repo.flat.txt --tracked-only
78
+ ```
79
+
80
+ Useful options:
81
+
82
+ ```bash
83
+ flat-pack /path/to/repo repo.flat.txt --exclude "node_modules/*"
84
+ flat-pack /path/to/repo repo.flat.txt --max-file-bytes 10485760
85
+ flat-pack /path/to/repo repo.flat.txt --include-git
86
+ ```
87
+
88
+ ## Format and Compression
89
+
90
+ New archives use format version 2 by default. Version 2 stores each regular
91
+ file as metadata plus one or more base64 chunk records, which keeps memory usage
92
+ bounded while packing and restoring large files.
93
+
94
+ ```bash
95
+ flat-pack /path/to/repo repo.flat.txt --chunk-size 1048576
96
+ ```
97
+
98
+ To write the legacy inline format:
99
+
100
+ ```bash
101
+ flat-pack /path/to/repo repo.v1.flat.txt --format-version 1
102
+ ```
103
+
104
+ To gzip-compress an archive:
105
+
106
+ ```bash
107
+ flat-pack /path/to/repo repo.flat.txt.gz --compress gzip
108
+ ```
109
+
110
+ `--compress auto` is the default and writes gzip when the output path ends in
111
+ `.gz`. Restore, inspect, and verify commands auto-detect gzip archives.
112
+
113
+ ## Restore a Repository
114
+
115
+ ```bash
116
+ flat-unpack repo.flat.txt restored-repo
117
+ ```
118
+
119
+ If the output directory already contains files:
120
+
121
+ ```bash
122
+ flat-unpack repo.flat.txt restored-repo --overwrite
123
+ ```
124
+
125
+ Restores are staged in a temporary sibling directory and moved into place only
126
+ after the full archive validates and writes successfully. If validation fails,
127
+ the existing output directory is left unchanged.
128
+
129
+ Validate an archive without writing files:
130
+
131
+ ```bash
132
+ flat-unpack repo.flat.txt restored-repo --verify-only
133
+ ```
134
+
135
+ You can also validate without naming an output directory:
136
+
137
+ ```bash
138
+ flat-verify repo.flat.txt
139
+ ```
140
+
141
+ On systems where symlink creation is unavailable:
142
+
143
+ ```bash
144
+ flat-unpack repo.flat.txt restored-repo --no-symlinks
145
+ ```
146
+
147
+ ## Inspect an Archive
148
+
149
+ ```bash
150
+ flat-inspect repo.flat.txt
151
+ flat-inspect repo.flat.txt --json
152
+ flat-inspect repo.flat.txt --limit 20
153
+ ```
154
+
155
+ Inspection validates the archive first, then reports version, compression,
156
+ source metadata, entry counts, total file bytes, chunk count, largest files, and
157
+ symlinks.
158
+
159
+ ## Safety Model
160
+
161
+ Flat Packager is intended for moving repository snapshots, not for executing or
162
+ trusting their contents. Treat archives from untrusted sources the same way you
163
+ would treat a zip file from an untrusted source.
164
+
165
+ The restore step rejects:
166
+
167
+ - absolute archive paths
168
+ - `..`, `.`, empty, or backslash path segments
169
+ - duplicate archive paths
170
+ - file or directory records nested underneath an archived symlink
171
+ - chunk records that are missing, out of order, corrupt, or attached to the
172
+ wrong file
173
+ - corrupt base64, size, or SHA-256 data
174
+
175
+ Restored symlinks may still point outside the restored repository, because that
176
+ is valid repository content. Use `--no-symlinks` if you want symlink targets
177
+ written as text files instead.
178
+
179
+ ## Limitations
180
+
181
+ - File contents are base64 encoded, so archives are larger than raw file bytes.
182
+ Use gzip compression when archive size matters.
183
+ - Legacy format version 1 stores each file as one JSON record and is
184
+ memory-heavy for large files. Version 2 is chunked and is the default.
185
+ - Remote GitHub packing depends on local `git` and whatever authentication your
186
+ git installation already has configured.
187
+ - Git LFS files are captured as whatever exists in the cloned checkout. If LFS
188
+ smudge is disabled or unavailable, pointer files may be archived instead of
189
+ large objects.
190
+ - This stores file bytes, directory modes, file modes, and symlink targets. It
191
+ does not preserve owners, groups, extended attributes, ACLs, hard links,
192
+ timestamps, git history, or ignored remote refs.
193
+
194
+ ## Test
195
+
196
+ ```bash
197
+ python3 -m unittest discover -s tests
198
+ ```
199
+
200
+ Build a wheel:
201
+
202
+ ```bash
203
+ python3 -m pip install ".[dev]"
204
+ python3 -m build
205
+ ```
206
+
207
+ ## Release
208
+
209
+ See [CHANGELOG.md](CHANGELOG.md) and [docs/RELEASING.md](docs/RELEASING.md).
210
+
211
+ ```bash
212
+ make release-check
213
+ ```
@@ -0,0 +1,52 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "flat-packager"
7
+ version = "0.4.0"
8
+ description = "Pack a repository into one flat text archive and restore it later."
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ license = "MIT"
12
+ license-files = ["LICENSE"]
13
+ authors = [
14
+ { name = "Thomas" }
15
+ ]
16
+ keywords = ["archive", "repository", "github", "packaging", "restore"]
17
+ classifiers = [
18
+ "Development Status :: 3 - Alpha",
19
+ "Environment :: Console",
20
+ "Intended Audience :: Developers",
21
+ "Programming Language :: Python :: 3",
22
+ "Programming Language :: Python :: 3 :: Only",
23
+ "Programming Language :: Python :: 3.10",
24
+ "Programming Language :: Python :: 3.11",
25
+ "Programming Language :: Python :: 3.12",
26
+ "Programming Language :: Python :: 3.13",
27
+ "Programming Language :: Python :: 3.14",
28
+ "Topic :: Software Development :: Version Control :: Git",
29
+ "Topic :: System :: Archiving",
30
+ ]
31
+ dependencies = []
32
+
33
+ [project.urls]
34
+ Homepage = "https://github.com/tomanizer/flat-packager"
35
+ Repository = "https://github.com/tomanizer/flat-packager"
36
+ Documentation = "https://github.com/tomanizer/flat-packager#readme"
37
+ Changelog = "https://github.com/tomanizer/flat-packager/blob/main/CHANGELOG.md"
38
+
39
+ [project.scripts]
40
+ flat-pack = "flat_packager.pack:main"
41
+ flat-unpack = "flat_packager.unpack:main"
42
+ flat-inspect = "flat_packager.inspect:main"
43
+ flat-verify = "flat_packager.verify:main"
44
+
45
+ [project.optional-dependencies]
46
+ dev = [
47
+ "build>=1.2",
48
+ "twine>=5.0",
49
+ ]
50
+
51
+ [tool.setuptools.packages.find]
52
+ where = ["src"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,25 @@
1
+ """Pack and restore repositories through a single flat text archive."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from flat_packager.inspect import inspect_data
6
+ from flat_packager.pack import build_archive, prepare_source
7
+ from flat_packager.unpack import (
8
+ ArchiveManifest,
9
+ load_and_validate_archive,
10
+ process_archive,
11
+ restore_archive,
12
+ )
13
+
14
+ __version__ = "0.4.0"
15
+
16
+ __all__ = [
17
+ "ArchiveManifest",
18
+ "__version__",
19
+ "build_archive",
20
+ "inspect_data",
21
+ "load_and_validate_archive",
22
+ "prepare_source",
23
+ "process_archive",
24
+ "restore_archive",
25
+ ]
@@ -0,0 +1,69 @@
1
+ """Shared archive constants and helpers."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import gzip
6
+ import json
7
+ from pathlib import Path
8
+ from typing import Any, Iterator, TextIO
9
+
10
+
11
+ ARCHIVE_KIND = "repo-flat-archive"
12
+ ARCHIVE_VERSION = 2
13
+ SUPPORTED_ARCHIVE_VERSIONS = {1, 2}
14
+ DEFAULT_CHUNK_SIZE = 1024 * 1024
15
+
16
+
17
+ def detect_archive_compression(path: Path) -> str:
18
+ try:
19
+ with path.open("rb") as handle:
20
+ if handle.read(2) == b"\x1f\x8b":
21
+ return "gzip"
22
+ except FileNotFoundError:
23
+ pass
24
+ return "none"
25
+
26
+
27
+ def should_compress(path: Path, compression: str) -> bool:
28
+ if compression == "gzip":
29
+ return True
30
+ if compression == "none":
31
+ return False
32
+ if compression == "auto":
33
+ return path.suffix == ".gz"
34
+ raise ValueError(f"unsupported compression mode: {compression}")
35
+
36
+
37
+ def open_archive_for_write(
38
+ path: Path,
39
+ compression: str = "auto",
40
+ ) -> TextIO:
41
+ if should_compress(path, compression):
42
+ return gzip.open(path, "wt", encoding="utf-8", newline="\n")
43
+ return path.open("w", encoding="utf-8", newline="\n")
44
+
45
+
46
+ def open_archive_for_read(path: Path) -> TextIO:
47
+ if detect_archive_compression(path) == "gzip":
48
+ return gzip.open(path, "rt", encoding="utf-8")
49
+ return path.open("r", encoding="utf-8")
50
+
51
+
52
+ def emit_json_line(handle: TextIO, payload: dict[str, object]) -> None:
53
+ handle.write(json.dumps(payload, sort_keys=True, separators=(",", ":")))
54
+ handle.write("\n")
55
+
56
+
57
+ def read_json_lines(archive_path: Path) -> Iterator[tuple[int, dict[str, Any]]]:
58
+ with open_archive_for_read(archive_path) as handle:
59
+ for line_number, line in enumerate(handle, start=1):
60
+ stripped = line.strip()
61
+ if not stripped:
62
+ continue
63
+ try:
64
+ payload = json.loads(stripped)
65
+ except json.JSONDecodeError as exc:
66
+ raise ValueError(f"line {line_number}: invalid JSON: {exc}") from exc
67
+ if not isinstance(payload, dict):
68
+ raise ValueError(f"line {line_number}: archive record must be an object")
69
+ yield line_number, payload