Skip to content

Commit

Permalink
Rewrite the runner in python
Browse files Browse the repository at this point in the history
  • Loading branch information
mitiko committed Mar 3, 2024
1 parent f985f42 commit 0a77608
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 18 deletions.
15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# weath3rb0i - lightweight CM text compressor

weath3rb0i is a CM single-file text compressor aimed at delivering high
compression ratios with novel modeling approaches.
weath3rb0i is an experimental CM single-file text compressor aimed at delivering
high compression ratios with novel modeling approaches.

The goal for v1.0:
- 12-bit state table
Expand All @@ -16,12 +16,21 @@ Wishing to futher experiment with:

## Usage

`weath3rb0i <Action> <Path>`
The main binary is WIP but there are many test-only scenarios you can execute
with:

`./run.py <binary> <...options>`

<!-- Main binary: -->
<!--
`weath3rb0i <Action> <Path>`
**Action**: c (compress), d (decompress), t (test = c + d)
**Path** can be a single file or a directory
Directories are shallow traversed and each file is compressed individually
-->

## License

GPLv3.0

Please contact me [@x_mitiko](https://twitter.com/x_mitiko) if you need a copy under a different license.
53 changes: 53 additions & 0 deletions run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env python3

import argparse
import subprocess
from os import environ as env

parser = argparse.ArgumentParser(
prog="weath3rb0i",
description="The weath3rb0i binary executor",
epilog="Run `cargo run` for the default",
)

binaries = [
"weath3rb0i",
"order0",
"ac-over-huffman",
]

# Add all parameters globally but only use the ones we require per binary (no checks for extra args)
parser.add_argument("bin", type=int, nargs="?", help="Which binary (by id) to run")
parser.add_argument(
"-r", "--release", action="store_true", help="Whether to compile in release mode"
)
parser.add_argument("-q", "--quiet", action="store_true", help="Hide compiler info")
parser.add_argument("--hsize", type=int, help="Max code length for Huffman tree")

args = parser.parse_args()
while args.bin is None or args.bin >= len(binaries):
for i, binary in enumerate(binaries[1:]):
print(f"{i+1}) {binary}")

try:
args.bin = int(input("Select binary to run: "))
except ValueError:
continue

binary = binaries[args.bin]
cmd = ["cargo", "run"]

if args.quiet:
cmd.append("--quiet")
if args.release:
cmd.append("--release")

cmd.extend(["--bin", binary, "--"])

if "FILE" in env:
cmd.append(env["FILE"])

if "DEBUG" in env:
print('(dbg) Command:', cmd)

subprocess.run(cmd)
15 changes: 0 additions & 15 deletions run.sh

This file was deleted.

0 comments on commit 0a77608

Please sign in to comment.