Coverage for src / codeaudit / codeaudit.py: 0%

35 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-04-09 09:33 +0200

1""" 

2License GPLv3 or higher. 

3 

4(C) 2025 Created by Maikel Mardjan - https://nocomplexity.com/ 

5 

6This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. 

7 

8This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. 

9 

10You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>. 

11 

12 

13CLI functions for codeaudit 

14""" 

15 

16import sys 

17 

18import fire # for working CLI with this PoC-thing (The Google way) 

19 

20from codeaudit import __version__ 

21from codeaudit.reporting import ( 

22 overview_report, 

23 report_implemented_tests, 

24 report_module_information, 

25 scan_report, 

26) 

27 

28codeaudit_ascii_art = r""" 

29---------------------------------------------------- 

30 _ __ _  

31|_) \/_|_|_ _ __ / _ _| _ |_| _| o _|_ 

32| / |_| |(_)| | \__(_)(_|(/_ | ||_|(_| | |_ 

33---------------------------------------------------- 

34""" 

35 

36 

37def display_version(): 

38 """Prints the module version. Or use codeaudit [-v] [--v] [-version] or [--version].""" 

39 print(f"version: {__version__}") 

40 

41 

42def display_help(): 

43 """Shows detailed help for using codeaudit tool.""" 

44 print(codeaudit_ascii_art) 

45 print( 

46 "Python Code Audit - A modern Python security source code analyzer based on distrust.\n" 

47 ) 

48 print("Commands to evaluate Python source code:") 

49 print("Usage: codeaudit COMMAND <directory|package> [report.html] \n") 

50 print( 

51 "Depending on the command, you must specify a local directory, a Python file, or a package name hosted on PyPI.org.Reporting: The results are generated as a static HTML report for viewing in a web browser.\n" 

52 ) 

53 print("Commands:") 

54 commands = [ 

55 "overview", 

56 "filescan", 

57 "modulescan", 

58 "checks", 

59 "version", 

60 ] # commands on CLI 

61 functions = [ 

62 overview_report, 

63 scan_report, 

64 report_module_information, 

65 report_implemented_tests, 

66 display_version, 

67 ] # Related functions relevant for help 

68 for command, function in zip(commands, functions): 

69 docstring = function.__doc__.strip().split("\n")[0] or "" 

70 summary = docstring.split("\n", 1)[0] 

71 print(f" {command:<20} {summary}") 

72 print( 

73 "\nUse the Python Code Audit documentation (https://codeaudit.nocomplexity.com) to audit and secure your Python programmes. Explore further essential open-source security tools at https://simplifysecurity.nocomplexity.com/\n" 

74 ) 

75 

76 

77def main(): 

78 if ( 

79 "-?" in sys.argv 

80 ): # Normalize help flags BEFORE Fire sees them: fire module treats anything starting with - as a flag/value, not as a help alias. 

81 sys.argv[sys.argv.index("-?")] = "--help" 

82 if "-help" in sys.argv: # Normalize help flags BEFORE Fire sees them 

83 sys.argv[sys.argv.index("-help")] = "--help" 

84 if len(sys.argv) > 1 and sys.argv[1] in ("-v", "--v", "--version", "-version"): 

85 display_version() 

86 elif len(sys.argv) > 1 and sys.argv[1] in ("-help", "--help", "-h"): 

87 display_help() 

88 elif len(sys.argv) == 1: 

89 display_help() 

90 else: 

91 fire.Fire( 

92 { 

93 "overview": overview_report, 

94 "modulescan": report_module_information, 

95 "filescan": scan_report, 

96 "checks": report_implemented_tests, 

97 "version": display_version, 

98 } 

99 ) 

100 

101 

102if __name__ == "__main__": 

103 main()