File tree Expand file tree Collapse file tree 9 files changed +78
-92
lines changed Expand file tree Collapse file tree 9 files changed +78
-92
lines changed Original file line number Diff line number Diff line change 33from click_extra import extra_command
44
55from ..utils import (
6- com_baud_option ,
7- com_timeout_option ,
6+ com_option_group ,
87 com_port_argument
98)
109
1514 context_settings = {"auto_envvar_prefix" : None }
1615) # type: ignore[misc]
1716@com_port_argument ()
18- @com_baud_option ()
19- @com_timeout_option ()
17+ @com_option_group ()
2018def cli (** kwargs : Any ) -> None :
2119 """Test the availability of various GeoCom protocol functions on an
2220 instrument."""
Original file line number Diff line number Diff line change @@ -58,13 +58,17 @@ def tests(tps: GeoCom) -> None:
5858def main (
5959 port : str ,
6060 baud : int = 9600 ,
61- timeout : int = 15
61+ timeout : int = 15 ,
62+ retry : int = 1 ,
63+ sync_after_timeout : bool = False
6264) -> None :
6365 try :
6466 with open_serial (
6567 port ,
6668 speed = baud ,
67- timeout = timeout
69+ timeout = timeout ,
70+ retry = retry ,
71+ sync_after_timeout = sync_after_timeout
6872 ) as com :
6973 tps = GeoCom (com )
7074 tests (tps )
Original file line number Diff line number Diff line change 44 extra_command ,
55 argument ,
66 option ,
7- option_group ,
87 IntRange ,
98 File ,
109 file_path
1110)
1211
1312from ..utils import (
14- com_baud_option ,
15- com_timeout_option ,
13+ com_option_group ,
1614 com_port_argument
1715)
1816
2321 context_settings = {"auto_envvar_prefix" : None }
2422) # type: ignore[misc]
2523@com_port_argument ()
26- @option_group (
27- "Connection options" ,
28- "" ,
29- com_baud_option (),
30- com_timeout_option ()
31- )
24+ @com_option_group ()
3225@option (
3326 "-o" ,
3427 "--output" ,
Original file line number Diff line number Diff line change @@ -56,16 +56,17 @@ def main_measure(
5656 port : str ,
5757 baud : int = 9600 ,
5858 timeout : int = 15 ,
59+ retry : int = 1 ,
60+ sync_after_timeout : bool = False ,
5961 output : TextIOWrapper | None = None ,
6062 positions : int = 1 ,
6163 zero : bool = False ,
6264 cycles : int = 1
6365) -> None :
64-
6566 with open_serial (
6667 port ,
67- retry = 2 ,
68- sync_after_timeout = True ,
68+ retry = retry ,
69+ sync_after_timeout = sync_after_timeout ,
6970 speed = baud ,
7071 timeout = timeout
7172 ) as com :
Original file line number Diff line number Diff line change 33from click_extra import (
44 extra_command ,
55 option ,
6- option_group ,
76 argument ,
87 Choice ,
98 IntRange
109)
1110
1211from ..utils import (
13- com_baud_option ,
14- com_timeout_option ,
12+ com_option_group ,
1513 com_port_argument
1614)
1715
5351 help = "suppress encoding errors and skip non-ASCII characters" ,
5452 is_flag = True
5553)
56- @option_group (
57- "Connection options" ,
58- "Options related to the serial connection" ,
59- com_baud_option (),
60- com_timeout_option ()
61- )
54+ @com_option_group ()
6255def cli (** kwargs : Any ) -> None :
6356 """Play a Morse encoded ASCII message through the beep signals
6457 of a GeoCom capable total station.
Original file line number Diff line number Diff line change @@ -124,6 +124,8 @@ def main(
124124 ignore_non_ascii : bool = False ,
125125 baud : int = 9600 ,
126126 timeout : int = 15 ,
127+ retry : int = 1 ,
128+ sync_after_timeout : bool = False ,
127129 unittime : int = 50 ,
128130 compatibility : str = "none" ,
129131) -> None :
@@ -134,7 +136,13 @@ def main(
134136 echo_red ("The message contains non-ASCII characters." )
135137 exit (1 )
136138
137- with open_serial (port , speed = baud , timeout = timeout ) as com :
139+ with open_serial (
140+ port ,
141+ speed = baud ,
142+ timeout = timeout ,
143+ retry = retry ,
144+ sync_after_timeout = sync_after_timeout
145+ ) as com :
138146 tps = GeoCom (com )
139147 beepstart = tps .bmm .beep_start
140148 beepstop = tps .bmm .beep_stop
Original file line number Diff line number Diff line change 44 extra_command ,
55 argument ,
66 option ,
7- option_group ,
87 Choice ,
98 IntRange ,
109 file_path ,
1110 dir_path
1211)
13- from cloup .constraints import mutually_exclusive
1412
1513from ..utils import (
16- com_baud_option ,
17- com_timeout_option ,
14+ com_option_group ,
15+ logging_option_group ,
1816 com_port_argument
1917)
2018
3533 type = dir_path (),
3634 help = "directory to save measurement output to"
3735)
38- @option_group (
39- "Connection options" ,
40- "Options related to the serial connection" ,
41- com_baud_option (),
42- com_timeout_option (),
43- option (
44- "-r" ,
45- "--retry" ,
46- help = "number of connection retry attempts" ,
47- type = IntRange (min = 0 , max = 10 ),
48- default = 1
49- ),
50- option (
51- "--sync-after-timeout" ,
52- help = "attempt to synchronize message que after a connection timeout" ,
53- is_flag = True
54- )
55- )
36+ @com_option_group ()
5637@option (
5738 "-f" ,
5839 "--format" ,
9374 ),
9475 default = ""
9576)
96- @option_group (
97- "Logging options" ,
98- "Options related to the logging functionalities." ,
99- option (
100- "--debug" ,
101- is_flag = True
102- ),
103- option (
104- "--info" ,
105- is_flag = True
106- ),
107- option (
108- "--warning" ,
109- is_flag = True
110- ),
111- option (
112- "--error" ,
113- is_flag = True
114- ),
115- constraint = mutually_exclusive
116- )
77+ @logging_option_group ()
11778def cli_measure (** kwargs : Any ) -> None :
11879 """Run sets of measurements to predefined targets."""
11980 from .measure import main
Original file line number Diff line number Diff line change 44 extra_command ,
55 argument ,
66 option ,
7- option_group ,
87 IntRange ,
98 Choice
109)
1110
1211from ..utils import (
13- com_baud_option ,
14- com_timeout_option ,
12+ com_option_group ,
1513 com_port_argument
1614)
1715
3028 ),
3129 type = str
3230)
33- @option_group (
34- "Connection options" ,
35- "Options related to the serial connection" ,
36- com_baud_option (),
37- com_timeout_option (),
38- option (
39- "-r" ,
40- "--retry" ,
41- help = "number of connection retry attempts" ,
42- type = IntRange (min = 0 , max = 10 ),
43- default = 1
44- ),
45- option (
46- "--sync-after-timeout" ,
47- help = "attempt to synchronize message que after a connection timeout" ,
48- is_flag = True
49- )
50- )
31+ @com_option_group ()
5132def cli_measure (** kwargs : Any ) -> None :
5233 """Measure target points.
5334
Original file line number Diff line number Diff line change 77 echo ,
88 style ,
99 option ,
10+ option_group ,
1011 argument ,
1112 Choice ,
1213 IntRange
1314)
15+ from cloup .constraints import mutually_exclusive
1416
1517
1618F = TypeVar ('F' , bound = Callable [..., Any ])
@@ -75,6 +77,51 @@ def com_baud_option() -> Callable[[F], F]:
7577 )
7678
7779
80+ def com_option_group () -> Callable [[F ], F ]:
81+ return option_group (
82+ "Connection options" ,
83+ "Options related to the serial connection" ,
84+ com_baud_option (),
85+ com_timeout_option (),
86+ option (
87+ "-r" ,
88+ "--retry" ,
89+ help = "number of connection retry attempts" ,
90+ type = IntRange (min = 0 , max = 10 ),
91+ default = 1
92+ ),
93+ option (
94+ "--sync-after-timeout" ,
95+ help = "attempt to synchronize message que after a timeout" ,
96+ is_flag = True
97+ )
98+ )
99+
100+
101+ def logging_option_group () -> Callable [[F ], F ]:
102+ return option_group (
103+ "Logging options" ,
104+ "Options related to the logging functionalities." ,
105+ option (
106+ "--debug" ,
107+ is_flag = True
108+ ),
109+ option (
110+ "--info" ,
111+ is_flag = True
112+ ),
113+ option (
114+ "--warning" ,
115+ is_flag = True
116+ ),
117+ option (
118+ "--error" ,
119+ is_flag = True
120+ ),
121+ constraint = mutually_exclusive
122+ )
123+
124+
78125def echo_color (
79126 message : Any ,
80127 color : str ,
You can’t perform that action at this time.
0 commit comments