18
18
from bs4 import BeautifulSoup
19
19
import logging
20
20
import requests
21
+ import pkg_resources
21
22
22
- VERSION = "3.0.2 "
23
+ VERSION = "3.0.3 "
23
24
24
25
# Check the manifest file
25
26
manifest_array = [["pip" , "requirements.txt" ], ["npm" , "package.json" ], ["maven" , "pom.xml" ],
26
27
["gradle" , "build.gradle" ], ["pub" , "pubspec.yaml" ]]
27
28
28
29
# binary url to check license text
29
- license_scanner_url_linux = "https://github.com/LGE-OSS/fosslight_dependency/raw/main/ third_party/nomos/nomossa"
30
- license_scanner_url_macos = "https://github.com/LGE-OSS/fosslight_dependency/raw/main/ third_party/askalono/askalono_macos"
31
- license_scanner_url_windows = "https://github.com/LGE-OSS/fosslight_dependency/raw/main/ third_party/ askalono/ askalono.exe"
30
+ license_scanner_url_linux = "third_party/nomos/nomossa"
31
+ license_scanner_url_macos = "third_party/askalono/askalono_macos"
32
+ license_scanner_url_windows = "third_party\\ askalono\\ askalono.exe"
32
33
33
34
34
35
class HelpStop (Exception ):
@@ -509,45 +510,28 @@ def check_license_scanner(os_name):
509
510
logging .info ("Not supported OS to analyze license text with binary." )
510
511
return
511
512
512
- license_scanner_bin = os .path .basename (license_scanner_url )
513
-
514
-
515
- def check_to_exist_license_scanner ():
516
- global license_scanner_bin , license_scanner_url
513
+ try :
514
+ base_path = sys ._MEIPASS
515
+ except Exception :
516
+ base_path = os .path .dirname (__file__ )
517
517
518
- fileobject = requests .get (license_scanner_url )
519
- if fileobject .status_code != 200 :
520
- logging .error ("### Error Message ###" )
521
- logging .error ("Downloading " + license_scanner_bin + " is failed." )
522
- return False
523
- else :
524
- with open (license_scanner_bin , 'wb' ) as f :
525
- f .write (fileobject .content )
526
-
527
- if os .path .isfile (license_scanner_bin ) == 1 :
528
- os .chmod (license_scanner_bin ,0o755 )
529
- return True
530
- else :
531
- return False
518
+ data_path = os .path .join (base_path , license_scanner_url )
519
+ license_scanner_bin = data_path
532
520
533
521
534
522
def check_and_run_license_scanner (file_dir , os_name ):
535
- global license_scanner_first_flag , is_license_scanner , license_scanner_bin
536
-
537
- if license_scanner_first_flag :
538
- is_license_scanner = check_to_exist_license_scanner ()
539
- license_scanner_first_flag = False
523
+ global license_scanner_bin
540
524
541
- if is_license_scanner :
525
+ try :
542
526
tmp_output_file_name = "tmp_license_scanner_output.txt"
543
527
544
528
if file_dir == "UNKNOWN" :
545
529
license_name = ""
546
530
else :
547
531
if os_name == 'Linux' :
548
- run_license_scanner = "./" + license_scanner_bin + " " + file_dir + " > " + tmp_output_file_name
532
+ run_license_scanner = license_scanner_bin + " " + file_dir + " > " + tmp_output_file_name
549
533
elif os_name == 'Darwin' :
550
- run_license_scanner = "./" + license_scanner_bin + " identify " + file_dir + " > " + tmp_output_file_name
534
+ run_license_scanner = license_scanner_bin + " identify " + file_dir + " > " + tmp_output_file_name
551
535
elif os_name == 'Windows' :
552
536
run_license_scanner = license_scanner_bin + " identify " + file_dir + " > " + tmp_output_file_name
553
537
else :
@@ -578,7 +562,9 @@ def check_and_run_license_scanner(file_dir, os_name):
578
562
else :
579
563
license_name = ""
580
564
581
- else :
565
+ except Exception as ex :
566
+ logging .info ("There are some errors for the license scanner binary" )
567
+ logging .info ("Error:" + str (ex ))
582
568
license_name = ""
583
569
584
570
return license_name
@@ -707,10 +693,6 @@ def parse_and_generate_output_pip(tmp_file_name):
707
693
except Exception as ex :
708
694
logging .info ("Error:" + str (ex ))
709
695
710
- if os_name == 'Linux' :
711
- if is_license_scanner :
712
- os .remove (license_scanner_bin )
713
-
714
696
if os .path .isdir (venv_tmp_dir ):
715
697
shutil .rmtree (venv_tmp_dir )
716
698
logging .info ("remove tmp directory: " + venv_tmp_dir )
@@ -912,10 +894,6 @@ def parse_and_generate_output_pub(tmp_file_name):
912
894
913
895
save_oss_report (wb )
914
896
915
- if os_name != 'Windows' :
916
- if is_license_scanner :
917
- os .remove (license_scanner_bin )
918
-
919
897
os .remove (tmp_license_txt_file_name )
920
898
921
899
@@ -992,7 +970,7 @@ def main_pub():
992
970
def main ():
993
971
# Global variables
994
972
global PACKAGE , output_file_name , input_file_name , CUR_PATH , OUTPUT_RESULT_DIR , MANUAL_DETECT , OUTPUT_CUSTOM_DIR , dn_url , PIP_ACTIVATE , PIP_DEACTIVATE
995
- global license_scanner_first_flag , is_license_scanner , license_scanner_url , license_scanner_bin , venv_tmp_dir , pom_backup , is_maven_first_try , tmp_license_txt_file_name
973
+ global license_scanner_url , license_scanner_bin , venv_tmp_dir , pom_backup , is_maven_first_try , tmp_license_txt_file_name
996
974
997
975
# Init logging
998
976
logging .basicConfig (level = logging .INFO , format = '%(message)s' )
@@ -1011,8 +989,6 @@ def main():
1011
989
dn_url = "https://pypi.org/project/"
1012
990
output_file_name = "pip_dependency_output.xlsx"
1013
991
venv_tmp_dir = "venv_osc_dep_tmp"
1014
- license_scanner_first_flag = True
1015
- is_license_scanner = False
1016
992
1017
993
elif PACKAGE == "npm" :
1018
994
dn_url = "https://www.npmjs.com/package/"
@@ -1034,8 +1010,6 @@ def main():
1034
1010
dn_url = "https://pub.dev/packages/"
1035
1011
input_file_name = "lib/oss_licenses.dart"
1036
1012
output_file_name = "pub_dependency_output.xlsx"
1037
- license_scanner_first_flag = True
1038
- is_license_scanner = False
1039
1013
tmp_license_txt_file_name = "tmp_license.txt"
1040
1014
1041
1015
else :
0 commit comments