class SpdxRdfOutput(OutputPlugin): options = [ CommandLineOption(('--spdx-rdf', ), type=FileOptionType(lazy=True, mode='w', encoding='utf-8'), metavar='FILE', help='Write scan output as SPDX RDF to FILE.', help_group=OUTPUT_GROUP) ] def is_enabled(self, spdx_rdf, **kwargs): return spdx_rdf def process_codebase(self, codebase, spdx_rdf, **kwargs): check_sha1(codebase) files = self.get_files(codebase, **kwargs) header = codebase.get_or_create_current_header() tool_name = header.tool_name tool_version = header.tool_version notice = header.notice input = kwargs.get('input', '') # NOQA write_spdx(spdx_rdf, files, tool_name, tool_version, notice, input, as_tagvalue=False)
class JsonPrettyOutput(OutputPlugin): options = [ CommandLineOption( ( '--json-pp', 'output_json_pp', ), type=FileOptionType(mode='wb', lazy=True), metavar='FILE', help='Write scan output as pretty-printed JSON to FILE.', help_group=OUTPUT_GROUP, sort_order=10), ] def is_enabled(self, output_json_pp, **kwargs): return output_json_pp def process_codebase(self, codebase, output_json_pp, **kwargs): files = self.get_files(codebase, **kwargs) write_json(codebase, files, output_file=output_json_pp, pretty=True, **kwargs)
class JsonLinesOutput(OutputPlugin): options = [ CommandLineOption(( '--json-lines', 'output_json_lines', ), type=FileOptionType(mode=mode, lazy=True), metavar='FILE', help='Write scan output as JSON Lines to FILE.', help_group=OUTPUT_GROUP, sort_order=15), ] def is_enabled(self, output_json_lines, **kwargs): return output_json_lines # TODO: reuse the json output code and merge that in a single plugin def process_codebase(self, codebase, output_json_lines, **kwargs): # NOTE: we write as binary, not text files = self.get_files(codebase, **kwargs) codebase.add_files_count_to_current_header() headers = OrderedDict(headers=codebase.get_headers()) simplejson_kwargs = dict(iterable_as_array=True, encoding='utf-8', separators=( comma, colon, )) output_json_lines.write(simplejson.dumps(headers, **simplejson_kwargs)) output_json_lines.write(eol) for name, value in codebase.attributes.to_dict().items(): if value: smry = {name: value} output_json_lines.write( simplejson.dumps(smry, **simplejson_kwargs)) output_json_lines.write(eol) for scanned_file in files: scanned_file_line = {file_key: [scanned_file]} output_json_lines.write( simplejson.dumps(scanned_file_line, **simplejson_kwargs)) output_json_lines.write(eol)
class CsvOutput(OutputPlugin): options = [ CommandLineOption(('--csv', ), type=FileOptionType(mode='wb', lazy=True), metavar='FILE', help='Write scan output as CSV to FILE.', help_group=OUTPUT_GROUP, sort_order=30), ] def is_enabled(self, csv, **kwargs): return csv def process_codebase(self, codebase, csv, **kwargs): results = self.get_files(codebase, **kwargs) write_csv(results, csv)
class JsonCompactOutput(OutputPlugin): options = [ CommandLineOption(('--json', 'output_json',), type=FileOptionType(mode='wb', lazy=True), metavar='FILE', help='Write scan output as compact JSON to FILE.', help_group=OUTPUT_GROUP, sort_order=10), ] def is_enabled(self, output_json, **kwargs): return output_json def process_codebase(self, codebase, output_json, **kwargs): results = get_results(codebase, as_list=False, **kwargs) write_json(results, output_file=output_json, pretty=False)
class HtmlOutput(OutputPlugin): options = [ CommandLineOption(('--html',), type=FileOptionType(mode='w', encoding='utf-8', lazy=True), metavar='FILE', help='Write scan output as HTML to FILE.', help_group=OUTPUT_GROUP, sort_order=50), ] def is_enabled(self, html, **kwargs): return html def process_codebase(self, codebase, html, **kwargs): results = self.get_files(codebase, **kwargs) version = codebase.get_or_create_current_header().tool_version template_loc = join(TEMPLATES_DIR, 'html', 'template.html') output_file = html write_templated(output_file, results, version, template_loc)
class CustomTemplateOutput(OutputPlugin): options = [ CommandLineOption(('--custom-output', ), type=FileOptionType(mode='w', encoding='utf-8', lazy=True), required_options=['custom_template'], metavar='FILE', help='Write scan output to FILE formatted with ' 'the custom Jinja template file.', help_group=OUTPUT_GROUP, sort_order=60), CommandLineOption( ('--custom-template', ), type=click.Path(exists=True, file_okay=True, dir_okay=False, readable=True, path_type=PATH_TYPE), required_options=['custom_output'], metavar='FILE', help='Use this Jinja template FILE as a custom template.', help_group=OUTPUT_GROUP, sort_order=65), ] def is_enabled(self, custom_output, custom_template, **kwargs): return custom_output and custom_template def process_codebase(self, codebase, custom_output, custom_template, **kwargs): results = self.get_files(codebase, **kwargs) version = codebase.get_or_create_current_header().tool_version if on_linux: custom_template = fsencode(custom_template) template_loc = custom_template output_file = custom_output write_templated(output_file, results, version, template_loc)
class HtmlAppOutput(OutputPlugin): """ Write scan output as a mini HTML application. """ options = [ CommandLineOption(('--html-app',), type=FileOptionType(mode='w', encoding='utf-8', lazy=True), metavar='FILE', help='(DEPRECATED: use the ScanCode Workbench app instead ) ' 'Write scan output as a mini HTML application to FILE.', help_group=OUTPUT_GROUP, sort_order=1000), ] def is_enabled(self, html_app, **kwargs): return html_app def process_codebase(self, codebase, input, html_app, **kwargs): # NOQA results = self.get_files(codebase, **kwargs) version = codebase.get_or_create_current_header().tool_version output_file = html_app scanned_path = input create_html_app(output_file, results, version, scanned_path)