match licenses

noted that rights for gitenberg ebooks was not getting set properly
pull/1/head
eric 2016-07-14 19:02:22 -04:00
parent d7324cd1db
commit f110e02297
2 changed files with 18 additions and 2 deletions

View File

@ -898,7 +898,7 @@ def load_from_yaml(yaml_url, test_mode=False):
url=git_download_from_yaml_url(yaml_url,metadata._version,edition_name=book_name_prefix, url=git_download_from_yaml_url(yaml_url,metadata._version,edition_name=book_name_prefix,
format_= ebook_format), format_= ebook_format),
provider='Github', provider='Github',
rights = metadata.rights if metadata.rights in cc.LICENSE_LIST_ALL else None, rights = cc.match_license(metadata.rights),
format = ebook_format, format = ebook_format,
edition = edition, edition = edition,
# version = metadata._version # version = metadata._version

View File

@ -36,13 +36,14 @@ GRANTS = tuple([(item[0],item[3]) for item in INFO_ALL])
LICENSE_LIST = [item[0] for item in INFO_CC] LICENSE_LIST = [item[0] for item in INFO_CC]
LICENSE_LIST_ALL = [item[0] for item in INFO_ALL] LICENSE_LIST_ALL = [item[0] for item in INFO_ALL]
LICENSE_NAMES_ALL = [item[2] for item in INFO_ALL]
LICENSE_URLS_ALL = [item[3] for item in INFO_ALL]
FACET_LIST = [item[1] for item in INFO_ALL] FACET_LIST = [item[1] for item in INFO_ALL]
RIGHTS_ALIAS = { RIGHTS_ALIAS = {
"Public domain in the USA.":"PD-US", "Public domain in the USA.":"PD-US",
} }
class CCLicense(): class CCLicense():
@staticmethod @staticmethod
def url(license): def url(license):
@ -146,3 +147,18 @@ def license_value(facet):
return LICENSE_LIST_ALL[FACET_LIST.index(facet)] return LICENSE_LIST_ALL[FACET_LIST.index(facet)]
else: else:
return '' return ''
def match_license(license_string):
if license_string in LICENSE_LIST_ALL:
return license_string
try:
l = LICENSE_NAMES_ALL.index(license_string)
return INFO_ALL[l][0]
except ValueError:
pass
try:
l = LICENSE_URLS_ALL.index(license_string)
return INFO_ALL[l][0]
except ValueError:
pass
return RIGHTS_ALIAS.get(license_string, None)