8
8
import os
9
9
import sys
10
10
import argparse
11
- from openpyxl import load_workbook , Workbook
12
11
import platform
13
12
import shutil
14
13
import subprocess
15
14
import json
16
15
import re
17
16
from xml .etree .ElementTree import parse
18
17
from bs4 import BeautifulSoup
19
- import pkg_resources
20
18
import yaml
21
19
from lastversion import lastversion
22
20
from fosslight_util .set_log import init_log
23
21
from datetime import datetime
24
- from . import __version__
22
+ from ._version import __version__
25
23
from fosslight_util .write_excel import write_excel_and_csv
26
24
from ._help import print_help_msg
27
25
@@ -173,7 +171,7 @@ def check_virtualenv_arg():
173
171
174
172
python_version = check_python_version ()
175
173
176
- venv_path = os .path .join (CUR_PATH ,venv_tmp_dir )
174
+ venv_path = os .path .join (CUR_PATH , venv_tmp_dir )
177
175
178
176
if python_version == 2 :
179
177
create_venv_command = "virtualenv -p python " + venv_tmp_dir
@@ -327,7 +325,8 @@ def open_input_file():
327
325
328
326
logger .error ("Please check the below thing first." )
329
327
logger .error (" 1.Did you run the license-maven-plugin?" )
330
- logger .error (" 2.Or if your project has the customized build output directory, then use '-c' option with your customized build output directory name" )
328
+ logger .error (" 2.Or if your project has the customized build output directory, \
329
+ then use '-c' option with your customized build output directory name" )
331
330
logger .error (" $ fosslight_dependency -c output" )
332
331
sys .exit (1 )
333
332
@@ -343,8 +342,8 @@ def close_input_file(input_fp):
343
342
def make_custom_json (tmp_custom_json ):
344
343
with open (tmp_custom_json , 'w' , encoding = 'utf8' ) as custom :
345
344
custom .write (
346
- "{\n \t \" name\" : \" \" ,\n \t \" version\" : \" \" ,\n \t \" licenses\" : \" \" ,\n \t \" repository\" : \" \" , \n \t \" url \" : \" \" , \n \t \" copyright \" : \" \" , \n \t \" licenseText \" : \" \" \n } \n " . encode (). decode (
347
- "utf-8" ))
345
+ "{\n \t \" name\" : \" \" ,\n \t \" version\" : \" \" ,\n \t \" licenses\" : \" \" ,\n \t \" repository\" : \
346
+ \" \" , \n \t \" url \" : \" \" , \n \t \" copyright \" : \" \" , \n \t \" licenseText \" : \" \" \n } \n " . encode (). decode ( "utf-8" ))
348
347
349
348
350
349
def start_license_checker ():
@@ -443,7 +442,7 @@ def resource_path(relative_path):
443
442
444
443
def check_license_scanner (os_name ):
445
444
global license_scanner_url , license_scanner_bin
446
-
445
+
447
446
if os_name == 'Linux' :
448
447
license_scanner_url = license_scanner_url_linux
449
448
elif os_name == 'Darwin' :
@@ -508,7 +507,7 @@ def check_and_run_license_scanner(file_dir, os_name):
508
507
509
508
except Exception as ex :
510
509
logger .info ("There are some errors for the license scanner binary" )
511
- logger .info ("Error:" + str (ex ))
510
+ logger .info ("Error:" + str (ex ))
512
511
license_name = ""
513
512
514
513
return license_name
@@ -574,8 +573,8 @@ def parse_and_generate_output_pip(tmp_file_name):
574
573
sheet_list = {}
575
574
576
575
try :
577
- with open (tmp_file_name , 'r' , encoding = 'utf-8' ) as json_file :
578
- json_data = json .load (json_file )
576
+ with open (tmp_file_name , 'r' , encoding = 'utf-8' ) as json_file :
577
+ json_data = json .load (json_file )
579
578
580
579
sheet_list ["SRC" ] = []
581
580
@@ -596,7 +595,7 @@ def parse_and_generate_output_pip(tmp_file_name):
596
595
sheet_list ["SRC" ].append (['pip' , oss_name , oss_version , license_name , dn_loc , homepage , '' , '' , '' ])
597
596
598
597
except Exception as ex :
599
- logger .error ("Error:" + str (ex ))
598
+ logger .error ("Error:" + str (ex ))
600
599
601
600
if os .path .isdir (venv_tmp_dir ):
602
601
shutil .rmtree (venv_tmp_dir )
@@ -608,7 +607,7 @@ def parse_and_generate_output_pip(tmp_file_name):
608
607
def parse_and_generate_output_npm (tmp_file_name ):
609
608
with open (tmp_file_name , 'r' , encoding = 'utf8' ) as json_file :
610
609
json_data = json .load (json_file )
611
-
610
+
612
611
sheet_list = {}
613
612
sheet_list ["SRC" ] = []
614
613
@@ -625,19 +624,14 @@ def parse_and_generate_output_npm(tmp_file_name):
625
624
license_name = ''
626
625
627
626
oss_version = d ['version' ]
628
-
627
+
629
628
if d ['repository' ]:
630
629
dn_loc = d ['repository' ]
631
630
else :
632
631
dn_loc = dn_url + oss_init_name + '/v/' + oss_version
633
632
634
633
homepage = dn_url + oss_init_name
635
634
636
- if d ['copyright' ]:
637
- copyright_text = d ['copyright' ]
638
- else :
639
- copyright_text = ''
640
-
641
635
multi_license = check_multi_license (license_name )
642
636
643
637
if multi_license == 1 :
@@ -649,7 +643,7 @@ def parse_and_generate_output_npm(tmp_file_name):
649
643
license_name = license_name .replace ("," , "" )
650
644
651
645
sheet_list ["SRC" ].append (['package.json' , oss_name , oss_version , license_name , dn_loc , homepage , '' , '' , '' ])
652
-
646
+
653
647
return sheet_list
654
648
655
649
@@ -741,7 +735,7 @@ def preprocess_pub_result(input_file):
741
735
742
736
743
737
def parse_and_generate_output_pub (tmp_file_name ):
744
- global license_scanner_bin , tmp_license_txt_file_name
738
+ global license_scanner_bin , tmp_license_txt_file_name
745
739
746
740
json_txt = preprocess_pub_result (tmp_file_name )
747
741
json_data = json .loads (json_txt )
@@ -752,7 +746,6 @@ def parse_and_generate_output_pub(tmp_file_name):
752
746
os_name = check_os ()
753
747
check_license_scanner (os_name )
754
748
755
- idx = 1
756
749
for key in json_data :
757
750
oss_origin_name = json_data [key ]['name' ]
758
751
oss_name = "pub:" + oss_origin_name
@@ -790,7 +783,7 @@ def compile_pods_item(pods_item, spec_repo_list, pod_in_sepc_list, pod_not_in_sp
790
783
oss_info = []
791
784
oss_info .append (oss_name )
792
785
oss_info .append (oss_version )
793
-
786
+
794
787
if oss_name in spec_repo_list :
795
788
pod_in_sepc_list .append (oss_info )
796
789
spec_repo_list .remove (oss_name )
@@ -815,22 +808,22 @@ def parse_and_generate_output_cocoapods(input_fp):
815
808
for pods_list in podfile_yaml ['PODS' ]:
816
809
if not isinstance (pods_list , str ):
817
810
for pods_list_key , pods_list_item in pods_list .items ():
818
- pod_in_sepc_list , spec_repo_list , pod_not_in_spec_list = compile_pods_item (pods_list_key , spec_repo_list , pod_in_sepc_list , pod_not_in_spec_list )
811
+ pod_in_sepc_list , spec_repo_list , pod_not_in_spec_list = \
812
+ compile_pods_item (pods_list_key , spec_repo_list , pod_in_sepc_list , pod_not_in_spec_list )
819
813
else :
820
- pod_in_sepc_list , spec_repo_list , pod_not_in_spec_list = compile_pods_item (pods_list , spec_repo_list , pod_in_sepc_list , pod_not_in_spec_list )
814
+ pod_in_sepc_list , spec_repo_list , pod_not_in_spec_list = \
815
+ compile_pods_item (pods_list , spec_repo_list , pod_in_sepc_list , pod_not_in_spec_list )
821
816
822
817
if len (spec_repo_list ) != 0 :
823
818
for spec_in_item in spec_repo_list :
824
819
spec_oss_name_adding_core = spec_in_item + "/Core"
825
820
for pod_not_item in pod_not_in_spec_list :
826
821
if spec_oss_name_adding_core == pod_not_item [0 ]:
827
822
pod_in_sepc_list .append ([spec_in_item , pod_not_item [1 ]])
828
-
829
823
830
824
sheet_list = {}
831
825
sheet_list ["SRC" ] = []
832
826
833
- idx = 1
834
827
for pod_oss in pod_in_sepc_list :
835
828
836
829
search_oss_name = ""
@@ -840,7 +833,7 @@ def parse_and_generate_output_cocoapods(input_fp):
840
833
else :
841
834
search_oss_name += alphabet_oss
842
835
843
- command = 'pod spec which --regex ' + '^' + search_oss_name + '$'
836
+ command = 'pod spec which --regex ' + '^' + search_oss_name + '$'
844
837
spec_which = os .popen (command ).readline ()
845
838
if spec_which .startswith ('[!]' ):
846
839
logger .error ("### Error Message ###" )
@@ -849,16 +842,14 @@ def parse_and_generate_output_cocoapods(input_fp):
849
842
850
843
file_path = spec_which .rstrip ().split (os .path .sep )
851
844
if file_path [0 ] == '' :
852
- file_path_without_version = os .path .join (os .sep ,* file_path [:- 2 ])
845
+ file_path_without_version = os .path .join (os .sep , * file_path [:- 2 ])
853
846
else :
854
847
file_path_without_version = os .path .join (* file_path [:- 2 ])
855
- spec_file_path = os .path .join (file_path_without_version ,pod_oss [1 ],file_path [- 1 ])
848
+ spec_file_path = os .path .join (file_path_without_version , pod_oss [1 ], file_path [- 1 ])
856
849
857
850
with open (spec_file_path , 'r' , encoding = 'utf8' ) as json_file :
858
851
json_data = json .load (json_file )
859
852
860
- keys = [key for key in json_data ]
861
-
862
853
oss_origin_name = json_data ['name' ]
863
854
oss_name = "cocoapods:" + oss_origin_name
864
855
oss_version = json_data ['version' ]
@@ -901,7 +892,7 @@ def main_pip():
901
892
# Remove temporary output file.
902
893
if os .path .isfile (tmp_file_name ):
903
894
os .remove (tmp_file_name )
904
-
895
+
905
896
return sheet_list
906
897
907
898
@@ -935,7 +926,7 @@ def main_maven():
935
926
936
927
if not is_maven_first_try :
937
928
clean_run_maven_plugin_output ()
938
-
929
+
939
930
return sheet_list
940
931
941
932
@@ -965,7 +956,7 @@ def main_pub():
965
956
966
957
967
958
def main_cocoapods ():
968
-
959
+
969
960
# open Podfile.lock
970
961
input_fp = open_input_file ()
971
962
@@ -977,14 +968,16 @@ def main_cocoapods():
977
968
978
969
979
970
def main ():
980
-
981
- global PACKAGE , output_file_name , input_file_name , CUR_PATH , OUTPUT_RESULT_DIR , MANUAL_DETECT , OUTPUT_CUSTOM_DIR , dn_url , PIP_ACTIVATE , PIP_DEACTIVATE
982
- global license_scanner_url , license_scanner_bin , venv_tmp_dir , pom_backup , is_maven_first_try , tmp_license_txt_file_name , source_type , logger
971
+
972
+ global PACKAGE , output_file_name , input_file_name , CUR_PATH , OUTPUT_RESULT_DIR , \
973
+ MANUAL_DETECT , OUTPUT_CUSTOM_DIR , dn_url , PIP_ACTIVATE , PIP_DEACTIVATE
974
+ global license_scanner_url , license_scanner_bin , venv_tmp_dir , pom_backup , \
975
+ is_maven_first_try , tmp_license_txt_file_name , source_type , logger
983
976
984
977
start_time = datetime .now ().strftime ('%Y-%m-%d_%H-%M-%S' )
985
978
986
979
parse_option ()
987
- logger = init_log (os .path .join (OUTPUT_RESULT_DIR , "fosslight_dependency_log_" + start_time + ".txt" ), True , 20 , 10 )
980
+ logger = init_log (os .path .join (OUTPUT_RESULT_DIR , "fosslight_dependency_log_" + start_time + ".txt" ), True , 20 , 10 )
988
981
989
982
# Check the latest version
990
983
latest_version = lastversion .has_update (repo = "fosslight_dependency" , at = 'pip' , current_version = __version__ )
@@ -1032,7 +1025,7 @@ def main():
1032
1025
input_file_name = "Podfile.lock"
1033
1026
output_file_name = "cocoapods_dependency_output"
1034
1027
source_type = ['git' , 'http' , 'svn' , 'hg' ]
1035
-
1028
+
1036
1029
else :
1037
1030
logger .error ("### Error Message ###" )
1038
1031
logger .error ("You enter the wrong first argument." )
0 commit comments