Py_sax2sab/sab2sax.py
arda.aydin@ontrol.com.tr dd7b586ea0 Drop testprogram/ from the repo, show version in dialog titles
testprogram/ is local test data, not part of the tool: untracked and
gitignored so it never comes back. verify.py now prints SKIP and exits 0
when the test pair is absent instead of blowing up.

Adds config.NAME / config.VERSION (sab2sax 0.0.0.001). Every dialog title
bar goes through config.title(), and the CLI prints the same line at
startup, so it is clear which build produced a file.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-12 22:08:20 +03:00

67 lines
2.4 KiB
Python

"""Entry point: converts either direction, the way `sedonac.exe <file>` does --
the input's extension decides.
python sab2sax.py [in.sax|in.sab] [out]
.sax in -> .sab out (sab.encode)
.sab in -> .sax out (sax.decode)
Omit the input and a file chooser opens; omit the output and a save dialog opens
next to the input, pre-filled with a timestamped name. Sedona home comes from
system.properties (see config.py).
"""
import os, sys
import config, sab, sax
def convert(in_path, out_path=None, home=None):
"""Convert `in_path` by extension, no dialogs. Returns (out_path, bytes written).
With no `out_path`, writes a timestamped name next to the input."""
ext = os.path.splitext(in_path)[1].lower()
if ext not in (".sax", ".sab"):
raise Exception("don't know what to do with %s -- expected .sax or .sab" % in_path)
if out_path is None:
name = sab.default_sab_name(in_path) if ext == ".sax" else sax.default_sax_name(in_path)
out_path = os.path.join(os.path.dirname(os.path.abspath(in_path)), name)
if ext == ".sax":
return out_path, sab.encode(in_path, home, out_path)
return out_path, sax.decode(in_path, home, out_path)
def main(argv):
print("%s %s" % (config.NAME, config.VERSION))
home = config.get_sedona_home()
in_path = argv[1] if len(argv) > 1 else config.choose_input_file()
if not in_path:
raise SystemExit("no input file selected")
in_path = os.path.abspath(in_path)
if not os.path.isfile(in_path):
raise SystemExit("no such file: " + in_path)
ext = os.path.splitext(in_path)[1].lower()
if ext not in (".sax", ".sab"):
raise SystemExit("don't know what to do with %s -- expected .sax or .sab" % in_path)
if len(argv) > 2:
out_path = argv[2]
elif ext == ".sax":
out_path = config.choose_sab_file(initialfile=sab.default_sab_name(in_path),
initial=os.path.dirname(in_path))
else:
out_path = config.choose_sax_output(initialfile=sax.default_sax_name(in_path),
initial=os.path.dirname(in_path))
if not out_path:
raise SystemExit("no output file selected")
if ext == ".sax":
n = sab.encode(in_path, home, out_path)
else:
n = sax.decode(in_path, home, out_path)
print("wrote %d bytes to %s" % (n, out_path))
if __name__ == "__main__":
main(sys.argv)