38
38
39
39
def deprecated (reason ):
40
40
"""Deprecate a function/method with a decorator"""
41
+
41
42
def actual_decorator (func ):
42
43
@functools .wraps (func )
43
44
def new_func (* args , ** kwargs ):
44
- logger .warning ("Call to deprecated function %s. %s" ,
45
- func .__name__ , reason )
45
+ logger .warning ("Call to deprecated function %s. %s" , func .__name__ , reason )
46
46
return func (* args , ** kwargs )
47
+
47
48
return new_func
49
+
48
50
return actual_decorator
49
51
50
52
@@ -588,82 +590,100 @@ def _run_cli_process(cmd, shell=True):
588
590
_stdout , _stderr = p .communicate ()
589
591
return _stdout , _stderr , p .returncode
590
592
591
- @deprecated ("Functionality has been moved into 'list_mbeds'. "
592
- "Please use list_mbeds with 'unique_names=True' and "
593
- "'read_details_txt=True'" )
593
+ @deprecated (
594
+ "Functionality has been moved into 'list_mbeds'. "
595
+ "Please use list_mbeds with 'unique_names=True' and "
596
+ "'read_details_txt=True'"
597
+ )
594
598
def list_mbeds_ext (self ):
595
599
"""! Function adds extra information for each mbed device
596
- @return Returns list of mbed devices plus extended data like 'platform_name_unique'
600
+ @return Returns list of mbed devices plus extended data like
601
+ 'platform_name_unique'
597
602
@details Get information about mbeds with extended parameters/info included
598
603
"""
599
604
600
605
return self .list_mbeds (unique_names = True , read_details_txt = True )
601
606
602
- @deprecated ("List formatting methods are deprecated for a simpler API. "
603
- "Please use 'list_mbeds' instead." )
607
+ @deprecated (
608
+ "List formatting methods are deprecated for a simpler API. "
609
+ "Please use 'list_mbeds' instead."
610
+ )
604
611
def list_manufacture_ids (self ):
605
612
"""! Creates list of all available mappings for target_id -> Platform
606
613
@return String with table formatted output
607
614
"""
608
615
from prettytable import PrettyTable , HEADER
609
616
610
- columns = [' target_id_prefix' , ' platform_name' ]
617
+ columns = [" target_id_prefix" , " platform_name" ]
611
618
pt = PrettyTable (columns , junction_char = "|" , hrules = HEADER )
612
619
for col in columns :
613
- pt .align [col ] = 'l'
620
+ pt .align [col ] = "l"
614
621
615
622
for target_id_prefix , platform_name in sorted (self .plat_db .items ()):
616
623
pt .add_row ([target_id_prefix , platform_name ])
617
624
618
625
return pt .get_string ()
619
626
620
- @deprecated ("List formatting methods are deprecated to simplify the API. "
621
- "Please use 'list_mbeds' instead." )
627
+ @deprecated (
628
+ "List formatting methods are deprecated to simplify the API. "
629
+ "Please use 'list_mbeds' instead."
630
+ )
622
631
def list_platforms (self ):
623
- """! Useful if you just want to know which platforms are currently available on the system
632
+ """! Useful if you just want to know which platforms are currently
633
+ available on the system
624
634
@return List of (unique values) available platforms
625
635
"""
626
636
result = []
627
637
mbeds = self .list_mbeds ()
628
638
for i , val in enumerate (mbeds ):
629
- platform_name = str (val [' platform_name' ])
639
+ platform_name = str (val [" platform_name" ])
630
640
if platform_name not in result :
631
641
result .append (platform_name )
632
642
return result
633
643
634
- @deprecated ("List formatting methods are deprecated to simplify the API. "
635
- "Please use 'list_mbeds' instead." )
644
+ @deprecated (
645
+ "List formatting methods are deprecated to simplify the API. "
646
+ "Please use 'list_mbeds' instead."
647
+ )
636
648
def list_platforms_ext (self ):
637
- """! Useful if you just want to know how many platforms of each type are currently available on the system
649
+ """! Useful if you just want to know how many platforms of each type are
650
+ currently available on the system
638
651
@return Dict of platform: platform_count
639
652
"""
640
653
result = {}
641
654
mbeds = self .list_mbeds ()
642
655
for i , val in enumerate (mbeds ):
643
- platform_name = str (val [' platform_name' ])
656
+ platform_name = str (val [" platform_name" ])
644
657
if platform_name not in result :
645
658
result [platform_name ] = 1
646
659
else :
647
660
result [platform_name ] += 1
648
661
return result
649
662
650
- @deprecated ("List formatting methods are deprecated to simplify the API. "
651
- "Please use 'list_mbeds' instead." )
663
+ @deprecated (
664
+ "List formatting methods are deprecated to simplify the API. "
665
+ "Please use 'list_mbeds' instead."
666
+ )
652
667
def list_mbeds_by_targetid (self ):
653
668
"""! Get information about mbeds with extended parameters/info included
654
- @return Returns dictionary where keys are TargetIDs and values are mbed structures
669
+ @return Returns dictionary where keys are TargetIDs and values are mbed
670
+ structures
655
671
@details Ordered by target id (key: target_id).
656
672
"""
657
673
result = {}
658
674
mbed_list = self .list_mbeds_ext ()
659
675
for mbed in mbed_list :
660
- target_id = mbed [' target_id' ]
676
+ target_id = mbed [" target_id" ]
661
677
result [target_id ] = mbed
662
678
return result
663
679
664
- @deprecated ("List formatting methods are deprecated to simplify the API. "
665
- "Please use 'list_mbeds' instead." )
666
- def get_string (self , border = False , header = True , padding_width = 1 , sortby = 'platform_name' ):
680
+ @deprecated (
681
+ "List formatting methods are deprecated to simplify the API. "
682
+ "Please use 'list_mbeds' instead."
683
+ )
684
+ def get_string (
685
+ self , border = False , header = True , padding_width = 1 , sortby = "platform_name"
686
+ ):
667
687
"""! Printing with some sql table like decorators
668
688
@param border Table border visibility
669
689
@param header Table header visibility
@@ -672,29 +692,43 @@ def get_string(self, border=False, header=True, padding_width=1, sortby='platfor
672
692
@return Returns string which can be printed on console
673
693
"""
674
694
from prettytable import PrettyTable , HEADER
675
- result = ''
695
+
696
+ result = ""
676
697
mbeds = self .list_mbeds (unique_names = True , read_details_txt = True )
677
698
if mbeds :
678
- """ ['platform_name', 'mount_point', 'serial_port', 'target_id'] - columns generated from USB auto-detection
679
- ['platform_name_unique', ...] - columns generated outside detection subsystem (OS dependent detection)
699
+ """ ['platform_name', 'mount_point', 'serial_port', 'target_id'] -
700
+ columns generated from USB auto-detection
701
+ ['platform_name_unique', ...] -
702
+ columns generated outside detection subsystem (OS dependent detection)
680
703
"""
681
- columns = ['platform_name' , 'platform_name_unique' , 'mount_point' , 'serial_port' , 'target_id' , 'daplink_version' ]
704
+ columns = [
705
+ "platform_name" ,
706
+ "platform_name_unique" ,
707
+ "mount_point" ,
708
+ "serial_port" ,
709
+ "target_id" ,
710
+ "daplink_version" ,
711
+ ]
682
712
pt = PrettyTable (columns , junction_char = "|" , hrules = HEADER )
683
713
for col in columns :
684
- pt .align [col ] = 'l'
714
+ pt .align [col ] = "l"
685
715
686
716
for mbed in mbeds :
687
717
row = []
688
718
for col in columns :
689
- row .append (mbed [col ] if col in mbed and mbed [col ] else ' unknown' )
719
+ row .append (mbed [col ] if col in mbed and mbed [col ] else " unknown" )
690
720
pt .add_row (row )
691
- result = pt .get_string (border = border , header = header , padding_width = padding_width , sortby = sortby )
721
+ result = pt .get_string (
722
+ border = border , header = header , padding_width = padding_width , sortby = sortby
723
+ )
692
724
return result
693
725
694
726
# Private functions supporting API
695
727
696
- @deprecated ("This method will be removed from the public API. "
697
- "Please use 'list_mbeds' instead" )
728
+ @deprecated (
729
+ "This method will be removed from the public API. "
730
+ "Please use 'list_mbeds' instead"
731
+ )
698
732
def get_json_data_from_file (self , json_spec_filename , verbose = False ):
699
733
"""! Loads from file JSON formatted string to data structure
700
734
@return None if JSON can be loaded
@@ -704,51 +738,69 @@ def get_json_data_from_file(self, json_spec_filename, verbose=False):
704
738
try :
705
739
return json .load (data_file )
706
740
except ValueError as json_error_msg :
707
- logger .error ("Parsing file(%s): %s" , json_spec_filename , json_error_msg )
741
+ logger .error (
742
+ "Parsing file(%s): %s" , json_spec_filename , json_error_msg
743
+ )
708
744
return None
709
745
except IOError as fileopen_error_msg :
710
746
logger .warning (fileopen_error_msg )
711
747
return None
712
748
713
- @deprecated ("This method will be removed from the public API. "
714
- "Please use 'list_mbeds' instead" )
749
+ @deprecated (
750
+ "This method will be removed from the public API. "
751
+ "Please use 'list_mbeds' instead"
752
+ )
715
753
def get_htm_target_id (self , mount_point ):
716
754
target_id , _ = self ._read_htm_ids (mount_point )
717
755
return target_id
718
756
719
- @deprecated ("This method will be removed from the public API. "
720
- "Please use 'list_mbeds' instead" )
757
+ @deprecated (
758
+ "This method will be removed from the public API. "
759
+ "Please use 'list_mbeds' instead"
760
+ )
721
761
def get_mbed_htm (self , mount_point ):
722
762
_ , build_info = self ._read_htm_ids (mount_point )
723
763
return build_info
724
764
725
- @deprecated ("This method will be removed from the public API. "
726
- "Please use 'list_mbeds' instead" )
765
+ @deprecated (
766
+ "This method will be removed from the public API. "
767
+ "Please use 'list_mbeds' instead"
768
+ )
727
769
def get_mbed_htm_comment_section_ver_build (self , line ):
728
770
return self ._mbed_htm_comment_section_ver_build (line )
729
771
730
- @deprecated ("This method will be removed from the public API. "
731
- "Please use 'list_mbeds' instead" )
772
+ @deprecated (
773
+ "This method will be removed from the public API. "
774
+ "Please use 'list_mbeds' instead"
775
+ )
732
776
def get_mbed_htm_lines (self , mount_point ):
733
777
return self ._htm_lines (mount_point )
734
778
735
- @deprecated ("This method will be removed from the public API. "
736
- "Please use 'list_mbeds' instead" )
779
+ @deprecated (
780
+ "This method will be removed from the public API. "
781
+ "Please use 'list_mbeds' instead"
782
+ )
737
783
def get_details_txt (self , mount_point ):
738
784
return self ._details_txt (mount_point )
739
785
740
- @deprecated ("This method will be removed from the public API. "
741
- "Please use 'list_mbeds' instead" )
786
+ @deprecated (
787
+ "This method will be removed from the public API. "
788
+ "Please use 'list_mbeds' instead"
789
+ )
742
790
def parse_details_txt (self , lines ):
743
791
return self ._parse_details (lines )
744
792
745
- @deprecated ("This method will be removed from the public API. "
746
- "Please use 'list_mbeds' instead" )
793
+ @deprecated (
794
+ "This method will be removed from the public API. "
795
+ "Please use 'list_mbeds' instead"
796
+ )
747
797
def scan_html_line_for_target_id (self , line ):
748
798
return self ._target_id_from_htm (line )
749
799
750
800
@staticmethod
751
- @deprecated ("This method will be removed from the public API. "
752
- "Please use 'list_mbeds' instead" )
801
+ @deprecated (
802
+ "This method will be removed from the public API. "
803
+ "Please use 'list_mbeds' instead"
804
+ )
753
805
def run_cli_process (cmd , shell = True ):
754
806
return MbedLsToolsBase ._run_cli_process (cmd , shell )
0 commit comments