refactor: check license names before sending text

File might not exist.
This commit is contained in:
Ankush Menat 2023-08-05 11:15:11 +05:30
parent 011d21b4a3
commit 2ed85ca9f2

View file

@ -6,6 +6,12 @@ import os
import frappe
from frappe.model.document import Document
LICENSES = (
"GNU Affero General Public License",
"GNU General Public License",
"MIT License",
)
class Package(Document):
# begin: auto-generated types
@ -29,6 +35,7 @@ class Package(Document):
@frappe.whitelist()
def get_license_text(license_type):
with open(os.path.join(os.path.dirname(__file__), "licenses", license_type + ".md")) as textfile:
return textfile.read()
def get_license_text(license_type: str) -> str | None:
if license_type in LICENSES:
with open(os.path.join(os.path.dirname(__file__), "licenses", license_type + ".md")) as textfile:
return textfile.read()