Exemplo n.º 1
0
 def download_scancode(self):
     print(self.SCANCODE_PATH)
     os.chdir(os.path.abspath(self.directory_to_scan))
     download_command = "pip download {0} --no-deps".format(
         SCANCODE_DOWNLOAD_PATH)
     scancode_exists = os.path.exists(self.SCANCODE_PATH)
     if not scancode_exists:
         if is_connected():
             os.popen(download_command).read()
             zip_ref = zipfile.ZipFile("scancode-toolkit-2.2.1.zip", 'r')
             zip_ref.extractall(".")
             zip_ref.close()
         else:
             print_to_command_line(
                 "You are not online, we cannot download scanner utilites. You need to be online for the first run.",
                 "failure")
             return
     self.EXTRACT_CODE_PATH = os.path.join(self.SCANCODE_PATH,
                                           'extractcode')
     self.CONFIG_PATH = os.path.join(self.SCANCODE_PATH, 'configure')
     self.SCANCODE_EXE_PATH = os.path.join(self.SCANCODE_PATH, 'scancode')
     # make extractcode executable
     os.popen("chmod 777 {0}".format(self.EXTRACT_CODE_PATH)).read()
     os.popen("chmod 777 {0}".format(self.CONFIG_PATH)).read()
     os.popen("chmod 777 {0}".format(self.SCANCODE_EXE_PATH)).read()
     self.extract_content_of_temp_dir()
     self.scan()
Exemplo n.º 2
0
 def get_files_to_parse(self):
     if not self.in_tests:
         print_to_command_line("Project directory", "title")
         print_to_command_line(self.project_dir, "success")
     for file_name_to_check in self.files_to_check:
         self.files_to_parse.append(
         check_file_in_dir(self.project_dir, file_name_to_check))
     self.parse_npm_file()
Exemplo n.º 3
0
 def parse_file(self):
     if not self.in_tests:
         print_to_command_line("File path", "title")
         print_to_command_line(self.file_dir, "information")
     package_json_content = None
     with open(self.file_dir) as json_data:
         json_deps_data = json.load(json_data)
         package_json_content = json_deps_data
     return package_json_content
Exemplo n.º 4
0
 def _packages_downloader(packages, download_dir):
     package_downloader = NpmPackageDownloader(download_dir)
     if is_connected():
         package_downloader.download_multiple(packages)
     else:
         print_to_command_line(
             "You are not online, we cannot download project dependencies. You need to be online.",
             "failure")
         return
Exemplo n.º 5
0
def analyse_dir(verbose, package_dir):
    npm_deps = []
    project_info = determine_build_tool(normalize_path(package_dir))
    if "npm" in project_info[0]:
        print_to_command_line("NPM Project", "success")
        NpmPackageManager(normalize_path(package_dir))
    if "pip" in project_info[0]:
        print_to_command_line("Python Project", "success")
        PipPackageManager(normalize_path(package_dir))
    return project_info
Exemplo n.º 6
0
 def parse_file(self):
     if not self.in_tests:
         print_to_command_line("File path", "title")
         print_to_command_line(self.file_dir, "success")
     try:
         # Python 2.x compatibility
         if not isinstance(self.file_dir, basestring):
             self.file_dir = self.file_dir.read()
     except NameError:
         # Python 3.x only
         if not isinstance(self.file_dir, str):
             self.file_dir = self.file_dir.read()
     for line in self.file_dir.splitlines():
         line = line.strip()
     return
Exemplo n.º 7
0
 def download(self):
     # Create setup file before downloading the packages to a directory
     touch_cmd = "touch {0}setup.py".format(normalize_path(self.dest_dir))
     # Run the Command
     if is_connected():
         cmd_output = os.popen("pip download -r {0} -d {1}".format(
             self.req_file, self.dest_dir)).read()
         # delete setup file after packages have been downloaded
         os.popen("rm -f {0}setup.py".format(self.dest_dir))
         self.download_output = cmd_output
         return cmd_output
     else:
         print_to_command_line(
             "You are not online, we cannot download project dependencies. You need to be online.",
             "failure")
         return
Exemplo n.º 8
0
 def scan(self):
     """Scan given directory, and output the result as an spdx document in the directory being scanned."""
     print_to_command_line("directory to scan", "title")
     print_to_command_line(self.directory_to_scan, "success")
     os.chdir(os.path.abspath(self.SCANCODE_PATH))
     ignore_pattern = "**/scancode-toolkit-2.2.1/**"
     spdx_rdf_filename = '{0}{1}-build-tool-rdf.spdx'.format(
         self.directory_to_scan,
         self.directory_to_scan.split("/")[-2])
     spdx_tv_filename = '{0}{1}-build-tool-tv.spdx'.format(
         self.directory_to_scan,
         self.directory_to_scan.split("/")[-2])
     rdf_scan_str = "./scancode --format spdx-rdf  {0} {1} --ignore {2}".format(
         self.directory_to_scan, spdx_rdf_filename, ignore_pattern)
     tv_scan_str = "./scancode --format spdx-tv  {0} {1} --ignore {2}".format(
         self.directory_to_scan, spdx_tv_filename, ignore_pattern)
     os.popen(rdf_scan_str).read()
     os.popen(tv_scan_str).read()
     delete_tmp_dir(self.directory_to_scan)
     return