26
26
import subprocess
27
27
import threading
28
28
import typing
29
- from optparse import OptionParser
29
+ import argparse
30
30
from colorama import Fore , Style
31
31
from java .base import DumpProgramOutputToQueue
32
32
@@ -37,77 +37,30 @@ def __init__(self, thread_list: typing.List[threading.Thread], queue: queue.Queu
37
37
self .queue = queue
38
38
self .command = cmd
39
39
40
- optParser = OptionParser ()
41
- optParser .add_option (
42
- "-t" ,
43
- "--timeout" ,
44
- action = "store" ,
45
- dest = "testTimeout" ,
46
- default = '200' ,
47
- type = 'str' ,
48
- help = "The program will return with timeout after specified seconds." ,
49
- metavar = "<timeout-second>" ,
50
- )
51
- optParser .add_option (
52
- "-a" ,
53
- "--address" ,
54
- action = "store" ,
55
- dest = "deviceAddress" ,
56
- default = '' ,
57
- type = 'str' ,
58
- help = "Address of the device" ,
59
- metavar = "<device-addr>" ,
60
- )
61
- optParser .add_option (
62
- "--setup-payload" ,
63
- action = "store" ,
64
- dest = "setupPayload" ,
65
- default = '' ,
66
- type = 'str' ,
67
- help = "Setup Payload (manual pairing code or QR code content)" ,
68
- metavar = "<setup-payload>"
69
- )
70
- optParser .add_option (
71
- "--nodeid" ,
72
- action = "store" ,
73
- dest = "nodeid" ,
74
- default = '1' ,
75
- type = 'str' ,
76
- help = "The Node ID issued to the device" ,
77
- metavar = "<nodeid>"
78
- )
79
- optParser .add_option (
80
- "--discriminator" ,
81
- action = "store" ,
82
- dest = "discriminator" ,
83
- default = '3840' ,
84
- type = 'str' ,
85
- help = "Discriminator of the device" ,
86
- metavar = "<nodeid>"
87
- )
88
- optParser .add_option (
89
- "-p" ,
90
- "--paa-trust-store-path" ,
91
- action = "store" ,
92
- dest = "paaTrustStorePath" ,
93
- default = '' ,
94
- type = 'str' ,
95
- help = "Path that contains valid and trusted PAA Root Certificates." ,
96
- metavar = "<paa-trust-store-path>"
97
- )
40
+ parser = argparse .ArgumentParser (description = 'Process pairing arguments.' )
98
41
99
- (options , remainingArgs ) = optParser .parse_args (args .split ())
42
+ parser .add_argument ('command' , help = "Command name" )
43
+ parser .add_argument ('-t' , '--timeout' , help = "The program will return with timeout after specified seconds" , default = '200' )
44
+ parser .add_argument ('-a' , '--address' , help = "Address of the device" )
45
+ parser .add_argument ('-s' , '--setup-payload' , dest = 'setup_payload' ,
46
+ help = "Setup Payload (manual pairing code or QR code content)" )
47
+ parser .add_argument ('-n' , '--nodeid' , help = "The Node ID issued to the device" , default = '1' )
48
+ parser .add_argument ('-d' , '--discriminator' , help = "Discriminator of the device" , default = '3840' )
49
+ parser .add_argument ('-p' , '--paa-trust-store-path' , dest = 'paa_trust_store_path' ,
50
+ help = "Path that contains valid and trusted PAA Root Certificates" )
100
51
101
- self .nodeid = options .nodeid
102
- self .setupPayload = options .setupPayload
103
- self .discriminator = options .discriminator
104
- self .testTimeout = options .testTimeout
52
+ args = parser .parse_args (args .split ())
53
+
54
+ self .command_name = args .command
55
+ self .nodeid = args .nodeid
56
+ self .setup_payload = args .setup_payload
57
+ self .discriminator = args .discriminator
58
+ self .timeout = args .timeout
105
59
106
60
logging .basicConfig (level = logging .INFO )
107
61
108
62
def TestOnnetworkLong (self , nodeid , setuppin , discriminator , timeout ):
109
63
java_command = self .command + ['pairing' , 'onnetwork-long' , nodeid , setuppin , discriminator , timeout ]
110
- print (java_command )
111
64
logging .info (f"Execute: { java_command } " )
112
65
java_process = subprocess .Popen (
113
66
java_command , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
@@ -116,10 +69,11 @@ def TestOnnetworkLong(self, nodeid, setuppin, discriminator, timeout):
116
69
117
70
def RunTest (self ):
118
71
logging .info ("Testing onnetwork-long pairing" )
119
- java_exit_code = self .TestOnnetworkLong (self .nodeid , self .setupPayload , self .discriminator , self .testTimeout )
120
- if java_exit_code != 0 :
121
- logging .error ("Testing onnetwork-long pairing failed with error %r" % java_exit_code )
122
- return java_exit_code
72
+ if self .command_name == 'onnetwork-long' :
73
+ java_exit_code = self .TestOnnetworkLong (self .nodeid , self .setup_payload , self .discriminator , self .timeout )
74
+ if java_exit_code != 0 :
75
+ logging .error ("Testing onnetwork-long pairing failed with error %r" % java_exit_code )
76
+ return java_exit_code
123
77
124
78
# Testing complete without errors
125
79
return 0
0 commit comments