fosslight-util 2.1.1__tar.gz → 2.1.2__tar.gz

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.
Files changed (37) hide show
  1. {fosslight_util-2.1.1 → fosslight_util-2.1.2}/PKG-INFO +1 -1
  2. {fosslight_util-2.1.1 → fosslight_util-2.1.2}/setup.py +1 -1
  3. {fosslight_util-2.1.1 → fosslight_util-2.1.2}/src/fosslight_util/download.py +95 -61
  4. {fosslight_util-2.1.1 → fosslight_util-2.1.2}/src/fosslight_util/output_format.py +10 -10
  5. {fosslight_util-2.1.1 → fosslight_util-2.1.2}/src/fosslight_util.egg-info/PKG-INFO +1 -1
  6. {fosslight_util-2.1.1 → fosslight_util-2.1.2}/LICENSE +0 -0
  7. {fosslight_util-2.1.1 → fosslight_util-2.1.2}/MANIFEST.in +0 -0
  8. {fosslight_util-2.1.1 → fosslight_util-2.1.2}/README.md +0 -0
  9. {fosslight_util-2.1.1 → fosslight_util-2.1.2}/requirements.txt +0 -0
  10. {fosslight_util-2.1.1 → fosslight_util-2.1.2}/setup.cfg +0 -0
  11. {fosslight_util-2.1.1 → fosslight_util-2.1.2}/src/fosslight_util/__init__.py +0 -0
  12. {fosslight_util-2.1.1 → fosslight_util-2.1.2}/src/fosslight_util/_get_downloadable_url.py +0 -0
  13. {fosslight_util-2.1.1 → fosslight_util-2.1.2}/src/fosslight_util/compare_yaml.py +0 -0
  14. {fosslight_util-2.1.1 → fosslight_util-2.1.2}/src/fosslight_util/constant.py +0 -0
  15. {fosslight_util-2.1.1 → fosslight_util-2.1.2}/src/fosslight_util/correct.py +0 -0
  16. {fosslight_util-2.1.1 → fosslight_util-2.1.2}/src/fosslight_util/cover.py +0 -0
  17. {fosslight_util-2.1.1 → fosslight_util-2.1.2}/src/fosslight_util/help.py +0 -0
  18. {fosslight_util-2.1.1 → fosslight_util-2.1.2}/src/fosslight_util/oss_item.py +0 -0
  19. {fosslight_util-2.1.1 → fosslight_util-2.1.2}/src/fosslight_util/parsing_yaml.py +0 -0
  20. {fosslight_util-2.1.1 → fosslight_util-2.1.2}/src/fosslight_util/read_excel.py +0 -0
  21. {fosslight_util-2.1.1 → fosslight_util-2.1.2}/src/fosslight_util/resources/frequentLicenselist.json +0 -0
  22. {fosslight_util-2.1.1 → fosslight_util-2.1.2}/src/fosslight_util/resources/frequent_license_nick_list.json +0 -0
  23. {fosslight_util-2.1.1 → fosslight_util-2.1.2}/src/fosslight_util/resources/licenses.json +0 -0
  24. {fosslight_util-2.1.1 → fosslight_util-2.1.2}/src/fosslight_util/set_log.py +0 -0
  25. {fosslight_util-2.1.1 → fosslight_util-2.1.2}/src/fosslight_util/spdx_licenses.py +0 -0
  26. {fosslight_util-2.1.1 → fosslight_util-2.1.2}/src/fosslight_util/timer_thread.py +0 -0
  27. {fosslight_util-2.1.1 → fosslight_util-2.1.2}/src/fosslight_util/write_excel.py +0 -0
  28. {fosslight_util-2.1.1 → fosslight_util-2.1.2}/src/fosslight_util/write_opossum.py +0 -0
  29. {fosslight_util-2.1.1 → fosslight_util-2.1.2}/src/fosslight_util/write_scancodejson.py +0 -0
  30. {fosslight_util-2.1.1 → fosslight_util-2.1.2}/src/fosslight_util/write_spdx.py +0 -0
  31. {fosslight_util-2.1.1 → fosslight_util-2.1.2}/src/fosslight_util/write_txt.py +0 -0
  32. {fosslight_util-2.1.1 → fosslight_util-2.1.2}/src/fosslight_util/write_yaml.py +0 -0
  33. {fosslight_util-2.1.1 → fosslight_util-2.1.2}/src/fosslight_util.egg-info/SOURCES.txt +0 -0
  34. {fosslight_util-2.1.1 → fosslight_util-2.1.2}/src/fosslight_util.egg-info/dependency_links.txt +0 -0
  35. {fosslight_util-2.1.1 → fosslight_util-2.1.2}/src/fosslight_util.egg-info/entry_points.txt +0 -0
  36. {fosslight_util-2.1.1 → fosslight_util-2.1.2}/src/fosslight_util.egg-info/requires.txt +0 -0
  37. {fosslight_util-2.1.1 → fosslight_util-2.1.2}/src/fosslight_util.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: fosslight_util
3
- Version: 2.1.1
3
+ Version: 2.1.2
4
4
  Summary: FOSSLight Util
5
5
  Home-page: https://github.com/fosslight/fosslight_util
6
6
  Author: LG Electronics
@@ -14,7 +14,7 @@ with open('requirements.txt', 'r', 'utf-8') as f:
14
14
  if __name__ == "__main__":
15
15
  setup(
16
16
  name='fosslight_util',
17
- version='2.1.1',
17
+ version='2.1.2',
18
18
  package_dir={"": "src"},
19
19
  packages=find_packages(where='src'),
20
20
  description='FOSSLight Util',
@@ -10,7 +10,7 @@ import zipfile
10
10
  import logging
11
11
  import argparse
12
12
  import shutil
13
- from git import Repo, GitCommandError
13
+ from git import Repo, GitCommandError, Git
14
14
  import bz2
15
15
  import contextlib
16
16
  from datetime import datetime
@@ -77,7 +77,7 @@ def parse_src_link(src_link):
77
77
  if src_link.startswith("git://github.com/"):
78
78
  src_link_changed = change_src_link_to_https(src_link_split[0])
79
79
  elif src_link.startswith("git@github.com:"):
80
- src_link_changed = change_ssh_link_to_https(src_link_split[0])
80
+ src_link_changed = src_link_split[0]
81
81
  else:
82
82
  if "rubygems.org" in src_link:
83
83
  src_info["rubygems"] = True
@@ -92,39 +92,9 @@ def parse_src_link(src_link):
92
92
  return src_info
93
93
 
94
94
 
95
- def main():
96
- parser = argparse.ArgumentParser(description='FOSSLight Downloader', prog='fosslight_download', add_help=False)
97
- parser.add_argument('-h', '--help', help='Print help message', action='store_true', dest='help')
98
- parser.add_argument('-s', '--source', help='Source link to download', type=str, dest='source')
99
- parser.add_argument('-t', '--target_dir', help='Target directory', type=str, dest='target_dir', default="")
100
- parser.add_argument('-d', '--log_dir', help='Directory to save log file', type=str, dest='log_dir', default="")
101
-
102
- src_link = ""
103
- target_dir = os.getcwd()
104
- log_dir = os.getcwd()
105
-
106
- try:
107
- args = parser.parse_args()
108
- except SystemExit:
109
- sys.exit(0)
110
-
111
- if args.help:
112
- print_help_msg_download()
113
- if args.source:
114
- src_link = args.source
115
- if args.target_dir:
116
- target_dir = args.target_dir
117
- if args.log_dir:
118
- log_dir = args.log_dir
119
-
120
- if not src_link:
121
- print_help_msg_download()
122
- else:
123
- cli_download_and_extract(src_link, target_dir, log_dir)
124
-
125
-
126
95
  def cli_download_and_extract(link: str, target_dir: str, log_dir: str, checkout_to: str = "",
127
- compressed_only: bool = False) -> Tuple[bool, str, str, str]:
96
+ compressed_only: bool = False, ssh_key: str = "",
97
+ id: str = "", git_token: str = "") -> Tuple[bool, str, str, str]:
128
98
  global logger
129
99
 
130
100
  success = True
@@ -152,7 +122,9 @@ def cli_download_and_extract(link: str, target_dir: str, log_dir: str, checkout_
152
122
  is_rubygems = src_info.get("rubygems", False)
153
123
 
154
124
  # General download (git clone, wget)
155
- success_git, msg, oss_name, oss_version = download_git_clone(link, target_dir, checkout_to, tag, branch)
125
+ success_git, msg, oss_name, oss_version = download_git_clone(link, target_dir, checkout_to,
126
+ tag, branch, ssh_key, id, git_token)
127
+ link = change_ssh_link_to_https(link)
156
128
  if (not is_rubygems) and (not success_git):
157
129
  if os.path.isfile(target_dir):
158
130
  shutil.rmtree(target_dir)
@@ -229,11 +201,38 @@ def get_github_token(git_url):
229
201
  return github_token
230
202
 
231
203
 
232
- def download_git_clone(git_url, target_dir, checkout_to="", tag="", branch=""):
204
+ def download_git_repository(refs_to_checkout, git_url, target_dir, tag):
205
+ success = False
206
+ oss_version = ""
207
+ clone_default_branch_flag = False
208
+
209
+ logger.info(f"Download git url :{git_url}")
210
+ if refs_to_checkout:
211
+ try:
212
+ # gitPython uses the branch argument the same whether you check out to a branch or a tag.
213
+ repo = Repo.clone_from(git_url, target_dir, branch=refs_to_checkout)
214
+ success = True
215
+ except GitCommandError as error:
216
+ logger.debug(f"Git checkout error:{error}")
217
+ success = False
218
+
219
+ if not success:
220
+ repo = Repo.clone_from(git_url, target_dir)
221
+ clone_default_branch_flag = True
222
+ success = True
223
+
224
+ if refs_to_checkout != tag or clone_default_branch_flag:
225
+ oss_version = repo.active_branch.name
226
+ else:
227
+ oss_version = repo.git.describe('--tags')
228
+ return success, oss_version
229
+
230
+
231
+ def download_git_clone(git_url, target_dir, checkout_to="", tag="", branch="", ssh_key="", id="", git_token=""):
233
232
  oss_name = get_github_ossname(git_url)
234
233
  refs_to_checkout = decide_checkout(checkout_to, tag, branch)
235
- clone_default_branch_flag = False
236
234
  msg = ""
235
+ success = True
237
236
 
238
237
  try:
239
238
  if platform.system() != "Windows":
@@ -244,36 +243,40 @@ def download_git_clone(git_url, target_dir, checkout_to="", tag="", branch=""):
244
243
  alarm.start()
245
244
 
246
245
  Path(target_dir).mkdir(parents=True, exist_ok=True)
247
- if refs_to_checkout != "":
248
- try:
249
- # gitPython uses the branch argument the same whether you check out to a branch or a tag.
250
- repo = Repo.clone_from(git_url, target_dir, branch=refs_to_checkout)
251
- except GitCommandError as error:
252
- error_msg = error.args[2].decode("utf-8")
253
- if "Remote branch " + refs_to_checkout + " not found in upstream origin" in error_msg:
254
- # clone default branch, when non-existent branch or tag entered
255
- repo = Repo.clone_from(git_url, target_dir)
256
- clone_default_branch_flag = True
257
- else:
258
- repo = Repo.clone_from(git_url, target_dir)
259
- clone_default_branch_flag = True
260
246
 
261
- if refs_to_checkout != tag or clone_default_branch_flag:
262
- oss_version = repo.active_branch.name
263
- else:
264
- oss_version = repo.git.describe('--tags')
265
- logger.info(f"git checkout: {oss_version}")
266
-
267
- if platform.system() != "Windows":
268
- signal.alarm(0)
247
+ if git_url.startswith("ssh:") and not ssh_key:
248
+ msg = "Private git needs ssh_key"
249
+ success = False
269
250
  else:
270
- del alarm
251
+ if ssh_key:
252
+ logger.info(f"Download git with ssh_key:{git_url}")
253
+ git_ssh_cmd = f'ssh -i {ssh_key}'
254
+ with Git().custom_environment(GIT_SSH_COMMAND=git_ssh_cmd):
255
+ success, oss_version = download_git_repository(refs_to_checkout, git_url, target_dir, tag)
256
+ else:
257
+ if id and git_token:
258
+ try:
259
+ m = re.match(r"^(ht|f)tp(s?)\:\/\/", git_url)
260
+ protocol = m.group()
261
+ if protocol:
262
+ git_url = git_url.replace(protocol, f"{protocol}{id}:{git_token}@")
263
+ except Exception as error:
264
+ logger.info(f"Failed to insert id, token to git url:{error}")
265
+ success, oss_version = download_git_repository(refs_to_checkout, git_url, target_dir, tag)
266
+
267
+ logger.info(f"git checkout: {oss_version}")
268
+ refs_to_checkout = oss_version
269
+
270
+ if platform.system() != "Windows":
271
+ signal.alarm(0)
272
+ else:
273
+ del alarm
271
274
  except Exception as error:
275
+ success = False
272
276
  logger.warning(f"git clone - failed: {error}")
273
277
  msg = str(error)
274
- return False, msg, oss_name, refs_to_checkout
275
278
 
276
- return True, msg, oss_name, oss_version
279
+ return success, msg, oss_name, refs_to_checkout
277
280
 
278
281
 
279
282
  def download_wget(link, target_dir, compressed_only):
@@ -444,5 +447,36 @@ def gem_download(link, target_dir, checkout_to):
444
447
  return success
445
448
 
446
449
 
450
+ def main():
451
+ parser = argparse.ArgumentParser(description='FOSSLight Downloader', prog='fosslight_download', add_help=False)
452
+ parser.add_argument('-h', '--help', help='Print help message', action='store_true', dest='help')
453
+ parser.add_argument('-s', '--source', help='Source link to download', type=str, dest='source')
454
+ parser.add_argument('-t', '--target_dir', help='Target directory', type=str, dest='target_dir', default="")
455
+ parser.add_argument('-d', '--log_dir', help='Directory to save log file', type=str, dest='log_dir', default="")
456
+
457
+ src_link = ""
458
+ target_dir = os.getcwd()
459
+ log_dir = os.getcwd()
460
+
461
+ try:
462
+ args = parser.parse_args()
463
+ except SystemExit:
464
+ sys.exit(0)
465
+
466
+ if args.help:
467
+ print_help_msg_download()
468
+ if args.source:
469
+ src_link = args.source
470
+ if args.target_dir:
471
+ target_dir = args.target_dir
472
+ if args.log_dir:
473
+ log_dir = args.log_dir
474
+
475
+ if not src_link:
476
+ print_help_msg_download()
477
+ else:
478
+ cli_download_and_extract(src_link, target_dir, log_dir)
479
+
480
+
447
481
  if __name__ == '__main__':
448
482
  main()
@@ -31,7 +31,7 @@ def check_output_format(output='', format='', customized_format={}):
31
31
  format = format.lower()
32
32
  if format not in list(support_format.keys()):
33
33
  success = False
34
- msg = 'Enter the supported format with -f option: ' + ', '.join(list(support_format.keys()))
34
+ msg = '(-f option) Enter the supported format: ' + ', '.join(list(support_format.keys()))
35
35
  else:
36
36
  output_extension = support_format[format]
37
37
 
@@ -47,11 +47,11 @@ def check_output_format(output='', format='', customized_format={}):
47
47
  if format:
48
48
  if output_extension != basename_extension:
49
49
  success = False
50
- msg = f"Enter the same extension of output file(-o:'{output}') with format(-f:'{format}')."
50
+ msg = f"(-o & -f option) Enter the same extension of output file(-o:'{output}') with format(-f:'{format}')."
51
51
  else:
52
52
  if basename_extension not in support_format.values():
53
53
  success = False
54
- msg = 'Enter the supported file extension: ' + ', '.join(list(support_format.values()))
54
+ msg = '(-o option) Enter the supported file extension: ' + ', '.join(list(support_format.values()))
55
55
  if success:
56
56
  output_file = basename_file
57
57
  output_extension = basename_extension
@@ -79,7 +79,7 @@ def check_output_formats(output='', formats=[], customized_format={}):
79
79
  for format in formats:
80
80
  if format not in list(support_format.keys()):
81
81
  success = False
82
- msg = 'Enter the supported format with -f option: ' + ', '.join(list(support_format.keys()))
82
+ msg = '(-f option) Enter the supported format: ' + ', '.join(list(support_format.keys()))
83
83
  else:
84
84
  output_extensions.append(support_format[format])
85
85
 
@@ -95,11 +95,11 @@ def check_output_formats(output='', formats=[], customized_format={}):
95
95
  if formats:
96
96
  if basename_extension not in output_extensions:
97
97
  success = False
98
- msg = f"The format of output file(-o:'{output}') should be in the format list(-f:'{formats}')."
98
+ msg = f"(-o & -f option) The format of output file(-o:'{output}') should be in the format list(-f:'{formats}')."
99
99
  else:
100
100
  if basename_extension not in support_format.values():
101
101
  success = False
102
- msg = 'Enter the supported file extension: ' + ', '.join(list(support_format.values()))
102
+ msg = '(-o option) Enter the supported file extension: ' + ', '.join(list(support_format.values()))
103
103
  output_extensions.append(basename_extension)
104
104
  output_files = [basename_file for _ in range(len(output_extensions))]
105
105
  else:
@@ -128,7 +128,7 @@ def check_output_formats_v2(output='', formats=[], customized_format={}):
128
128
  for format in formats:
129
129
  if format not in list(support_format.keys()):
130
130
  success = False
131
- msg = 'Enter the supported format with -f option: ' + ', '.join(list(support_format.keys()))
131
+ msg = '(-f option) Enter the supported format with -f option: ' + ', '.join(list(support_format.keys()))
132
132
  else:
133
133
  output_extensions.append(support_format[format])
134
134
 
@@ -144,11 +144,11 @@ def check_output_formats_v2(output='', formats=[], customized_format={}):
144
144
  if formats:
145
145
  if basename_extension not in output_extensions:
146
146
  success = False
147
- msg = f"The format of output file(-o:'{output}') should be in the format list(-f:'{formats}')."
147
+ msg = f"(-o & -f option) The format of output file(-o:'{output}') should be in the format list(-f:'{formats}')."
148
148
  else:
149
149
  if basename_extension not in support_format.values():
150
150
  success = False
151
- msg = 'Enter the supported file extension: ' + ', '.join(list(support_format.values()))
151
+ msg = '(-o option) Enter the supported file extension: ' + ', '.join(list(support_format.values()))
152
152
  output_extensions.append(basename_extension)
153
153
  output_files = [basename_file for _ in range(len(output_extensions))]
154
154
  else:
@@ -199,6 +199,6 @@ def write_output_file(output_file_without_ext: str, file_extension: str, scan_it
199
199
  success, msg, result_file = write_yaml(result_file, scan_item, False)
200
200
  else:
201
201
  success = False
202
- msg = f'Not supported file extension({file_extension})'
202
+ msg = f'(-f option) Not supported file extension({file_extension})'
203
203
 
204
204
  return success, msg, result_file
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: fosslight-util
3
- Version: 2.1.1
3
+ Version: 2.1.2
4
4
  Summary: FOSSLight Util
5
5
  Home-page: https://github.com/fosslight/fosslight_util
6
6
  Author: LG Electronics
File without changes
File without changes
File without changes