|
20 | 20 | # ScanCode.io is a free software code scanning tool from nexB Inc. and others. |
21 | 21 | # Visit https://github.com/nexB/scancode.io for support and download. |
22 | 22 |
|
23 | | -import pprint |
24 | 23 | import sys |
25 | 24 | import tempfile |
26 | 25 |
|
27 | 26 | from django.conf import settings |
28 | 27 | from django.shortcuts import render |
29 | 28 | from django.views import generic |
30 | 29 |
|
31 | | -from scantext.forms import EditorForm |
| 30 | +from scantext.forms import LicenseForm |
32 | 31 |
|
33 | 32 | SCANCODE_BASE_URL = "https://github.com/nexB/scancode-toolkit/tree/develop/src/licensedcode/data/licenses" |
34 | 33 | SCANCODE_LICENSE_TEXT_URL = SCANCODE_BASE_URL + "/{}.LICENSE" |
|
39 | 38 |
|
40 | 39 |
|
41 | 40 | def license_scanview(request): |
42 | | - form = EditorForm() |
| 41 | + form = LicenseForm() |
43 | 42 | if request.method == "POST": |
44 | | - form = EditorForm(request.POST) |
| 43 | + form = LicenseForm(request.POST) |
45 | 44 | if form.is_valid(): |
46 | 45 | text = form.cleaned_data["input_text"] |
47 | | - # license_location = tempfile.NamedTemporaryFile(mode="w", prefix="license_scan_", dir=settings.SCANCODEIO_WORKSPACE_LOCATION) |
48 | | - # with license_location as f: |
49 | | - # f.write(text) |
50 | | - # f.flush() |
51 | | - # x=get_licenses(location=f) |
52 | | - # f.close() |
53 | | - # the get_licenses in the above code (line 56) returns this error |
54 | | - # error: |
55 | | - # expected str, bytes or os.PathLike object, not _TemporaryFileWrapper |
56 | | - # the below code just works |
57 | | - |
58 | | - expressions = get_licenses( |
59 | | - location="scantext/tests/data/LICENSES", |
60 | | - include_text=True, |
61 | | - license_text_diagnostics=True, |
62 | | - ) |
| 46 | + with tempfile.NamedTemporaryFile( |
| 47 | + mode="w", |
| 48 | + prefix="license_scan_", |
| 49 | + dir=settings.SCANCODEIO_WORKSPACE_LOCATION, |
| 50 | + ) as temp_file: |
| 51 | + temp_file.write(text) |
| 52 | + temp_file.flush() |
| 53 | + expressions = get_licenses( |
| 54 | + location=temp_file.name, |
| 55 | + include_text=True, |
| 56 | + license_text_diagnostics=True, |
| 57 | + ) |
| 58 | + temp_file.close() |
| 59 | + |
63 | 60 | return render( |
64 | 61 | request, |
65 | 62 | "scantext/license_detail.html", |
66 | 63 | { |
67 | 64 | "text": text, |
68 | | - "expr": expressions, |
| 65 | + "result": expressions, |
69 | 66 | }, |
70 | 67 | ) |
71 | | - return render(request, "scantext/license_scan.html", {"form": form}) |
| 68 | + return render(request, "scantext/license_scan_form.html", {"form": form}) |
72 | 69 |
|
73 | 70 |
|
74 | 71 | def get_licenses( |
|
0 commit comments