2626 LocalClient ,
2727 default_multicast_address ,
2828)
29- from infuse_iot .util .argparse import ValidRelease
29+ from infuse_iot .util .argparse import ValidFile , ValidRelease
3030
3131
3232class SubCommand (InfuseCommand ):
@@ -38,7 +38,7 @@ def __init__(self, args):
3838 self ._client = LocalClient (default_multicast_address (), 1.0 )
3939 self ._conn_timeout = args .conn_timeout
4040 self ._min_rssi : int | None = args .rssi
41- self ._single_id : int | None = args . id
41+ self ._explicit_ids : list [ int ] = []
4242 self ._release : ValidRelease = args .release
4343 self ._app_name = self ._release .metadata ["application" ]["primary" ]
4444 self ._app_id = self ._release .metadata ["application" ]["id" ]
@@ -63,17 +63,26 @@ def __init__(self, args):
6363 else :
6464 self ._log = open (args .log , "+a" , encoding = "utf-8" ) # noqa: SIM115
6565
66+ if args .id is not None :
67+ self ._explicit_ids .append (args .id )
68+ elif args .list is not None :
69+ with args .list .open ("r" ) as f :
70+ for line in f .readlines ():
71+ self ._explicit_ids .append (int (line .strip (), 0 ))
72+
6673 @classmethod
6774 def add_parser (cls , parser ):
6875 parser .add_argument (
6976 "--release" , "-r" , type = ValidRelease , required = True , help = "Application release to upgrade to"
7077 )
7178 parser .add_argument ("--rssi" , type = int , help = "Minimum RSSI to attempt upgrade process" )
72- parser .add_argument ("--id" , type = lambda x : int (x , 0 ), help = "Single device to upgrade" )
7379 parser .add_argument ("--log" , type = str , help = "File to write upgrade results to" )
7480 parser .add_argument (
7581 "--conn-timeout" , type = int , default = 10000 , help = "Timeout to wait for a connection to the device (ms)"
7682 )
83+ explicit = parser .add_mutually_exclusive_group ()
84+ explicit .add_argument ("--id" , type = lambda x : int (x , 0 ), help = "Single device to upgrade" )
85+ explicit .add_argument ("--list" , type = ValidFile , help = "File containing a list of IDs to upgrade" )
7786
7887 def progress_table (self ):
7988 table = Table ()
@@ -111,14 +120,16 @@ def run(self):
111120 with Live (self .progress_table (), refresh_per_second = 4 ) as live :
112121 for source , announce in self ._client .observe_announce ():
113122 self .state_update (live , "Scanning" )
114- if announce .application != self ._app_id and not self ._single_id :
115- continue
116- if self ._single_id :
117- if self ._single_id != source .infuse_id :
123+ if len (self ._explicit_ids ):
124+ if source .infuse_id not in self ._explicit_ids :
118125 continue
119- if self ._single_id in self ._handled :
120- # The one device we care about has been upgraded
126+ if len (self ._handled ) == len (self ._explicit_ids ):
127+ # We've handled all devices
128+ self .state_update (live , "All devices updated" )
121129 return
130+ else :
131+ if announce .application != self ._app_id :
132+ continue
122133 if source .infuse_id in self ._handled :
123134 continue
124135 v = announce .version
0 commit comments