diff options
Diffstat (limited to 'README.md')
| -rw-r--r-- | README.md | 100 |
1 files changed, 84 insertions, 16 deletions
@@ -5,7 +5,20 @@ SPDX-FileCopyrightText: 2026 M. Shulhan <ms@kilabit.info> # spdxconv -spdxconv is a tool to convert and insert the SPDX identifiers. +spdxconv is a tool to convert existing license and copyright into +[SPDX](https://spdx.dev/) +or insert the new identifiers. + +This tool works in tandem with [REUSE software](https://reuse.software). + +Features, + +- Customizable values for default license identifier and copyright +- Customizable pattern for setting comment syntax based on file name +- Customizable pattern for searching and capturing existing license through + regex +- Customizable pattern for searching and capturing existing copyright year, + author, and contact through regex ## Background @@ -59,6 +72,41 @@ license_identifier = file_copyright_text = max_line_match = 10 +[match-file-comment] +pattern = "^.*\\.(adoc|asciidoc|c|cc|cpp|cs|dart|go|h|hh|hpp|java|js|jsx|jsonc|kt|kts|php|rs|sass|scss|swift|ts|tsx)$" +comment_prefix = "//" + +[match-file-comment] +pattern = "^.*\\.(bash|csh|dockerfile|env|gitignore|hcl|ipynb|make|pl|pm|py|ps1|rb|sh|tf|yaml|yml|zsh)$" +prefix = "#" + +[match-file-comment] +pattern = "^.*\\.(css)$" +prefix = "/*" +suffix = "*/" + +[match-file-comment] +pattern = "^.*\\.(fxml|htm|html|html5|kml|markdown|md|xml)$" +prefix = "<!--" +suffix = "-->" + +[match-file-comment] +pattern = "^.*\\.(lua|sql)$" +prefix = "--" + +[match-file-comment] +pattern = "^.*\\.(rst)$" +prefix = ".." + +[match-file-comment] +pattern = "^.*\\.(tex)$" +prefix = "%" + +# File name that match with this pattern will have the ".license" file +# created. +[match-file-comment] +pattern = "^.*\\.(apk|app|bz2|csv|doc|docx|exe|gif|gz|jpeg|jpg|json|pdf|png|ppt|pptx|svg|svgz|tar|tgz|xls|xlsx|zip)$" + [match-license] pattern = "^(//+|#+)\\s+(.*)governed by a BSD-style(.*)$" license_identifier = BSD-3-Clause @@ -69,8 +117,12 @@ pattern = "^(//+|#+)\\s+Copyright\\s+(?<year>\\d{4}),?\\s+(?<author>.*)\\s+<*(?< ``` The configuration use the `ini` file format. -You need to modify it by filling the "default" section, and can add another -match-license and match-copyright pattern as required. +You need to modify it by filling the "default" section before running the +`scan` or `apply` command. + +You can add match-file-comment, match-license and match-copyright +section as required, or modify the existing one to match with your use case. + For quick references here are several rules that you need to be aware of, - The regex value must be enclosed in double quote @@ -93,12 +145,28 @@ top and bottom of file for `SPDX-*` identifiers, `match-license`, and `match-copyright` before the program insert the default values. The default values is 10. +### match-file-comment section + +The first thing that the program do is to detect which comment string to be +used when inserting SPDX identifiers in the file. + +For each pattern in the "match-file-comment" section, the program will match +it with file name to get the comment prefix and suffix to be used later. + +User can add their own "match-file-comment" section as they like or modify +the existing one. + +The "match-file-comment" can have empty prefix and suffix. +That means, if the file name match, it will create new file with ".license" +suffix that contains SPDX identifiers only, instead of inserting to the file +directly. + ### match-license section <!-- REUSE-IgnoreStart --> -The first thing that the program do is search for line that match -with "SPDX-License-Identifier:". +After program detect the file comment syntax to use, then it will search for +line that match with "SPDX-License-Identifier:". <!-- REUSE-IgnoreEnd --> @@ -208,22 +276,22 @@ identifier, ... ``` -Regular group are the file where program can detect the syntax of comment -inside it. +Regular group are list of file where program can detect its file comment to +be used. Program will insert the new SPDX identifiers into the file using the -detected comment syntax. +comment syntax. -Binary group are non-text file, for example images (like jpg, png) or -executable files. -For binary file, program will create new file with the same name as binary -file plus additional suffix ".license". +Binary group are list of non-text file, for example images (like jpg, png) +or executable files. +For binary file, program will create new file with the same name plus +additional suffix ".license". Inside those "$name.license" file, the new SPDX identifiers will be inserted as defined in the report. -Unknown group are regular file where program cannot detect the comment -syntax used inside it. -This files will not be processed, it is listed here so user can modify the -configuration and rerun the scan command for the next cycle. +Unknown group are list of file where program cannot detect the file comment +to be used. +This files will not be processed, it is listed here so user can inspect, +modify the configuration, and rerun the scan command for the next cycle. ## apply command |
