Skip to content

Commit d212c41

Browse files
committed
ensure for NCD conversion that both input & output are in same folder
1 parent f2a096c commit d212c41

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

sigmf/convert/__init__.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ def main() -> None:
2020
Unified entry-point for SigMF conversion of non-SigMF files.
2121
"""
2222
parser = argparse.ArgumentParser(description="Convert non-SigMF files to SigMF format")
23-
parser.add_argument("-i", "--input", type=str, required=True, help="Input file path")
24-
parser.add_argument("-o", "--output", type=str, default=None, help="Output SigMF path")
23+
parser.add_argument("input", type=str, help="Input file path")
24+
parser.add_argument("output", type=str, help="Output SigMF path (no extension)")
2525
parser.add_argument("-v", "--verbose", action="count", default=0)
2626
parser.add_argument(
2727
"-a", "--archive", action="store_true", help="Save as SigMF archive instead of separate meta/data files."
@@ -40,6 +40,14 @@ def main() -> None:
4040
logging.basicConfig(level=level_lut[min(args.verbose, 2)])
4141

4242
input_path = Path(args.input)
43+
output_path = Path(args.output)
44+
45+
# validate that ncd files are in same directory as input
46+
if args.ncd and input_path.parent.resolve() != output_path.parent.resolve():
47+
raise SigMFConversionError(
48+
f"NCD files must be in the same directory as input file. "
49+
f"Input: {input_path.parent.resolve()}, Output: {output_path.parent.resolve()}"
50+
)
4351

4452
# detect file type using magic bytes (same logic as fromfile())
4553
magic_bytes = get_magic_bytes(input_path, count=4, offset=0)
@@ -48,13 +56,13 @@ def main() -> None:
4856
# WAV file
4957
from .wav import wav_to_sigmf
5058

51-
_ = wav_to_sigmf(wav_path=input_path, out_path=args.output, create_archive=args.archive, create_ncd=args.ncd)
59+
_ = wav_to_sigmf(wav_path=input_path, out_path=output_path, create_archive=args.archive, create_ncd=args.ncd)
5260

5361
elif magic_bytes == b"BLUE":
5462
# BLUE file
5563
from .blue import blue_to_sigmf
5664

57-
_ = blue_to_sigmf(blue_path=input_path, out_path=args.output, create_archive=args.archive, create_ncd=args.ncd)
65+
_ = blue_to_sigmf(blue_path=input_path, out_path=output_path, create_archive=args.archive, create_ncd=args.ncd)
5866

5967
else:
6068
raise SigMFConversionError(

0 commit comments

Comments
 (0)