fosslight-util 1.4.38__py3-none-any.whl → 1.4.40__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -15,28 +15,11 @@ logger = logging.getLogger(constant.LOGGER_NAME)
15
15
 
16
16
 
17
17
  def extract_name_version_from_link(link):
18
- # Github : https://github.com/(owner)/(repo)
19
- # npm : https://www.npmjs.com/package/(package)/v/(version)
20
- # npm2 : https://www.npmjs.com/package/@(group)/(package)/v/(version)
21
- # pypi : https://pypi.org/project/(oss_name)/(version)
22
- # pypi2 : https://files.pythonhosted.org/packages/source/(alphabet)/(oss_name)/(oss_name)-(version).tar.gz
23
- # Maven: https://mvnrepository.com/artifact/(group)/(artifact)/(version)
24
- # pub: https://pub.dev/packages/(package)/versions/(version)
25
- # Cocoapods: https://cocoapods.org/(package)
26
- pkg_pattern = {
27
- "pypi": r'https?:\/\/pypi\.org\/project\/([^\/]+)[\/]?([^\/]*)',
28
- "pypi2": r'https?:\/\/files\.pythonhosted\.org\/packages\/source\/[\w]\/([^\/]+)\/[\S]+-([^\-]+)\.tar\.gz',
29
- "maven": r'https?:\/\/mvnrepository\.com\/artifact\/([^\/]+)\/([^\/]+)\/?([^\/]*)',
30
- "npm": r'https?:\/\/www\.npmjs\.com\/package\/([^\/\@]+)(?:\/v\/)?([^\/]*)',
31
- "npm2": r'https?:\/\/www\.npmjs\.com\/package\/(\@[^\/]+\/[^\/]+)(?:\/v\/)?([^\/]*)',
32
- "pub": r'https?:\/\/pub\.dev\/packages\/([^\/]+)(?:\/versions\/)?([^\/]*)',
33
- "pods": r'https?:\/\/cocoapods\.org\/pods\/([^\/]+)'
34
- }
35
18
  oss_name = ""
36
19
  oss_version = ""
37
20
  if link.startswith("www."):
38
21
  link = link.replace("www.", "https://www.", 1)
39
- for key, value in pkg_pattern.items():
22
+ for key, value in constant.PKG_PATTERN.items():
40
23
  p = re.compile(value)
41
24
  match = p.match(link)
42
25
  if match:
@@ -57,7 +40,7 @@ def extract_name_version_from_link(link):
57
40
  elif key == "pub":
58
41
  oss_name = f"pub:{origin_name}"
59
42
  oss_version = match.group(2)
60
- elif key == "pods":
43
+ elif key == "cocoapods":
61
44
  oss_name = f"cocoapods:{origin_name}"
62
45
  except Exception as ex:
63
46
  logger.info(f"extract_name_version_from_link {key}:{ex}")
@@ -14,3 +14,23 @@ supported_sheet_and_scanner = {'SRC': FL_SOURCE,
14
14
  f'SRC_{FL_DEPENDENCY}': FL_DEPENDENCY,
15
15
  f'BIN_{FL_BINARY}': FL_BINARY,
16
16
  f'DEP_{FL_DEPENDENCY}': FL_DEPENDENCY}
17
+
18
+ # Github : https://github.com/(owner)/(repo)
19
+ # npm : https://www.npmjs.com/package/(package)/v/(version)
20
+ # npm2 : https://www.npmjs.com/package/@(group)/(package)/v/(version)
21
+ # pypi : https://pypi.org/project/(oss_name)/(version)
22
+ # pypi2 : https://files.pythonhosted.org/packages/source/(alphabet)/(oss_name)/(oss_name)-(version).tar.gz
23
+ # Maven: https://mvnrepository.com/artifact/(group)/(artifact)/(version)
24
+ # pub: https://pub.dev/packages/(package)/versions/(version)
25
+ # Cocoapods : https://cocoapods.org/(package)
26
+ # go : https://pkg.go.dev/(package_name_with_slash)@(version)
27
+ PKG_PATTERN = {
28
+ "pypi": r'https?:\/\/pypi\.org\/project\/([^\/]+)[\/]?([^\/]*)',
29
+ "pypi2": r'https?:\/\/files\.pythonhosted\.org\/packages\/source\/[\w]\/([^\/]+)\/[\S]+-([^\-]+)\.tar\.gz',
30
+ "maven": r'https?:\/\/mvnrepository\.com\/artifact\/([^\/]+)\/([^\/]+)\/?([^\/]*)',
31
+ "npm": r'https?:\/\/www\.npmjs\.com\/package\/([^\/\@]+)(?:\/v\/)?([^\/]*)',
32
+ "npm2": r'https?:\/\/www\.npmjs\.com\/package\/(\@[^\/]+\/[^\/]+)(?:\/v\/)?([^\/]*)',
33
+ "pub": r'https?:\/\/pub\.dev\/packages\/([^\/]+)(?:\/versions\/)?([^\/]*)',
34
+ "cocoapods": r'https?:\/\/cocoapods\.org\/pods\/([^\/]+)',
35
+ "go": r'https?:\/\/pkg.go.dev\/([^\@]+)\@?v?([^\/]*)'
36
+ }
@@ -0,0 +1,44 @@
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+ # Copyright (c) 2024 LG Electronics Inc.
4
+ # SPDX-License-Identifier: Apache-2.0
5
+
6
+ import os
7
+ import sys
8
+ from fosslight_util.help import print_package_version
9
+
10
+
11
+ class CoverItem:
12
+ tool_name_key = "Tool name"
13
+ tool_version_key = "Tool version"
14
+ start_time_key = "Start time"
15
+ python_ver_key = "Python version"
16
+ analyzed_path_key = "Analyzed path"
17
+ comment_key = "Comment"
18
+
19
+ def __init__(self, tool_name="", start_time="", input_path="", comment=""):
20
+ self.tool_name = tool_name
21
+ if start_time:
22
+ date, time = start_time.split('_')
23
+ self.start_time = f'{date}, {time[0:2]}:{time[2:4]}'
24
+ else:
25
+ self.start_time = ""
26
+ self.input_path = os.path.abspath(input_path)
27
+ self.comment = comment
28
+
29
+ self.tool_version = print_package_version(self.tool_name, "", False)
30
+ self.python_version = f'{sys.version_info.major}.{sys.version_info.minor}'
31
+
32
+ def __del__(self):
33
+ pass
34
+
35
+ def get_print_json(self):
36
+ json_item = {}
37
+ json_item[self.tool_name_key] = self.tool_name
38
+ json_item[self.tool_version_key] = self.tool_version
39
+ json_item[self.start_time_key] = self.start_time
40
+ json_item[self.python_ver_key] = self.python_version
41
+ json_item[self.analyzed_path_key] = self.input_path
42
+ json_item[self.comment_key] = self.comment
43
+
44
+ return json_item
fosslight_util/help.py CHANGED
@@ -52,10 +52,12 @@ def print_package_version(pkg_name, msg="", exitopt=True):
52
52
  if msg == "":
53
53
  msg = f"{pkg_name} Version:"
54
54
  cur_version = pkg_resources.get_distribution(pkg_name).version
55
- print(f'{msg} {cur_version}')
56
55
 
57
56
  if exitopt:
57
+ print(f'{msg} {cur_version}')
58
58
  sys.exit(0)
59
+ else:
60
+ return cur_version
59
61
 
60
62
 
61
63
  def print_help_msg_download(exitOpt=True):
@@ -3,7 +3,7 @@
3
3
  # Copyright (c) 2021 LG Electronics Inc.
4
4
  # SPDX-License-Identifier: Apache-2.0
5
5
  import os
6
- from fosslight_util.write_excel import write_result_to_excel, write_result_to_csv, remove_empty_sheet
6
+ from fosslight_util.write_excel import write_result_to_excel, write_result_to_csv
7
7
  from fosslight_util.write_opossum import write_opossum
8
8
  from fosslight_util.write_yaml import write_yaml
9
9
 
@@ -56,29 +56,24 @@ def check_output_format(output='', format='', customized_format={}):
56
56
  return success, msg, output_path, output_file, output_extension
57
57
 
58
58
 
59
- def write_output_file(output_file_without_ext, file_extension, sheet_list, extended_header={}, hide_header={}):
59
+ def write_output_file(output_file_without_ext, file_extension, sheet_list, extended_header={}, hide_header={}, cover=""):
60
60
  success = True
61
61
  msg = ''
62
62
 
63
- is_not_null, sheet_list = remove_empty_sheet(sheet_list)
64
- if is_not_null:
65
- if file_extension == '':
66
- file_extension = '.xlsx'
67
- result_file = output_file_without_ext + file_extension
63
+ if file_extension == '':
64
+ file_extension = '.xlsx'
65
+ result_file = output_file_without_ext + file_extension
68
66
 
69
- if file_extension == '.xlsx':
70
- success, msg = write_result_to_excel(result_file, sheet_list, extended_header, hide_header)
71
- elif file_extension == '.csv':
72
- success, msg, result_file = write_result_to_csv(result_file, sheet_list)
73
- elif file_extension == '.json':
74
- success, msg = write_opossum(result_file, sheet_list)
75
- elif file_extension == '.yaml':
76
- success, msg, result_file = write_yaml(result_file, sheet_list, False)
77
- else:
78
- success = False
79
- msg = f'Not supported file extension({file_extension})'
67
+ if file_extension == '.xlsx':
68
+ success, msg = write_result_to_excel(result_file, sheet_list, extended_header, hide_header, cover)
69
+ elif file_extension == '.csv':
70
+ success, msg, result_file = write_result_to_csv(result_file, sheet_list)
71
+ elif file_extension == '.json':
72
+ success, msg = write_opossum(result_file, sheet_list)
73
+ elif file_extension == '.yaml':
74
+ success, msg, result_file = write_yaml(result_file, sheet_list, False)
80
75
  else:
81
- result_file = ""
82
- msg = "Nothing is detected from the scanner so output file is not generated."
76
+ success = False
77
+ msg = f'Not supported file extension({file_extension})'
83
78
 
84
79
  return success, msg, result_file
@@ -13,6 +13,7 @@ import copy
13
13
  from pathlib import Path
14
14
  import fosslight_util.constant as constant
15
15
  from jsonmerge import merge
16
+ from fosslight_util.cover import CoverItem
16
17
 
17
18
  _HEADER = {'BIN (': ['ID', 'Binary Name', 'Source Code Path',
18
19
  'NOTICE.html', 'OSS Name', 'OSS Version',
@@ -31,6 +32,7 @@ _EMPTY_ITEM_MSG = "* There is no item"\
31
32
  IDX_FILE = 0
32
33
  IDX_EXCLUDE = 7
33
34
  logger = logging.getLogger(constant.LOGGER_NAME)
35
+ COVER_SHEET_NAME = 'Scanner Info'
34
36
 
35
37
 
36
38
  def write_excel_and_csv(filename_without_extension, sheet_list, ignore_os=False, extended_header={}, hide_header={}):
@@ -105,9 +107,9 @@ def get_header_row(sheet_name, sheet_content, extended_header={}):
105
107
  if sheet_name.startswith(header_key):
106
108
  selected_header = merged_headers[header_key]
107
109
  break
108
-
109
- if not selected_header:
110
- selected_header = sheet_content.pop(0)
110
+ if len(sheet_content) > 0:
111
+ if not selected_header:
112
+ selected_header = sheet_content.pop(0)
111
113
  return selected_header, sheet_content
112
114
 
113
115
 
@@ -166,16 +168,18 @@ def write_result_to_csv(output_file, sheet_list_origin, separate_sheet=False, ex
166
168
  return success, error_msg, output
167
169
 
168
170
 
169
- def write_result_to_excel(out_file_name, sheet_list, extended_header={}, hide_header={}):
171
+ def write_result_to_excel(out_file_name, sheet_list, extended_header={}, hide_header={}, cover=""):
170
172
  success = True
171
173
  error_msg = ""
172
174
 
173
175
  try:
174
- if sheet_list:
175
- output_dir = os.path.dirname(out_file_name)
176
- Path(output_dir).mkdir(parents=True, exist_ok=True)
176
+ output_dir = os.path.dirname(out_file_name)
177
+ Path(output_dir).mkdir(parents=True, exist_ok=True)
177
178
 
178
- workbook = xlsxwriter.Workbook(out_file_name)
179
+ workbook = xlsxwriter.Workbook(out_file_name)
180
+ if cover:
181
+ write_cover_sheet(workbook, cover)
182
+ if sheet_list:
179
183
  for sheet_name, sheet_contents in sheet_list.items():
180
184
  selected_header, sheet_content_without_header = get_header_row(sheet_name, sheet_contents[:], extended_header)
181
185
  try:
@@ -188,13 +192,33 @@ def write_result_to_excel(out_file_name, sheet_list, extended_header={}, hide_he
188
192
 
189
193
  if hide_header:
190
194
  hide_column(worksheet, selected_header, hide_header)
191
- workbook.close()
195
+ workbook.close()
192
196
  except Exception as ex:
193
197
  error_msg = str(ex)
194
198
  success = False
195
199
  return success, error_msg
196
200
 
197
201
 
202
+ def write_cover_sheet(workbook, cover):
203
+ worksheet = workbook.add_worksheet(COVER_SHEET_NAME)
204
+
205
+ format_bold = workbook.add_format({'bold': True})
206
+ worksheet.merge_range('A1:B1', 'About the scanner', format_bold)
207
+
208
+ key_format = workbook.add_format({'bold': True, 'font_color': 'white', 'bg_color': 'navy'})
209
+ item_format = workbook.add_format()
210
+ item_format.set_text_wrap()
211
+
212
+ cover_json = cover.get_print_json()
213
+ row = 1
214
+ for item in cover_json:
215
+ worksheet.write(row, 0, item, key_format)
216
+ worksheet.write(row, 1, cover_json[item], item_format)
217
+ row += 1
218
+ worksheet.set_column(0, 0, 30)
219
+ worksheet.set_column(1, 1, 100)
220
+
221
+
198
222
  def write_result_to_sheet(worksheet, sheet_contents):
199
223
  row = 1
200
224
  for row_item in sheet_contents:
@@ -221,7 +245,33 @@ def create_worksheet(workbook, sheet_name, header_row):
221
245
  return worksheet
222
246
 
223
247
 
224
- def merge_excels(find_excel_dir, final_out, merge_files=''):
248
+ def merge_cover_comment(find_excel_dir, merge_files=''):
249
+ FIND_EXTENSION = '.xlsx'
250
+ merge_comment = []
251
+ cover_comment = ''
252
+ try:
253
+ files = os.listdir(find_excel_dir)
254
+
255
+ if len([name for name in files if name.endswith(FIND_EXTENSION)]) > 0:
256
+ for file in files:
257
+ if merge_files:
258
+ if file not in merge_files:
259
+ continue
260
+ if file.endswith(FIND_EXTENSION):
261
+ file = os.path.join(find_excel_dir, file)
262
+ df_excel = pd.read_excel(file, sheet_name=COVER_SHEET_NAME, index_col=0, engine='openpyxl')
263
+ if not df_excel.empty:
264
+ tool_name = df_excel.loc[CoverItem.tool_name_key].values[0]
265
+ comment = df_excel.loc[CoverItem.comment_key].values[0]
266
+ merge_comment.append(str(f"[{tool_name}] {comment}"))
267
+ cover_comment = '\n'.join(merge_comment)
268
+ except Exception as ex:
269
+ logger.warning(f'Fail to merge comment of Scanner info: {str(ex)}')
270
+
271
+ return cover_comment
272
+
273
+
274
+ def merge_excels(find_excel_dir, final_out, merge_files='', cover=''):
225
275
  success = True
226
276
  msg = ""
227
277
  FIND_EXTENSION = '.xlsx'
@@ -231,7 +281,7 @@ def merge_excels(find_excel_dir, final_out, merge_files=''):
231
281
 
232
282
  if len([name for name in files if name.endswith(FIND_EXTENSION)]) > 0:
233
283
  writer = pd.ExcelWriter(final_out)
234
-
284
+ write_cover_sheet(writer.book, cover)
235
285
  for file in files:
236
286
  if merge_files:
237
287
  if file not in merge_files:
@@ -243,13 +293,14 @@ def merge_excels(find_excel_dir, final_out, merge_files=''):
243
293
  excel_file = pd.ExcelFile(file, engine='openpyxl')
244
294
 
245
295
  for sheet_name in excel_file.sheet_names:
246
- sheet_name_to_copy = f"{f_short_name}_{sheet_name}"
296
+ if sheet_name == COVER_SHEET_NAME:
297
+ continue
247
298
  df_excel = pd.read_excel(
248
299
  file, sheet_name=sheet_name, engine='openpyxl')
249
- if sheet_name not in added_sheet_names:
250
- sheet_name_to_copy = sheet_name
251
- df_excel.to_excel(writer, sheet_name_to_copy,
252
- index=False)
300
+ if sheet_name in added_sheet_names:
301
+ sheet_name = f"{f_short_name}_{sheet_name}"
302
+ df_excel.to_excel(writer, sheet_name, index=False)
303
+ added_sheet_names.append(sheet_name)
253
304
  writer.close()
254
305
  except Exception as ex:
255
306
  msg = str(ex)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: fosslight-util
3
- Version: 1.4.38
3
+ Version: 1.4.40
4
4
  Summary: FOSSLight Util
5
5
  Home-page: https://github.com/fosslight/fosslight_util
6
6
  Author: LG Electronics
@@ -1,19 +1,20 @@
1
1
  fosslight_util/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- fosslight_util/_get_downloadable_url.py,sha256=vCsrppexrNR6ROzgosDb9ZiJCcWvuykdClBGd91nkd4,10175
2
+ fosslight_util/_get_downloadable_url.py,sha256=63ZPI4KCpUFgL4oheKm8zvekuCRzpwNkVaLJcA-uA90,9010
3
3
  fosslight_util/compare_yaml.py,sha256=0bapoyS0yrzkiK70K57E8-3wZ_D6mZAJ-24Eq9TYBlk,2632
4
- fosslight_util/constant.py,sha256=mDrH3Ahldhs9xT63iC8BmeRLHjN6fewI1H-pxnGvcD8,595
4
+ fosslight_util/constant.py,sha256=j9uhncoC2Fn4j4ATNsjUoS91nVXhyGzU6xLyWFj941A,1834
5
5
  fosslight_util/convert_excel_to_yaml.py,sha256=7ZsAMMQJIEXrmcl_28nSHvFpGMi1ZiRZYpEfI5O8vP8,2298
6
6
  fosslight_util/correct.py,sha256=RQ70zaQ_xuo9Mo0zIcb6pRQwt96bsimQJWkYldE2vbg,5224
7
+ fosslight_util/cover.py,sha256=21l-BS3ZJ8nDxMLHKGT9igB3XbCme55A0eQf01jbISM,1436
7
8
  fosslight_util/download.py,sha256=tYsY5rb3fRCwqCDzZzF7wY_kzpMO4cz3G6B7ApdEolA,13732
8
- fosslight_util/help.py,sha256=3ej8HhpszfFLRxR99Ob55MwHypjIHce1-YSp5_ENq-A,2113
9
+ fosslight_util/help.py,sha256=xhAf43fuRLOU3TE7jqaxVTizVn4aANDvHaHYQAdaqYc,2154
9
10
  fosslight_util/oss_item.py,sha256=Gjw-aI4gZGYrCbAkCL35lXlgA2w2F2plgOUmenQ1Cig,5238
10
- fosslight_util/output_format.py,sha256=-gw3F6wOHS0dKEtbZj8q4JC3JdXdDfid_bOtdlOJEdo,3243
11
+ fosslight_util/output_format.py,sha256=kJpuTuS3XTrsdUd2gsl5GWto5KtJfSej-qkD9azZFdQ,2982
11
12
  fosslight_util/parsing_yaml.py,sha256=zmetMiZprni_YMxUfj_Nx-nXm0sT31Ck_V0nWFS6ZmE,4332
12
13
  fosslight_util/read_excel.py,sha256=eN2aNkJv3Y2071f6lHfQTHx5IFJe0imxH3TeRO_kodc,5154
13
14
  fosslight_util/set_log.py,sha256=8cFGpr4HMk4grHo3a5keR4V1xWBscbjowYPxyrh42ks,3140
14
15
  fosslight_util/spdx_licenses.py,sha256=r90hUY4_T-XrHIJHLx1Ox3gWZ3qzdZj9rJFo7AwmkPE,3641
15
16
  fosslight_util/timer_thread.py,sha256=5VbZENQPD-N0NUmzEktqGr6Am-e7vxD79K05mmr29g0,433
16
- fosslight_util/write_excel.py,sha256=JWZGvmJ42cD1kLJ_2Z43JhaDp2S3SxHjREtL73YBzX8,10017
17
+ fosslight_util/write_excel.py,sha256=8-qZhCM31KzLrNwysX_hF9ZCSzSUOzkZmTPeekKVKJg,12065
17
18
  fosslight_util/write_opossum.py,sha256=PGJV5DysNJvIFbzsyGXxh_kRcvZuHAOmLs-WlXP8qMI,11831
18
19
  fosslight_util/write_scancodejson.py,sha256=CSKjuwbA04nK5ogXklNsCBgGDZXPr805T8KPLgvx71U,2282
19
20
  fosslight_util/write_spdx.py,sha256=B_aHv9vScgZI5gHo5Hd56ckNWOHdyAQebRV54bTx9ec,9542
@@ -22,9 +23,9 @@ fosslight_util/write_yaml.py,sha256=ppBBErAXbXw8jtJ9j7BDeQHHzDlsTRt62XR0GgTcr70,
22
23
  fosslight_util/resources/frequentLicenselist.json,sha256=GUhzK6tu7ok10fekOnmVmUgIGRC-acGABZKTNKfDyYA,4776157
23
24
  fosslight_util/resources/frequent_license_nick_list.json,sha256=ryU2C_6ZxHbz90_sUN9OvI9GXkCMLu7oGcmd9W79YYo,5005
24
25
  fosslight_util/resources/licenses.json,sha256=mK55z-bhY7Mjpj2KsO1crKGGL-X3F6MBFQJ0zLlx010,240843
25
- fosslight_util-1.4.38.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
26
- fosslight_util-1.4.38.dist-info/METADATA,sha256=EI1wf4oIup1AK-1YhpCLpjFzLO2BnzCKb17NJIMwtLE,6189
27
- fosslight_util-1.4.38.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
28
- fosslight_util-1.4.38.dist-info/entry_points.txt,sha256=bzXX5i7HZ13V8BLKvtu_9KO3ZjtRypH-XszOXT6I3bU,69
29
- fosslight_util-1.4.38.dist-info/top_level.txt,sha256=2qyYWGLakgBRy4BqoBNt-I5C29tBr_e93e5e1pbuTGA,15
30
- fosslight_util-1.4.38.dist-info/RECORD,,
26
+ fosslight_util-1.4.40.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
27
+ fosslight_util-1.4.40.dist-info/METADATA,sha256=o4BdKiS8Caz_wUgyy2_REDR9uQ-vYmkgw-Njxyjdo2A,6189
28
+ fosslight_util-1.4.40.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
29
+ fosslight_util-1.4.40.dist-info/entry_points.txt,sha256=bzXX5i7HZ13V8BLKvtu_9KO3ZjtRypH-XszOXT6I3bU,69
30
+ fosslight_util-1.4.40.dist-info/top_level.txt,sha256=2qyYWGLakgBRy4BqoBNt-I5C29tBr_e93e5e1pbuTGA,15
31
+ fosslight_util-1.4.40.dist-info/RECORD,,