| 1 |
#!/usr/bin/env python3 |
| 2 |
# -*- coding: utf-8 -*- |
| 3 |
# |
| 4 |
# Copyright (C) 2009-2022 Jerry Casiano |
| 5 |
# |
| 6 |
# This program is free software: you can redistribute it and/or modify |
| 7 |
# it under the terms of the GNU General Public License as published by |
| 8 |
# the Free Software Foundation, either version 3 of the License, or |
| 9 |
# (at your option) any later version. |
| 10 |
# |
| 11 |
# This program is distributed in the hope that it will be useful, |
| 12 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
# GNU General Public License for more details. |
| 15 |
# |
| 16 |
# You should have received a copy of the GNU General Public License |
| 17 |
# along with this program. |
| 18 |
# |
| 19 |
# If not, see <http://www.gnu.org/licenses/gpl-3.0.txt>. |
| 20 |
|
| 21 |
import json |
| 22 |
import sys |
| 23 |
|
| 24 |
from glob import glob |
| 25 |
from io import StringIO |
| 26 |
from os import path |
| 27 |
|
| 28 |
NOTICE = """/* Do not edit directly. See build-aux directory */""" |
| 29 |
|
| 30 |
HEADER = """ |
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include <glib.h> |
| 34 |
#include <glib/gi18n-lib.h> |
| 35 |
|
| 36 |
#ifndef __GTK_DOC_IGNORE__ |
| 37 |
#define FONT_MANAGER_MAX_KEYWORD_ENTRIES 25 |
| 38 |
#endif |
| 39 |
|
| 40 |
static const struct |
| 41 |
{ |
| 42 |
const gchar *license; |
| 43 |
const gchar *license_url; |
| 44 |
const gchar *keywords[FONT_MANAGER_MAX_KEYWORD_ENTRIES]; |
| 45 |
} |
| 46 |
FontManagerLicenseData[] = |
| 47 |
{ |
| 48 |
""" |
| 49 |
|
| 50 |
FOOTER = """ |
| 51 |
}; |
| 52 |
|
| 53 |
#ifndef __GTK_DOC_IGNORE__ |
| 54 |
#define FONT_MANAGER_LICENSE_ENTRIES G_N_ELEMENTS(FontManagerLicenseData) |
| 55 |
#endif |
| 56 |
|
| 57 |
""" |
| 58 |
|
| 59 |
TRANSLATOR_COMMENT = """/* Translators : This is the name of a software license. */""" |
| 60 |
|
| 61 |
def write_license_entry (tmp, val) : |
| 62 |
if val is None: |
| 63 |
tmp.write(" NULL,\n") |
| 64 |
else: |
| 65 |
tmp.write(" \"{0}\",\n".format(val)) |
| 66 |
|
| 67 |
def get_license_entries () : |
| 68 |
license_dir = path.dirname(path.realpath(__file__)) |
| 69 |
tmp = StringIO() |
| 70 |
for filename in sorted(glob("*.json")): |
| 71 |
filepath = path.join(license_dir, filename) |
| 72 |
try: |
| 73 |
with open(filepath) as raw: |
| 74 |
obj = json.load(raw) |
| 75 |
for l in obj["License"]: |
| 76 |
tmp.write("\n {\n") |
| 77 |
tmp.write(' {0}\n'.format(TRANSLATOR_COMMENT)) |
| 78 |
tmp.write(' N_("{0}"),\n'.format(l["Name"])) |
| 79 |
write_license_entry(tmp, l["URL"]) |
| 80 |
tmp.write(" {\n") |
| 81 |
for k in l["Keywords"]: |
| 82 |
if k is None: |
| 83 |
tmp.write(" NULL\n") |
| 84 |
break |
| 85 |
else: |
| 86 |
tmp.write(" ") |
| 87 |
write_license_entry(tmp, k) |
| 88 |
tmp.write(" }\n },\n") |
| 89 |
except: |
| 90 |
print("Failed to load license : {0} : Skipping...".format(filepath)) |
| 91 |
contents = tmp.getvalue() |
| 92 |
tmp.close() |
| 93 |
return contents |
| 94 |
|
| 95 |
|
| 96 |
if __name__ == "__main__": |
| 97 |
with open(path.join(sys.argv[1], "font-manager-license.h"), "w") as header_file: |
| 98 |
header_file.write(NOTICE) |
| 99 |
header_file.write(HEADER) |
| 100 |
header_file.write(get_license_entries()) |
| 101 |
header_file.write(FOOTER) |