@@ -180,13 +180,13 @@ class AppendDestination(DataframeAction):
180
180
assume convention on naming
181
181
TODO check if it's ok with FilterDest
182
182
"""
183
-
184
183
def __init__ (self , * args , ** kwargs ) -> None :
185
184
self .already_called = False
186
- # self.destinations = list(ConnectionRoles)
185
+ self .destinations = list (ConnectionRoles )
187
186
# default=list(ConnectionRoles),
188
187
super ().__init__ (
189
- * args , choices = CustomConnectionRolesChoices ([e .name for e in ConnectionRoles ]),
188
+ * args ,
189
+ choices = CustomConnectionRolesChoices ([e .name for e in ConnectionRoles ]),
190
190
default = list (ConnectionRoles ), ** kwargs )
191
191
192
192
@@ -198,11 +198,17 @@ def __call__(self, parser, namespace, values, option_string=None):
198
198
# TODO change the default ?
199
199
# setattr(namespace, self.dest, [])
200
200
print ("Already set" )
201
+ print ("setting value %r" % values )
202
+ # print("setting value %r" % self.destinations)
201
203
# to make it unique
202
- self .destinations = list (set (self .destinations .append (values )))
204
+ self .destinations .append (values )
205
+ self .destinations = list (set (self .destinations ))
206
+ print ("new result %r" % self .destinations )
203
207
else :
204
- self .destinations = values
208
+ print ("Received first value %s" % values )
209
+ self .destinations = [values ]
205
210
211
+ self .already_called = True
206
212
# df_name + "destinations"
207
213
setattr (namespace , self .dest , self .destinations )
208
214
# pcap1 = getattr(namespace, self.df_name + "1")
@@ -332,11 +338,11 @@ def __init__(self, df_name: str, **kwargs) -> None:
332
338
333
339
# assert self.field == "tcpdest" or self.field == "mptcpdest"
334
340
# self.mptcp = mptcp
335
- # self.seen
341
+ # self.seen
336
342
# init with all destinations
337
343
self .destinations = list (ConnectionRoles )
338
344
self .already_called = False
339
- # TODO it could set choices automatically
345
+ # TODO it could set choices automatically
340
346
super ().__init__ (df_name , ** kwargs )
341
347
342
348
def __call__ (self , parser , namespace , values , option_string = None ):
@@ -454,6 +460,41 @@ def gen_bicap_parser(protocol, dest=False):
454
460
# protocol=protocol,
455
461
return gen_pcap_parser (input_pcaps = input_pcaps , direction = dest )
456
462
463
+ # argparse_completer.ACArgumentParser
464
+ class MpTcpAnalyzerParser (argparse_completer .ACArgumentParser ):
465
+ '''
466
+ Wrapper around cmd2 argparse completer
467
+ Should allow to switch backends easily.
468
+ Also allows to do some postprocessing once the arguments are parsed
469
+ like loading dataframes etc
470
+
471
+ '''
472
+
473
+ # def _parse_known_args(self, arg_strings, namespace):
474
+ def parse_known_args (self , args = None , namespace = None ):
475
+ """
476
+ override it just to postprocess arguments
477
+ """
478
+
479
+ # returns a 2-item tuple
480
+ known , unknown = super ().parse_known_args (args , namespace )
481
+ # print("res", res)
482
+
483
+ # TODO call filter_dataframe ?
484
+ if getattr (known , "_dataframes" , None ):
485
+ for name , df in known ._dataframes .items ():
486
+ # print
487
+ # so now we can filter the destination ?
488
+ log .debug ("dataframe [%s] in namespace" % name )
489
+ else :
490
+ log .debug ("No dataframe in namespace" )
491
+
492
+ # postprocessing for filtering destination
493
+
494
+ log .debug ("MpTcpAnalyzerParser parser finished" )
495
+ # TODO pass along known, dataframes ?
496
+ return (known , unknown )
497
+
457
498
458
499
# map pcaps to a group
459
500
def gen_pcap_parser (
@@ -464,7 +505,7 @@ def gen_pcap_parser(
464
505
parents = [],
465
506
# TODO get rid of this/skip-stream
466
507
skip_subflows : bool = True ,
467
- ) -> argparse_completer . ACArgumentParser :
508
+ ) -> MpTcpAnalyzerParser :
468
509
"""
469
510
Generates a parser with common options.
470
511
This parser can be completed or overridden by its children.
@@ -543,6 +584,7 @@ def _pcap(name, pcapAction="store", filterAction="store"):
543
584
# choices=CustomConnectionRolesChoices([e.name for e in ConnectionRoles]),
544
585
# TODO check how it works/FilterDest
545
586
action = partial (AppendDestination , df_name ),
587
+ # action=partial(AppendDestination, df_name),
546
588
# type parameter is a function/callable
547
589
type = lambda x : ConnectionRoles .from_string (x ),
548
590
help = 'Filter flows according to their direction'
@@ -563,32 +605,4 @@ def _pcap(name, pcapAction="store", filterAction="store"):
563
605
return parser
564
606
565
607
566
- # argparse_completer.ACArgumentParser
567
- class MpTcpAnalyzerParser (argparse_completer .ACArgumentParser ):
568
- '''
569
- Wrapper around cmd2 argparse completer
570
- Should allow to switch backends easily.
571
- Also allows to do some postprocessing once the arguments are parsed
572
- like loading dataframes etc
573
-
574
- '''
575
-
576
- # def _parse_known_args(self, arg_strings, namespace):
577
- def parse_known_args (self , args = None , namespace = None ):
578
- """
579
- override it just to postprocess arguments
580
- """
581
- res = super ().parse_known_args (args , namespace )
582
-
583
- # TODO call filter_dataframe ?
584
- if getattr (res , "_dataframes" , None ):
585
- for name , df in res ._dataframes .items ():
586
- # print
587
- # so now we can filter the destination ?
588
- pass
589
-
590
- # postprocessing for filtering destination
591
-
592
- logging .debug ("MpTcpAnalyzerParser parser finished" )
593
- return res
594
608
0 commit comments