You can pull the set of identifiers from [https://wking.github.io/fsf-api/licenses.json](https://wking.github.io/fsf-api/licenses.json).
-You can pull an individual license from `https://wking.github.io/fsf-api/{id}.json`, for example [https://wking.github.io/fsf-api/Expat.json](https://wking.github.io/fsf-api/Expat.json).
+You can pull an individual license from a few places:
+
+* Using their FSF ID:
+
+ https://wking.github.io/fsf-api/{id}.json
+
+ For example [https://wking.github.io/fsf-api/Expat.json](https://wking.github.io/fsf-api/Expat.json).
+
+* Using a non-FSF ID, according to the mapping between other scheme and the FSF scheme asserted by this API:
+
+ https://wking.github.io/fsf-api/{scheme}/{id}.json
+
+ For example [https://wking.github.io/fsf-api/spdx/MIT.json](https://wking.github.io/fsf-api/spdx/MIT.json).
+ This API currently [attempts](#caveats) to maintain the following mappings:
+
+ * `spdx`, using [the SPDX identifiers][spdx-list].
## Caveats
[osi-api-non-canon-2]: https://github.com/OpenSourceOrg/licenses/issues/47
[osi-api-noncanon-1]: https://github.com/OpenSourceOrg/licenses/tree/f7ff223f9694ca0d5114fc82e43c74b5c5087891#is-this-authoritative
[osi-api]: https://api.opensource.org/
+[spdx-list]: https://spdx.org/licenses/
# SPDX-License-Identifier: MIT
import glob
+import itertools
import json
import os
import sys
def save(licenses, dir=os.curdir):
os.makedirs(dir, exist_ok=True)
- for path in glob.glob(os.path.join(dir, '*.json')):
+ if sys.version_info >= (3, 5):
+ paths = glob.glob(os.path.join(dir, '**', '*.json'), recursive=True)
+ else:
+ paths = itertools.chain(
+ glob.glob(os.path.join(dir, '*.json')),
+ glob.glob(os.path.join(dir, '*', '*.json')),
+ )
+ for path in paths:
os.remove(path)
- index = {}
- for id, license in licenses.items():
- index[id] = {'name': license['name']}
- if 'identifiers' in license:
- index[id]['identifiers'] = license['identifiers']
+ index = sorted(licenses.keys())
with open(os.path.join(dir, 'licenses.json'), 'w') as f:
- json.dump(obj=index, fp=f, indent=2, sort_keys=True)
+ json.dump(obj=index, fp=f, indent=2)
f.write('\n')
for id, license in licenses.items():
license = license.copy()
if 'tags' in license:
license['tags'] = sorted(license['tags'])
- with open(os.path.join(dir, '{}.json'.format(id)), 'w') as f:
+ license_path = os.path.join(dir, '{}.json'.format(id))
+ with open(license_path, 'w') as f:
json.dump(obj=license, fp=f, indent=2, sort_keys=True)
f.write('\n')
+ for scheme, identifier in license.get('identifiers', {}).items():
+ scheme_dir = os.path.join(dir, scheme)
+ os.makedirs(scheme_dir, exist_ok=True)
+ id_path = os.path.join(scheme_dir, '{}.json'.format(identifier))
+ os.link(license_path, id_path)
if __name__ == '__main__':