Skip to content

Commit 9bfb796

Browse files
committed
added console script
1 parent 90fdfc6 commit 9bfb796

File tree

3 files changed

+54
-43
lines changed

3 files changed

+54
-43
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ Almost all the functionality of the standard library is implemented. Some featur
4343

4444
## usage
4545
```
46-
usage: python -m python_hackrf [-h] {info, sweep} ...
46+
usage: python_hackrf [-h] {info, sweep} ...
4747
4848
python_hackrf is a Python wrapper for libhackrf and hackrf-tools.
4949
@@ -56,15 +56,15 @@ Available commands:
5656
sweep a command-line spectrum analyzer.
5757
```
5858
```
59-
usage: python -m python_hackrf info [-h] [-f] [-s]
59+
usage: python_hackrf info [-h] [-f] [-s]
6060
6161
options:
6262
-h, --help show this help message and exit
6363
-f, --full show info like in hackrf_info
6464
-s, --serial_numbers show only founded serial_numbers
6565
```
6666
```
67-
usage: python -m python_hackrf sweep [-h] [-d] [-a] [-f] [-p] [-l] [-g] [-w] [-1] [-N] [-B] [-s] [-SR] [-BF] [-r]
67+
usage: python_hackrf sweep [-h] [-d] [-a] [-f] [-p] [-l] [-g] [-w] [-1] [-N] [-B] [-s] [-SR] [-BF] [-r]
6868
6969
options:
7070
-h, --help show this help message and exit

pyproject.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "python_hackrf"
3-
version = "1.0.6"
3+
version = "1.0.7"
44
authors = [
55
{name="Leonid Gvozdev", email="[email protected]"},
66
]
@@ -24,4 +24,7 @@ requires = [
2424
"setuptools",
2525
"wheel",
2626
"numpy"
27-
]
27+
]
28+
29+
[project.scripts]
30+
python_hackrf= "python_hackrf.__main__:main"

python_hackrf/__main__.py

Lines changed: 46 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
from .pylibhackrf import pyhackrf
33
import argparse
44

5-
if __name__ == '__main__':
5+
6+
def main():
67
parser = argparse.ArgumentParser(
78
description="python_hackrf is a Python wrapper for libhackrf and hackrf-tools.",
89
usage="python -m python_hackrf [-h] {info, sweep} ..."
@@ -34,42 +35,49 @@
3435
pyhackrf_sweep_parser.add_argument('-r', action='store', help='filename. output file', metavar='')
3536
args, unparsed_args = parser.parse_known_args()
3637

37-
if args.command == 'info':
38-
if args.serial_numbers:
39-
pyhackrf_info.pyhackrf_serial_numbers_list_info()
40-
else:
41-
pyhackrf_info.pyhackrf_info()
38+
if not hasattr(args, 'command'):
39+
parser.print_help()
40+
else:
41+
if args.command == 'info':
42+
if args.serial_numbers:
43+
pyhackrf_info.pyhackrf_serial_numbers_list_info()
44+
else:
45+
pyhackrf_info.pyhackrf_info()
46+
47+
if args.command == 'sweep':
48+
str_frequencies = args.f.split(',')
49+
frequencies = []
50+
for frequency_range in str_frequencies:
51+
frequency_range = frequency_range.split(':')
52+
freq_min, freq_max = None, None
53+
try:
54+
freq_min = int(frequency_range[0])
55+
except Exception:
56+
pass
57+
try:
58+
freq_max = int(frequency_range[1])
59+
except Exception:
60+
pass
61+
if freq_min is not None and freq_max is not None:
62+
frequencies.extend([freq_min, freq_max])
4263

43-
if args.command == 'sweep':
44-
str_frequencies = args.f.split(',')
45-
frequencies = []
46-
for frequency_range in str_frequencies:
47-
frequency_range = frequency_range.split(':')
48-
freq_min, freq_max = None, None
49-
try:
50-
freq_min = int(frequency_range[0])
51-
except Exception:
52-
pass
53-
try:
54-
freq_max = int(frequency_range[1])
55-
except Exception:
56-
pass
57-
if freq_min is not None and freq_max is not None:
58-
frequencies.extend([freq_min, freq_max])
64+
pyhackrf_sweep.pyhackrf_sweep(frequencies=frequencies,
65+
lna_gain=int(args.l),
66+
vga_gain=int(args.g),
67+
bin_width=int(args.w),
68+
serial_number=args.d,
69+
amp_enable=args.a,
70+
antenna_enable=args.p,
71+
num_sweeps=int(args.N) if args.N is not None else None,
72+
binary_output=args.B,
73+
one_shot=args.__dict__.get('1'),
74+
filename=args.r,
75+
sweep_style=pyhackrf.py_sweep_style.LINEAR if args.s == 'L' else pyhackrf.py_sweep_style.INTERLEAVED,
76+
sample_rate=int(args.SR) * 1e6,
77+
baseband_filter=float(args.BF) * 1e6,
78+
print_to_console=True,
79+
)
5980

60-
pyhackrf_sweep.pyhackrf_sweep(frequencies=frequencies,
61-
lna_gain=int(args.l),
62-
vga_gain=int(args.g),
63-
bin_width=int(args.w),
64-
serial_number=args.d,
65-
amp_enable=args.a,
66-
antenna_enable=args.p,
67-
num_sweeps=int(args.N) if args.N is not None else None,
68-
binary_output=args.B,
69-
one_shot=args.__dict__.get('1'),
70-
filename=args.r,
71-
sweep_style=pyhackrf.py_sweep_style.LINEAR if args.s == 'L' else pyhackrf.py_sweep_style.INTERLEAVED,
72-
sample_rate=int(args.SR) * 1e6,
73-
baseband_filter=float(args.BF) * 1e6,
74-
print_to_console=True,
75-
)
81+
82+
if __name__ == '__main__':
83+
main()

0 commit comments

Comments
 (0)