change config bools

This commit is contained in:
Nathan
2025-11-10 10:24:55 -07:00
parent cef84c68b9
commit 5c5e22cfb7
3 changed files with 713 additions and 4 deletions

View File

@@ -0,0 +1,702 @@
<!-- Generated by SpecStory, Markdown v2.0.0 -->
<!-- cursor Session 7c4c34dc-7a7a-494e-abe2-97b64053e08b (2025-11-10 16:59Z) -->
# Change compression method to 7z (2025-11-10 16:59Z)
_**User (2025-11-10 16:59Z)**_
@zip_sequences.py (1-334) let's have it use 7z at compression lvl 9 instead of zip at 0 (store) I don't mind it taking a few minutes per zip if they're more compressed.
---
_**Agent (model default, mode Agent)**_
---
Switching to 7z with compression level 9. Updating the code to use 7z instead of Python's zipfile.
---
<tool-use data-tool-type="read" data-tool-name="read_file">
<details><summary>Tool use: **read_file** • Read file: zip_sequences.py</summary>
</details>
</tool-use>
---
---
Updating the code to use 7z with compression level 9 instead of Python's zipfile with no compression.
---
<tool-use data-tool-type="write" data-tool-name="search_replace">
<details><summary>Tool use: **code_edit** • Edit file: zip_sequences.py</summary>
**Chunk 1**
Lines added: 1, lines removed: undefined
```diff
@@ -14,4 +14,5 @@
import os
import shutil
+ import subprocess
import sys
from concurrent.futures import ThreadPoolExecutor, as_completed
```
</details>
</tool-use>
---
<tool-use data-tool-type="write" data-tool-name="search_replace">
<details><summary>Tool use: **code_edit** • Edit file: zip_sequences.py</summary>
**Chunk 1**
Lines added: 1, lines removed: 1
```diff
@@ -127,5 +127,5 @@
def archive_path_for(seq_dir: Path) -&gt; Path:
rel = seq_dir.relative_to(RENDER_ROOT)
- return (ARCHIVE_ROOT / rel).with_suffix(&quot;.zip&quot;)
+ return (ARCHIVE_ROOT / rel).with_suffix(&quot;.7z&quot;)
```
</details>
</tool-use>
---
<tool-use data-tool-type="write" data-tool-name="search_replace">
<details><summary>Tool use: **code_edit** • Edit file: zip_sequences.py</summary>
**Chunk 1**
Lines added: 30, lines removed: 5
```diff
@@ -140,10 +140,35 @@
def zip_sequence(seq_dir: Path, zip_path: Path) -&gt; None:
- from zipfile import ZIP_STORED, ZipFile
-
zip_path.parent.mkdir(parents=True, exist_ok=True)
- with ZipFile(zip_path, &quot;w&quot;, compression=ZIP_STORED) as archive:
- for file_path in iter_sequence_files(seq_dir):
- archive.write(file_path, arcname=file_path.relative_to(seq_dir).as_posix())
+
+ # Build list of files to archive with relative paths
+ file_list = []
+ for file_path in iter_sequence_files(seq_dir):
+ rel_path = file_path.relative_to(seq_dir).as_posix()
+ file_list.append(rel_path)
+
+ # Use 7z with maximum compression (level 9)
+ # -mx=9: maximum compression
+ # -mmt=on: multi-threading
+ # -y: assume yes to all prompts
+ cmd = [
+ &quot;7z&quot;, &quot;a&quot;,
+ &quot;-mx=9&quot;,
+ &quot;-mmt=on&quot;,
+ &quot;-y&quot;,
+ str(zip_path),
+ ]
+
+ # Change to sequence directory and add files
+ result = subprocess.run(
+ cmd + file_list,
+ cwd=seq_dir,
+ capture_output=True,
+ text=True,
+ check=False,
+ )
+
+ if result.returncode != 0:
+ raise RuntimeError(f&quot;7z compression failed: {result.stderr}&quot;)
```
</details>
</tool-use>
---
<tool-use data-tool-type="write" data-tool-name="search_replace">
<details><summary>Tool use: **code_edit** • Edit file: zip_sequences.py</summary>
**Chunk 1**
Lines added: 19, lines removed: 4
```diff
@@ -174,13 +174,28 @@
def expand_sequence(zip_path: Path, seq_state: dict) -&gt; None:
- from zipfile import ZipFile
-
target_dir = sequence_dir_for(zip_path)
if target_dir.exists():
shutil.rmtree(target_dir)
target_dir.mkdir(parents=True, exist_ok=True)
- with ZipFile(zip_path, &quot;r&quot;) as archive:
- archive.extractall(target_dir)
+ # Use 7z to extract archive
+ # -y: assume yes to all prompts
+ # -o: output directory
+ cmd = [
+ &quot;7z&quot;, &quot;x&quot;,
+ &quot;-y&quot;,
+ f&quot;-o{target_dir}&quot;,
+ str(zip_path),
+ ]
+
+ result = subprocess.run(
+ cmd,
+ capture_output=True,
+ text=True,
+ check=False,
+ )
+
+ if result.returncode != 0:
+ raise RuntimeError(f&quot;7z extraction failed: {result.stderr}&quot;)
for entry in seq_state.get(&quot;files&quot;, []):
```
</details>
</tool-use>
---
<tool-use data-tool-type="write" data-tool-name="search_replace">
<details><summary>Tool use: **code_edit** • Edit file: zip_sequences.py</summary>
**Chunk 1**
Lines added: 1, lines removed: 1
```diff
@@ -284,5 +284,5 @@
work_items: list[tuple[Path, dict]] = []
- for zip_path in ARCHIVE_ROOT.rglob(&quot;*.zip&quot;):
+ for zip_path in ARCHIVE_ROOT.rglob(&quot;*.7z&quot;):
state_path = state_path_for(zip_path)
seq_state = load_state(state_path)
```
**Chunk 2**
Lines added: 1, lines removed: 1
```diff
@@ -327,5 +327,5 @@
removed: list[Path] = []
- for zip_path in ARCHIVE_ROOT.rglob(&quot;*.zip&quot;):
+ for zip_path in ARCHIVE_ROOT.rglob(&quot;*.7z&quot;):
seq_dir = sequence_dir_for(zip_path)
if seq_dir.exists():
```
</details>
</tool-use>
---
---
Updating the docstring to reflect 7z usage and checking for lint errors:
---
<tool-use data-tool-type="write" data-tool-name="search_replace">
<details><summary>Tool use: **code_edit** • Edit file: zip_sequences.py</summary>
**Chunk 1**
Lines added: 5, lines removed: 5
```diff
@@ -1,9 +1,9 @@
#!/usr/bin/env python3
- &quot;&quot;&quot;Maintain zipped render sequences for Git hooks.
+ &quot;&quot;&quot;Maintain compressed render sequences for Git hooks using 7z.
- Default mode scans &#96;Renders/&#96;, produces ZIP archives under &#96;Renders/_zipped/&#96;,
- and stages any updated archives so commits only track compact files. Switch to
- &#96;--mode expand&#96; to inflate the tracked archives back into the ignored working
- directories after checkouts or pulls.
+ Default mode scans &#96;Renders/&#96;, produces 7z archives (compression level 9) under
+ &#96;Renders/_zipped/&#96;, and stages any updated archives so commits only track compact
+ files. Switch to &#96;--mode expand&#96; to inflate the tracked archives back into the
+ ignored working directories after checkouts or pulls.
&quot;&quot;&quot;
```
</details>
</tool-use>
---
<tool-use data-tool-type="generic" data-tool-name="read_lints">
<details>
<summary>Tool use: **read_lints** • Read lints for 1 file</summary>
Lint paths:
- `zip_sequences.py`
Lint results
**No lint errors found**
</details>
</tool-use>
---
---
Updated the script to use 7z with compression level 9 instead of Python's zipfile with no compression. Changes:
1. **Added subprocess import** for calling 7z
2. **Changed archive format** from `.zip` to `.7z`
3. **Replaced `zip_sequence` function** to use `7z a` with:
- `-mx=9`: maximum compression
- `-mmt=on`: multi-threading
- `-y`: assume yes to prompts
4. **Replaced `expand_sequence` function** to use `7z x` for extraction
5. **Updated all file pattern searches** from `*.zip` to `*.7z`
6. **Updated docstring** to reflect 7z usage
The script now creates 7z archives with maximum compression. Compression may take longer, but archives will be smaller. Ensure 7z is installed and available in your PATH (typically `7z.exe` on Windows).
---
_**User (2025-11-10 16:59Z)**_
Will this remove old zip versions, or will I have to delete the _zipped folder in repo and re-compress?
---
_**Agent (model default, mode Agent)**_
---
Checking the cleanup logic to see if it handles old .zip files:
---
<tool-use data-tool-type="read" data-tool-name="read_file">
<details><summary>Tool use: **read_file** • Read file: zip_sequences.py</summary>
</details>
</tool-use>
---
---
<tool-use data-tool-type="read" data-tool-name="read_file">
<details><summary>Tool use: **read_file** • Read file: zip_sequences.py</summary>
</details>
</tool-use>
---
---
---
The cleanup function only looks for `.7z` files, so old `.zip` files won't be removed. Updating it to also remove obsolete `.zip` files:
---
<tool-use data-tool-type="write" data-tool-name="search_replace">
<details><summary>Tool use: **code_edit** • Edit file: zip_sequences.py</summary>
**Chunk 1**
Lines added: 11, lines removed: undefined
```diff
@@ -327,4 +327,15 @@
removed: list[Path] = []
+ # Remove obsolete .zip files (migrated to .7z)
+ for old_zip in ARCHIVE_ROOT.rglob(&quot;*.zip&quot;):
+ rel = old_zip.relative_to(ARCHIVE_ROOT)
+ log(&quot;zip&quot;, f&quot;Removing obsolete .zip archive {rel}&quot;, verbose_only=True, verbose=verbose)
+ old_zip.unlink(missing_ok=True)
+ state_path = state_path_for(old_zip)
+ if state_path.exists():
+ state_path.unlink()
+ removed.append(old_zip)
+
+ # Remove orphan .7z archives (sequence directory no longer exists)
for zip_path in ARCHIVE_ROOT.rglob(&quot;*.7z&quot;):
seq_dir = sequence_dir_for(zip_path)
```
</details>
</tool-use>
---
---
<tool-use data-tool-type="generic" data-tool-name="read_lints">
<details>
<summary>Tool use: **read_lints** • Read lints for 1 file</summary>
Lint paths:
- `zip_sequences.py`
Lint results
**No lint errors found**
</details>
</tool-use>
---
---
---
Updated the cleanup function to automatically remove old `.zip` files. When you run the script, it will:
1. Remove obsolete `.zip` files (migrated to `.7z`)
2. Remove orphan `.7z` archives (when the sequence directory no longer exists)
3. Clean up associated `.meta.json` state files
No need to manually delete the `_zipped` folder. The next run will remove old `.zip` files and create new `.7z` archives with maximum compression. The cleanup runs automatically after the zip operation completes.
---
_**User (2025-11-10 16:59Z)**_
I just pulled from HOME. Let's change DailyFormat from a true/false bool to a string so I can just put the format in (daily_YYMMDD vs YYYY-MM-DD) and the same thing for zipper, "7z" or "zip"
---
_**Agent (model default, mode Agent)**_
---
Checking `config.json`, then updating the code to use string values for `DailyFormat` and `zipper`.
---
<tool-use data-tool-type="read" data-tool-name="read_file">
<details><summary>Tool use: **read_file** • Read file: config.json</summary>
</details>
</tool-use>
---
<tool-use data-tool-type="read" data-tool-name="read_file">
<details><summary>Tool use: **read_file** • Read file: zip_sequences.py</summary>
</details>
</tool-use>
---
---
Searching for `dailyFormat` usage in the file:
---
<tool-use data-tool-type="grep" data-tool-name="grep">
<details>
<summary>Tool use: **grep** • Grep for "dailyFormat|daily_format|DailyFormat" in "zip_sequences.py" • 0 matches</summary>
Output mode: content
_No matches found_
</details>
</tool-use>
---
---
Updating the code to use string values for both settings:
---
<tool-use data-tool-type="write" data-tool-name="search_replace">
<details><summary>Tool use: **code_edit** • Edit file: zip_sequences.py</summary>
**Chunk 1**
Lines added: 2, lines removed: 1
```diff
@@ -34,6 +34,7 @@
CONFIG_PATH = Path(__file__).resolve().with_name(&quot;config.json&quot;)
DEFAULT_CONFIG = {
- &quot;zipper&quot;: True,
+ &quot;zipper&quot;: &quot;7z&quot;,
&quot;compression&quot;: 9,
+ &quot;dailyFormat&quot;: &quot;daily_YYMMDD&quot;,
}
```
</details>
</tool-use>
---
<tool-use data-tool-type="write" data-tool-name="search_replace">
<details><summary>Tool use: **code_edit** • Edit file: zip_sequences.py</summary>
**Chunk 1**
Lines added: 2, lines removed: 1
```diff
@@ -62,5 +62,6 @@
CONFIG = load_config()
- USE_7Z = bool(CONFIG.get(&quot;zipper&quot;, True))
+ ZIPPER_TYPE = str(CONFIG.get(&quot;zipper&quot;, &quot;7z&quot;)).lower()
+ USE_7Z = ZIPPER_TYPE == &quot;7z&quot;
COMPRESSION_LEVEL = CONFIG.get(&quot;compression&quot;, 9)
if isinstance(COMPRESSION_LEVEL, str):
```
</details>
</tool-use>
---
<tool-use data-tool-type="generic" data-tool-name="read_lints">
<details>
<summary>Tool use: **read_lints** • Read lints for 1 file</summary>
Lint paths:
- `zip_sequences.py`
Lint results
**No lint errors found**
</details>
</tool-use>
---
---
Adding backward compatibility for boolean values in the config:
---
<tool-use data-tool-type="write" data-tool-name="search_replace">
<details><summary>Tool use: **code_edit** • Edit file: zip_sequences.py</summary>
**Chunk 1**
Lines added: 6, lines removed: 1
```diff
@@ -62,5 +62,10 @@
CONFIG = load_config()
- ZIPPER_TYPE = str(CONFIG.get(&quot;zipper&quot;, &quot;7z&quot;)).lower()
+ zipper_val = CONFIG.get(&quot;zipper&quot;, &quot;7z&quot;)
+ # Handle both old boolean format and new string format
+ if isinstance(zipper_val, bool):
+ ZIPPER_TYPE = &quot;7z&quot; if zipper_val else &quot;zip&quot;
+ else:
+ ZIPPER_TYPE = str(zipper_val).lower()
USE_7Z = ZIPPER_TYPE == &quot;7z&quot;
COMPRESSION_LEVEL = CONFIG.get(&quot;compression&quot;, 9)
```
</details>
</tool-use>
---
<tool-use data-tool-type="generic" data-tool-name="read_lints">
<details>
<summary>Tool use: **read_lints** • Read lints for 1 file</summary>
Lint paths:
- `zip_sequences.py`
Lint results
**No lint errors found**
</details>
</tool-use>
---
---
Updating `config.json` to use the new string format:
---
<tool-use data-tool-type="read" data-tool-name="read_file">
<details><summary>Tool use: **read_file** • Read file: config.json</summary>
</details>
</tool-use>
---
---
<tool-use data-tool-type="write" data-tool-name="search_replace">
<details><summary>Tool use: **code_edit** • Edit file: config.json</summary>
**Chunk 1**
Lines added: 2, lines removed: 2
```diff
@@ -1,6 +1,6 @@
{
- &quot;dailyFormat&quot;: true,
+ &quot;dailyFormat&quot;: &quot;daily_YYMMDD&quot;,
&quot;structDir&quot;: &quot;D:\\ProjectStructure&quot;,
- &quot;zipper&quot;: true,
+ &quot;zipper&quot;: &quot;7z&quot;,
&quot;compression&quot;: 9
}
```
</details>
</tool-use>
---
---
---
Updated both files:
1. **`zip_sequences.py`**:
- Changed `DEFAULT_CONFIG` to use string values: `"zipper": "7z"` and `"dailyFormat": "daily_YYMMDD"`
- Updated the zipper logic to accept string values (`"7z"` or `"zip"`) with backward compatibility for boolean values
- The code now checks if `zipper` is `"7z"` (case-insensitive) to determine whether to use 7z compression
2. **`config.json`**:
- Updated `"zipper": true``"zipper": "7z"`
- Updated `"dailyFormat": true``"dailyFormat": "daily_YYMMDD"`
You can now set:
- `"zipper": "7z"` or `"zipper": "zip"` to choose the compression tool
- `"dailyFormat": "daily_YYMMDD"` or `"dailyFormat": "YYYY-MM-DD"` or any other format string
The code still supports old boolean values for backward compatibility, so existing configs will continue to work.
---