| @@ -1,15 +1,15 @@ | | | @@ -1,15 +1,15 @@ |
1 | #! @PYTHONBIN@ | | 1 | #! @PYTHONBIN@ |
2 | # $NetBSD: url2pkg.py,v 1.24 2019/10/27 19:19:55 rillig Exp $ | | 2 | # $NetBSD: url2pkg.py,v 1.25 2019/10/28 20:17:24 rillig Exp $ |
3 | | | 3 | |
4 | # Copyright (c) 2019 The NetBSD Foundation, Inc. | | 4 | # Copyright (c) 2019 The NetBSD Foundation, Inc. |
5 | # All rights reserved. | | 5 | # All rights reserved. |
6 | # | | 6 | # |
7 | # This code is derived from software contributed to The NetBSD Foundation | | 7 | # This code is derived from software contributed to The NetBSD Foundation |
8 | # by Roland Illig. | | 8 | # by Roland Illig. |
9 | # | | 9 | # |
10 | # Redistribution and use in source and binary forms, with or without | | 10 | # Redistribution and use in source and binary forms, with or without |
11 | # modification, are permitted provided that the following conditions | | 11 | # modification, are permitted provided that the following conditions |
12 | # are met: | | 12 | # are met: |
13 | # 1. Redistributions of source code must retain the above copyright | | 13 | # 1. Redistributions of source code must retain the above copyright |
14 | # notice, this list of conditions and the following disclaimer. | | 14 | # notice, this list of conditions and the following disclaimer. |
15 | # 2. Redistributions in binary form must reproduce the above copyright | | 15 | # 2. Redistributions in binary form must reproduce the above copyright |
| @@ -106,46 +106,94 @@ class Globals: | | | @@ -106,46 +106,94 @@ class Globals: |
106 | if len(candidates) != 1: | | 106 | if len(candidates) != 1: |
107 | return '' | | 107 | return '' |
108 | return str(candidates[0]).replace(str(self.pkgsrcdir), '../..') | | 108 | return str(candidates[0]).replace(str(self.pkgsrcdir), '../..') |
109 | | | 109 | |
110 | def bmake(self, *args: str) -> None: | | 110 | def bmake(self, *args: str) -> None: |
111 | self.debug('running bmake {0} in {1}', args, str(self.pkgdir)) | | 111 | self.debug('running bmake {0} in {1}', args, str(self.pkgdir)) |
112 | subprocess.check_call([self.make, *args], cwd=self.pkgdir) | | 112 | subprocess.check_call([self.make, *args], cwd=self.pkgdir) |
113 | | | 113 | |
114 | def show_var(self, varname: str) -> str: | | 114 | def show_var(self, varname: str) -> str: |
115 | output = subprocess.check_output((self.make, 'show-var', 'VARNAME=' + varname)) | | 115 | output = subprocess.check_output((self.make, 'show-var', 'VARNAME=' + varname)) |
116 | return output.decode('utf-8').strip() | | 116 | return output.decode('utf-8').strip() |
117 | | | 117 | |
118 | def pkgsrc_license(self, license_name: str) -> str: | | 118 | def pkgsrc_license(self, license_name: str) -> str: |
| | | 119 | comment = '' |
| | | 120 | |
| | | 121 | def suffix(suf: str, comm: str): |
| | | 122 | nonlocal license_name, comment |
| | | 123 | if comment == '' and license_name.endswith(suf): |
| | | 124 | comment = f'\t# {comm}' |
| | | 125 | license_name = license_name[:-len(suf)].rstrip() |
| | | 126 | |
| | | 127 | suffix('| file LICENSE', 'OR file LICENSE') |
| | | 128 | suffix('+ file LICENSE', '+ file LICENSE') |
| | | 129 | |
119 | known_licenses = ( | | 130 | known_licenses = ( |
120 | ('', | | 131 | ('2-clause-bsd', 'BSD-2', 'bsd2', 'BSD_2_clause'), |
121 | 'Apache Software License', # too unspecific; needs a version number | | 132 | # ('2-clause-bsd OR modified-bsd OR original-bsd', 'BSD'), # XXX: questionable |
122 | 'BSD'), # too unspecific, may be 2-clause, 3-clause, 4-clause | | 133 | ('acm-license', 'ACM'), |
123 | ('${PERL5_LICENSE}', 'perl'), | | 134 | ('apache-1.1 OR apache-2.0', 'APACHE'), |
124 | ('apache-2.0', 'Apache 2', 'Apache 2.0'), | | 135 | ('apache-2.0', 'Apache 2', 'Apache 2.0', 'apache2', |
| | | 136 | 'Apache Software License', 'Apache License 2.0', |
| | | 137 | 'Apache License (== 2.0)'), |
| | | 138 | ('apache-2.0 AND lppl-1.3c', 'apache2lppl', 'apache2lppl1.3c', |
| | | 139 | 'lppl1.3capache2'), |
| | | 140 | ('artistic OR artistic-2.0', 'ARTISTIC'), |
125 | ('artistic-2.0', 'artistic_2'), | | 141 | ('artistic-2.0', 'artistic_2'), |
126 | ('gnu-gpl-v3', 'GNU Lesser General Public License (LGPL), Version 3'), | | 142 | ('boost-license', 'BSL-1.0'), |
127 | ('gnu-lgpl-v2', 'LGPL'), | | 143 | ('cc-by-v4.0', 'cc-by-4'), |
| | | 144 | ('cc0-1.0-universal', 'CC0'), |
| | | 145 | ('gfsl', 'gfl'), |
| | | 146 | ('gnu-fdl-v1.3', 'fdl'), |
| | | 147 | ('gnu-gpl-v1', 'GPL-1'), |
| | | 148 | ('gnu-gpl-v1 OR gnu-gpl-v2 OR gnu-gpl-v3', 'GPL'), |
| | | 149 | ('gnu-gpl-v2', 'gpl', 'gpl2', 'GPL-2'), |
| | | 150 | ('gnu-gpl-v2 AND cc-by-sa-v4.0', 'gpl3+cc-by-sa-4'), |
| | | 151 | ('gnu-gpl-v2 AND lppl-1.3c', 'lpplgpl', 'gpl2lppl'), |
| | | 152 | ('gnu-gpl-v2 AND ofl-v1.1 AND lppl-1.3c', 'gplofllppl'), |
| | | 153 | ('gnu-gpl-v2 OR gnu-gpl-v3', 'GPL-2 | GPL-3', 'GPL (>= 2)', 'GPL (>= 2.0)'), |
| | | 154 | ('gnu-gpl-v3', 'gpl3', 'GPL-3', |
| | | 155 | 'GNU Lesser General Public License (LGPL), Version 3'), |
| | | 156 | ('gnu-gpl-v3', 'GPL (>= 3)'), |
| | | 157 | ('gnu-lgpl-v2', 'LGPL', 'LGPL-2'), |
| | | 158 | ('gnu-lgpl-v2 OR gnu-lgpl-v2.1 OR gnu-lgpl-v3', 'LGPL'), |
| | | 159 | ('gnu-lgpl-v2.1', 'LGPL-2.1'), |
| | | 160 | ('gnu-lgpl-v3', 'LGPL-3'), |
| | | 161 | ('gnu-lgpl-v2 OR gnu-lgpl-v3', 'LGPL-2 | LGPL-3'), |
| | | 162 | ('gnu-lgpl-v2 OR gnu-lgpl-v2.1 OR gnu-lgpl-v3', 'LGPL (>= 2)'), |
| | | 163 | ('lppl-1.0', 'lppl1'), |
| | | 164 | ('lppl-1.2', 'lppl1.2'), |
| | | 165 | ('lppl-1.3c', 'lppl', 'lppl1.3', 'lppl1.3c'), |
| | | 166 | ('lucent', 'LUCENT', 'Lucent Public License'), |
128 | ('mit', 'MIT', 'MIT License'), | | 167 | ('mit', 'MIT', 'MIT License'), |
129 | ('python-software-foundation', | | 168 | ('mit\t# + file LICENSE OR unlimited', 'MIT + file LICENSE | Unlimited'), |
130 | 'PSF', 'PSF license', 'Python Software Foundation License'), | | 169 | ('mit AND lppl-1.3c', 'mitlppl'), |
| | | 170 | ('modified-bsd', 'bsd3', 'BSD 3 clause', 'BSD_3_clause'), |
| | | 171 | ('ofl-v1.1', 'ofl'), |
| | | 172 | ('ofl-v1.1 AND lppl-1.3c', 'ofllppl1.3', 'ofllppl1.3c', 'ofllppl'), |
| | | 173 | ('${PERL5_LICENSE}', 'perl'), |
| | | 174 | ('postgresql-license', 'POSTGRESQL'), |
| | | 175 | ('public-domain', 'pd'), |
| | | 176 | ('python-software-foundation', 'PSF', 'PSF license', |
| | | 177 | 'Python Software Foundation License'), |
131 | ('zpl-2.1', 'ZPL 2.1'), | | 178 | ('zpl-2.1', 'ZPL 2.1'), |
132 | ) | | 179 | ) |
133 | | | 180 | |
134 | for known_license in known_licenses: | | 181 | lower = license_name.lower() |
135 | if license_name in known_license: | | 182 | for group in known_licenses: |
136 | return known_license[0] | | 183 | if lower in map(str.lower, group): |
137 | if (self.pkgsrcdir / 'licenses' / license_name).is_file(): | | 184 | return group[0] + comment |
138 | return license_name | | 185 | if (self.pkgsrcdir / 'licenses' / lower).is_file(): |
| | | 186 | return lower + comment |
139 | return '' | | 187 | return '' |
140 | | | 188 | |
141 | | | 189 | |
142 | class Lines: | | 190 | class Lines: |
143 | """ | | 191 | """ |
144 | A list of lines (typically from a Makefile, but other file types work as | | 192 | A list of lines (typically from a Makefile, but other file types work as |
145 | well) with high-level methods for manipulating variable assignments. | | 193 | well) with high-level methods for manipulating variable assignments. |
146 | """ | | 194 | """ |
147 | lines: List[str] | | 195 | lines: List[str] |
148 | | | 196 | |
149 | def __init__(self, *lines: str) -> None: | | 197 | def __init__(self, *lines: str) -> None: |
150 | self.lines = [] | | 198 | self.lines = [] |
151 | for line in lines: | | 199 | for line in lines: |