Skip to content

Commit c872577

Browse files
authored
Merge pull request #2 from LGE-OSS/develop
Develop to include directly binaries that analyze license text
2 parents 03d4119 + eea4452 commit c872577

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+27
-49
lines changed

MANIFEST.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
include LICENSE
2+
include LICENSES/*

build.spec

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
block_cipher = None
44

55

6-
a = Analysis(['unified_script\\dependency_unified.py'],
7-
pathex=['C:\\Users\\dd-jy\\pythonProject\\fosslight_dependency'],
8-
binaries=[],
6+
a = Analysis(['dependency_unified.py'],
7+
pathex=['C:\\Users\\dd-jy\\pythonProject\\fosslight_dependency\\unified_script'],
8+
binaries=[('third_party\\askalono\\askalono.exe', 'third_party\\askalono')],
99
datas=[],
1010
hiddenimports=[],
1111
hookspath=[],

setup.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
if __name__ == "__main__":
1414
setup(
1515
name = 'fosslight_dependency',
16-
version = '3.0.2',
16+
version = '3.0.3',
1717
packages = find_packages(),
1818
description = 'FOSSLight Dependency',
1919
long_description = 'It is a script file to scan dependencies through package manager file and generate a result report.',
@@ -24,6 +24,8 @@
2424
classifiers = ['Programming Language :: Python :: 3.6',
2525
'License :: OSI Approved :: Apache Software License'],
2626
install_requires = required,
27+
package_data = {'unified_script':['third_party/nomos/nomossa','third_party/askalono/askalono.exe','third_party/askalono/askalono_macos']},
28+
include_package_data = True,
2729
entry_points = {
2830
"console_scripts": [
2931
"fosslight_dependency=unified_script.dependency_unified:main"

unified_script/dependency_unified.py

Lines changed: 19 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,18 @@
1818
from bs4 import BeautifulSoup
1919
import logging
2020
import requests
21+
import pkg_resources
2122

22-
VERSION = "3.0.2"
23+
VERSION = "3.0.3"
2324

2425
# Check the manifest file
2526
manifest_array = [["pip", "requirements.txt"], ["npm", "package.json"], ["maven", "pom.xml"],
2627
["gradle", "build.gradle"], ["pub", "pubspec.yaml"]]
2728

2829
# 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"
3233

3334

3435
class HelpStop(Exception):
@@ -509,45 +510,28 @@ def check_license_scanner(os_name):
509510
logging.info("Not supported OS to analyze license text with binary.")
510511
return
511512

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__)
517517

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
532520

533521

534522
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
540524

541-
if is_license_scanner:
525+
try:
542526
tmp_output_file_name = "tmp_license_scanner_output.txt"
543527

544528
if file_dir == "UNKNOWN":
545529
license_name = ""
546530
else:
547531
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
549533
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
551535
elif os_name == 'Windows':
552536
run_license_scanner = license_scanner_bin + " identify " + file_dir + " > " + tmp_output_file_name
553537
else:
@@ -578,7 +562,9 @@ def check_and_run_license_scanner(file_dir, os_name):
578562
else:
579563
license_name = ""
580564

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))
582568
license_name = ""
583569

584570
return license_name
@@ -707,10 +693,6 @@ def parse_and_generate_output_pip(tmp_file_name):
707693
except Exception as ex:
708694
logging.info("Error:"+ str(ex))
709695

710-
if os_name == 'Linux':
711-
if is_license_scanner:
712-
os.remove(license_scanner_bin)
713-
714696
if os.path.isdir(venv_tmp_dir):
715697
shutil.rmtree(venv_tmp_dir)
716698
logging.info("remove tmp directory: " + venv_tmp_dir)
@@ -912,10 +894,6 @@ def parse_and_generate_output_pub(tmp_file_name):
912894

913895
save_oss_report(wb)
914896

915-
if os_name != 'Windows':
916-
if is_license_scanner:
917-
os.remove(license_scanner_bin)
918-
919897
os.remove(tmp_license_txt_file_name)
920898

921899

@@ -992,7 +970,7 @@ def main_pub():
992970
def main():
993971
# Global variables
994972
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
996974

997975
# Init logging
998976
logging.basicConfig(level=logging.INFO, format='%(message)s')
@@ -1011,8 +989,6 @@ def main():
1011989
dn_url = "https://pypi.org/project/"
1012990
output_file_name = "pip_dependency_output.xlsx"
1013991
venv_tmp_dir = "venv_osc_dep_tmp"
1014-
license_scanner_first_flag = True
1015-
is_license_scanner = False
1016992

1017993
elif PACKAGE == "npm":
1018994
dn_url = "https://www.npmjs.com/package/"
@@ -1034,8 +1010,6 @@ def main():
10341010
dn_url = "https://pub.dev/packages/"
10351011
input_file_name = "lib/oss_licenses.dart"
10361012
output_file_name = "pub_dependency_output.xlsx"
1037-
license_scanner_first_flag = True
1038-
is_license_scanner = False
10391013
tmp_license_txt_file_name = "tmp_license.txt"
10401014

10411015
else:
File renamed without changes.

0 commit comments

Comments
 (0)