# -*- coding: utf-8 -*-

# Verify that each license added to this list has 'OSI Approved?: Y' on https://spdx.org/licenses/
LICENSE_ALIASES = dict((key.lower(), value) for (key, value) in {
    'https://polymer.github.io/LICENSE.txt': 'BSD-3-Clause', # Verified on 26-Sep-2016
    'http://polymer.github.io/LICENSE.txt': 'BSD-3-Clause', # Verified on 26-Sep-2016
    'Academic Free License v1.1': 'AFL-1.1',
    'Academic Free License v1.2': 'AFL-1.2',
    'Academic Free License v2.0': 'AFL-2.0',
    'Academic Free License v2.1': 'AFL-2.1',
    'Academic Free License v3.0': 'AFL-3.0',
    'Adaptive Public License 1.0': 'APL-1.0',
    'Apache License 1.1': 'Apache-1.1',
    'Apache License 2.0': 'Apache-2.0',
    'Apple Public Source License 1.0': 'APSL-1.0',
    'Apple Public Source License 1.1': 'APSL-1.1',
    'Apple Public Source License 1.2': 'APSL-1.2',
    'Apple Public Source License 2.0': 'APSL-2.0',
    'Artistic License 1.0': 'Artistic-1.0',
    'Artistic License 1.0 (Perl)': 'Artistic-1.0-Perl',
    'Artistic License 1.0 w/clause 8': 'Artistic-1.0-cl8',
    'Artistic License 2.0': 'Artistic-2.0',
    'Attribution Assurance License': 'AAL',
    'Boost Software License 1.0': 'BSL-1.0',
    'BSD 2-clause "Simplified" License': 'BSD-2-Clause',
    'BSD 3-clause "New" or "Revised" License': 'BSD-3-Clause',
    'BSD Zero Clause License': '0BSD',
    'CeCILL Free Software License Agreement v2.1': 'CECILL-2.1',
    'CNRI Python License': 'CNRI-Python',
    'Common Development and Distribution License 1.0': 'CDDL-1.0',
    'Common Public Attribution License 1.0': 'CPAL-1.0',
    'Common Public License 1.0': 'CPL-1.0',
    'Computer Associates Trusted Open Source License 1.1': 'CATOSL-1.1',
    'CUA Office Public License v1.0': 'CUA-OPL-1.0',
    'Eclipse Public License 1.0': 'EPL-1.0',
    'Educational Community License v1.0': 'ECL-1.0',
    'Educational Community License v2.0': 'ECL-2.0',
    'Eiffel Forum License v1.0': 'EFL-1.0',
    'Eiffel Forum License v2.0': 'EFL-2.0',
    'Entessa Public License v1.0': 'Entessa',
    'EU DataGrid Software License': 'EUDatagrid',
    'European Union Public License 1.1': 'EUPL-1.1',
    'Fair License': 'Fair',
    'Frameworx Open License 1.0': 'Frameworx-1.0',
    'GNU Affero General Public License v3.0': 'AGPL-3.0',
    'GNU General Public License v2.0 only': 'GPL-2.0',
    'GNU General Public License v3.0 only': 'GPL-3.0',
    'GNU Lesser General Public License v2.1 only': 'LGPL-2.1',
    'GNU Lesser General Public License v3.0 only': 'LGPL-3.0',
    'GNU Library General Public License v2 only': 'LGPL-2.0',
    'Historic Permission Notice and Disclaimer': 'HPND',
    'IBM Public License v1.0': 'IPL-1.0',
    'Intel Open Source License': 'Intel',
    'IPA Font License': 'IPA',
    'ISC License': 'ISC',
    'LaTeX Project Public License v1.3c': 'LPPL-1.3c',
    'Licence Libre du Québec – Permissive version 1.1': 'LiLiQ-P-1.1',
    'Licence Libre du Québec – Réciprocité forte version 1.1': 'LiLiQ-Rplus-1.1',
    'Licence Libre du Québec – Réciprocité version 1.1': 'LiLiQ-R-1.1',
    'Lucent Public License v1.02': 'LPL-1.02',
    'Lucent Public License Version 1.0': 'LPL-1.0',
    'Microsoft Public License': 'MS-PL',
    'Microsoft Reciprocal License': 'MS-RL',
    'MirOS Licence': 'MirOS',
    'MIT License': 'MIT',
    'Motosoto License': 'Motosoto',
    'Mozilla Public License 1.0': 'MPL-1.0',
    'Mozilla Public License 1.1': 'MPL-1.1',
    'Mozilla Public License 2.0': 'MPL-2.0',
    'Mozilla Public License 2.0 (no copyleft exception)': 'MPL-2.0-no-copyleft-exception',
    'Multics License': 'Multics',
    'NASA Open Source Agreement 1.3': 'NASA-1.3',
    'Naumen Public License': 'Naumen',
    'Nethack General Public License': 'NGPL',
    'Nokia Open Source License': 'Nokia',
    'Non-Profit Open Software License 3.0': 'NPOSL-3.0',
    'NTP License': 'NTP',
    'OCLC Research Public License 2.0': 'OCLC-2.0',
    'Open Group Test Suite License': 'OGTSL',
    'Open Software License 1.0': 'OSL-1.0',
    'Open Software License 2.0': 'OSL-2.0',
    'Open Software License 2.1': 'OSL-2.1',
    'Open Software License 3.0': 'OSL-3.0',
    'OSET Public License version 2.1': 'OSET-PL-2.1',
    'PHP License v3.0': 'PHP-3.0',
    'PostgreSQL License': 'PostgreSQL',
    'Python License 2.0': 'Python-2.0',
    'Q Public License 1.0': 'QPL-1.0',
    'RealNetworks Public Source License v1.0': 'RPSL-1.0',
    'Reciprocal Public License 1.1': 'RPL-1.1',
    'Reciprocal Public License 1.5': 'RPL-1.5',
    'Ricoh Source Code Public License': 'RSCPL',
    'SIL Open Font License 1.1': 'OFL-1.1',
    'Simple Public License 2.0': 'SimPL-2.0',
    'Sleepycat License': 'Sleepycat',
    'Sun Industry Standards Source License v1.1': 'SISSL',
    'Sun Public License v1.0': 'SPL-1.0',
    'Sybase Open Watcom Public License 1.0': 'Watcom-1.0',
    'Universal Permissive License v1.0': 'UPL-1.0',
    'University of Illinois/NCSA Open Source License': 'NCSA',
    'Vovida Software License v1.0': 'VSL-1.0',
    'W3C Software Notice and License (2002-12-31)': 'W3C',
    'X.Net License': 'Xnet',
    'zlib License': 'Zlib',
    'Zope Public License 2.0': 'ZPL-2.0',
}.iteritems())

SPDX_IDENTIFIERS = dict([(identifier.lower(), identifier) for identifier in set(LICENSE_ALIASES.values())])

def validate_spdx(license_name):
  spdx_identifier = LICENSE_ALIASES.get(license_name.lower(), license_name.lower()).lower()
  return SPDX_IDENTIFIERS.get(spdx_identifier, None)
