FOSSology  4.4.0
Open Source License Compliance by Open Source Software
CliOptions.py
1 #!/usr/bin/env python3
2 
3 # SPDX-FileCopyrightText: © 2023 Siemens AG
4 # SPDX-FileContributor: Gaurav Mishra <mishra.gaurav@siemens.com>
5 
6 # SPDX-License-Identifier: GPL-2.0-only
7 
8 import os
9 from argparse import Namespace
10 from enum import Enum
11 
12 
13 class ReportFormat(Enum):
14  """
15  Report formats supported by the script.
16  """
17  TEXT = 0
18  SPDX_JSON = 1
19  SPDX_RDF = 2
20  SPDX_TAG_VALUE = 3
21  SPDX_YAML = 4
22 
23 
24 class CliOptions(object):
25  """
26  Hold the various shared flags and data
27 
28  :ivar nomos: run nomos scanner
29  :ivar ojo: run ojo scanner
30  :ivar copyright: run copyright scanner
31  :ivar keyword: run keyword scanner
32  :ivar repo: scan whole repo or just diff
33  :ivar diff_dir: directory to scan
34  :ivar allowlist: information from allowlist.json
35  :ivar report_format: Report format to use
36  """
37  nomos: bool = False
38  ojo: bool = False
39  copyright: bool = False
40  keyword: bool = False
41  repo: bool = False
42  diff_dir: str = os.getcwd()
43  allowlist: dict[str, list[str]] = {
44  'licenses': [],
45  'exclude': []
46  }
47  report_format: ReportFormat = ReportFormat.TEXT
48 
49  def update_args(self, args: Namespace):
50  """
51  Update options based on argsparse values.
52 
53  :param args: Argparse from cli
54  """
55  if "nomos" in args.operation:
56  self.nomosnomos = True
57  if "copyright" in args.operation:
58  self.copyrightcopyright = True
59  if "keyword" in args.operation:
60  self.keywordkeyword = True
61  if "ojo" in args.operation:
62  self.ojoojo = True
63  if "repo" in args.operation:
64  self.reporepo = True
65  if self.nomosnomos is False and self.ojoojo is False and self.copyrightcopyright is False \
66  and self.keywordkeyword is False:
67  self.nomosnomos = True
68  self.ojoojo = True
69  self.copyrightcopyright = True
70  self.keywordkeyword = True
71  self.report_formatreport_format = ReportFormat[args.report]
def update_args(self, Namespace args)
Definition: CliOptions.py:49