-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrefresh_datajs.py
297 lines (269 loc) · 11.6 KB
/
refresh_datajs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
#! /usr/bin/env python3
# Copyright (c) 2016, Jan Brohl <[email protected]>
# All rights reserved.
import json
import interfaces.ckan
import datetime
from typing import List, Dict
license_id_to_name = {
"public-domain": "public domain",
"AFL-3.0": "Academic Free License 3.0",
"AGPL-3.0": "GNU Affero General Public License 3.0",
"Apache": "Apache License",
"Apache-1.0": "Apache License 1.0",
"Apache-2.0": "Apache License 2.0",
"APSL-2.0": "Apple Public Source License 2.0",
"Artistic": "Artistic License",
"Artistic-1.0": "Artistic License 1.0",
"Artistic-2.0": "Artistic License 2.0",
"BSD-2-clause": "BSD 2-clause \"Simplified\" License",
"BSD-3-clause": "BSD 3-clause \"New\" or \"Revised\" License",
"BSD-4-clause": "BSD 4-clause \"Original\" or \"Old\" License",
"ISC": "ISC License",
"CC-BY": "Creative Commons Attribution",
"CC-BY-1.0": "Creative Commons Attribution 1.0",
"CC-BY-2.0": "Creative Commons Attribution 2.0",
"CC-BY-2.5": "Creative Commons Attribution 2.5",
"CC-BY-3.0": "Creative Commons Attribution 3.0",
"CC-BY-4.0": "Creative Commons Attribution 4.0",
"CC-BY-SA": "Creative Commons Attribution Share Alike",
"CC-BY-SA-1.0": "Creative Commons Attribution Share Alike 1.0",
"CC-BY-SA-2.0": "Creative Commons Attribution Share Alike 2.0",
"CC-BY-SA-2.5": "Creative Commons Attribution Share Alike 2.5",
"CC-BY-SA-3.0": "Creative Commons Attribution Share Alike 3.0",
"CC-BY-SA-4.0": "Creative Commons Attribution Share Alike 4.0",
"CC-BY-NC": "Creative Commons Attribution Non Commercial",
"CC-BY-NC-1.0": "Creative Commons Attribution Non Commercial 1.0",
"CC-BY-NC-2.0": "Creative Commons Attribution Non Commercial 2.0",
"CC-BY-NC-2.5": "Creative Commons Attribution Non Commercial 2.5",
"CC-BY-NC-3.0": "Creative Commons Attribution Non Commercial 3.0",
"CC-BY-NC-4.0": "Creative Commons Attribution Non Commercial 4.0",
"CC-BY-NC-SA": "Creative Commons Attribution Non Commercial Share Alike",
"CC-BY-NC-SA-1.0": "Creative Commons Attribution Non Commercial Share Alike 1.0",
"CC-BY-NC-SA-2.0": "Creative Commons Attribution Non Commercial Share Alike 2.0",
"CC-BY-NC-SA-2.5": "Creative Commons Attribution Non Commercial Share Alike 2.5",
"CC-BY-NC-SA-3.0": "Creative Commons Attribution Non Commercial Share Alike 3.0",
"CC-BY-NC-SA-4.0": "Creative Commons Attribution Non Commercial Share Alike 4.0",
"CC-BY-NC-ND": "Creative Commons Attribution Non Commercial No Derivatives",
"CC-BY-NC-ND-1.0": "Creative Commons Attribution Non Commercial No Derivatives 1.0",
"CC-BY-NC-ND-2.0": "Creative Commons Attribution Non Commercial No Derivatives 2.0",
"CC-BY-NC-ND-2.5": "Creative Commons Attribution Non Commercial No Derivatives 2.5",
"CC-BY-NC-ND-3.0": "Creative Commons Attribution Non Commercial No Derivatives 3.0",
"CC-BY-NC-ND-4.0": "Creative Commons Attribution Non Commercial No Derivatives 4.0",
"CC-BY-ND": "Creative Commons Attribution No Derivatives",
"CC-BY-ND-1.0": "Creative Commons Attribution No Derivatives 1.0",
"CC-BY-ND-2.0": "Creative Commons Attribution No Derivatives 2.0",
"CC-BY-ND-2.5": "Creative Commons Attribution No Derivatives 2.5",
"CC-BY-ND-3.0": "Creative Commons Attribution No Derivatives 3.0",
"CC-BY-ND-4.0": "Creative Commons Attribution No Derivatives 4.0",
"CC0": "Creative Commons Zero 1.0 Universal",
"CDDL": "Common Development and Distribution License",
"CPL": "Common Public License",
"EFL-1.0": "Eiffel Forum License 1.0",
"EFL-2.0": "Eiffel Forum License 2.0",
"Expat": "MIT License (Expat)",
"MIT": "MIT License (Expat)",
"GPL-1.0": "GNU General Public License 1.0 only",
"GPL-2.0": "GNU General Public License 2.0 only",
"GPL-3.0": "GNU General Public License 3.0 only",
"LGPL-2.0": "GNU Library General Public License 2 only",
"LGPL-2.1": "GNU Library General Public License 2.1 only",
"LGPL-3.0": "GNU Library General Public License 3 only",
"GFDL-1.0": "GNU Free Documentation License 1.0",
"GFDL-1.1": "GNU Free Documentation License 1.1",
"GFDL-1.2": "GNU Free Documentation License 1.2",
"GFDL-1.3": "GNU Free Documentation License 1.3",
"GFDL-NIV-1.0": "GNU Free Documentation License, with no Front-Cover or Back-Cover Texts or Invariant Sections v1.0",
"GFDL-NIV-1.1": "GNU Free Documentation License, with no Front-Cover or Back-Cover Texts or Invariant Sections v1.1",
"GFDL-NIV-1.2": "GNU Free Documentation License, with no Front-Cover or Back-Cover Texts or Invariant Sections v1.2",
"GFDL-NIV-1.3": "GNU Free Documentation License, with no Front-Cover or Back-Cover Texts or Invariant Sections v1.3",
"LPPL-1.0": "LaTeX Project Public License 1.0",
"LPPL-1.1": "LaTeX Project Public License 1.1",
"LPPL-1.2": "LaTeX Project Public License 1.2",
"LPPL-1.3c": "LaTeX Project Public License 1.3c",
"MPL-1.0": "Mozilla Public License 1.0",
"MPL-1.1": "Mozilla Public License 1.1",
"MPL-2.0": "Mozilla Public License 2.0",
"Ms-PL": "Microsoft Public License",
"Ms-RL": "Microsoft Reciprocal License",
"Perl": "Artistic License 1.0 (Perl)",
"Python-2.0": "Python License 2.0",
"QPL-1.0": "Q Public License 1.0",
"Unlicense": "The Unlicense",
"W3C": "W3C Software Notice and License (2002-12-31)",
"WTFPL": "Do What The F*ck You Want To Public License",
"Zlib": "zlib License",
"Zope": "Zope Public License",
"open-source": "Other Open Source Initiative (OSI) approved license",
"restricted": "All rights reserved",
"unrestricted": "Not an OSI approved license, but not restricted",
"unknown": "License not provided"
}
mandatory_fields = [
"identifier",
"name",
"abstract",
"author",
"ksp_version",
"license",
"version",
"download"
]
modes_autofill = {
"github": [
"name",
"abstract",
"author",
"download",
"download_hash",
"download_size",
"resources.homepage",
"resources.repository",
"resources.bugtracker",
"version",
"license"
],
"http": [
"download",
"download_content_type",
"download_hash",
"download_size"
],
"other": [],
"spacedock": [
"abstract",
"author",
"download",
"download_hash",
"download_size",
"ksp_version",
"license",
"name",
"resources.homepage",
"resources.repository",
"resources.spacedock",
"resources.x_screenshot",
"version"
]
}
# Keep these lists synched with https://github.com/KSP-CKAN/CKAN/wiki/Suggested-Tags
tags_mod_types: List[str] = [
'parts',
'physics',
'plugin',
'app',
'config',
'library',
'flags',
'agency',
'suits',
]
tags_mod_descriptors: List[str] = [
'control',
'convenience',
'information',
'editor',
'planet-pack',
'graphics',
'sound',
'resources',
'science',
'tech-tree',
'career',
'combat',
'comms',
'buildings',
'crewed',
'uncrewed',
'stock-inventory',
'first-person',
]
tags_descriptions: Dict[str, str] = {
'parts': 'Mods that provide new pieces that you can add to your planes or rockets',
'physics': 'Mods that change something about the physics, such as atmospheric lift/drag, re-entry heating, or craft rigidity',
'plugin': 'Mods that contain a DLL',
'app': 'Mods that include or work best with something executable or web-based that runs outside of KSP',
'config': 'Mods that add alternative or default configuration, such as tech trees or ModuleManager patches',
'library': 'Mods that do nothing by themselves, but provide functionality for other mods',
'flags': 'Mods that provide new flags',
'agency': 'Mods that add agencies that can submit contracts',
'suits': 'Mods that add custom suits',
'control': 'Mods that add alternative methods of controlling crafts, such as autopilot features or programmability',
'convenience': 'Mods that make some game actions easier, such as shortcut toolbar buttons',
'information': 'Mods that provide extended information about your craft, orbit, planets, etc.',
'editor': 'Mods that add or change something in the editors',
'planet-pack': 'Mods that modify the solar system by adding, removing, or changing planets or moons or their orbits',
'graphics': 'Mods that change the visuals, usually with new models or textures',
'sound': 'Mods that change the music or sound effects',
'resources': 'Mods focused on ISRU and resource management',
'science': 'Mods that add new ways to collect or use science',
'tech-tree': 'Mods that extend or overhaul the tech tree hierarchy',
'career': 'Mods that enhance career gameplay, often by providing or hiding contracts',
'combat': 'Mods that provide armor, weapons, or combat-oriented mechanics',
'comms': 'Mods that alter some aspect of communication between vessels',
'buildings': 'Mods that add static ground structures',
'crewed': 'Mods that enhance crewed gameplay, along the lines of life support, colony-building, and station-building',
'uncrewed': 'Mods that enhance uncrewed gameplay',
'stock-inventory': 'Mods that enhance the stock inventory system',
'first-person': 'Mods that provide or enhance a first-person view, such as IVAs and props',
}
js = """
var license_name_to_id = {};
for (var k in license_id_to_name) {
license_name_to_id[license_id_to_name[k]] = k;
}
var license_ids = Object.keys(license_id_to_name);
license_ids.sort();
var license_names = Object.keys(license_name_to_id);
license_names.sort();
var ckan_ids = [];
var ckan_name_to_id = {};
for (var i in ckan_names_ids) {
var id = ckan_names_ids[i][1];
var name = ckan_names_ids[i][0];
if (!ckan_ids.includes(id)) {
ckan_ids.push(id);
}
ckan_name_to_id[name] = id;
}
ckan_ids.sort();
var ckan_names = Object.keys(ckan_name_to_id);
ckan_names.sort();
"""
def main():
ckan = interfaces.ckan.full()
ckan_ids = sorted(set(e["identifier"] for e in ckan))
ckan_names_ids = sorted(
set((e["name"].strip(), e["identifier"]) for e in ckan))
ckan_schema = interfaces.ckan.json_schema()
now = datetime.datetime.utcnow()
now_str = now.strftime("%Y-%m-%dT%H:%M:%S")
with open("static/data.js", "w", encoding="utf-8") as f:
f.write("// auto-generated on %s UTC - see refresh_datajs.py\n\"use strict\";\n\nvar data_updated = \"%s\";\n\n" % (now_str, now_str))
f.write("var mandatory_fields = ")
json.dump(mandatory_fields, f, sort_keys=True)
f.write(";\n\n")
f.write("var license_id_to_name = ")
json.dump(license_id_to_name, f, sort_keys=True)
f.write(";\n\n")
f.write("var modes_autofill = ")
json.dump(modes_autofill, f, sort_keys=True)
f.write(";\n\n")
f.write("var ckan_schema = ")
json.dump(ckan_schema, f, sort_keys=True)
f.write(";\n\n")
f.write("var ckan_names_ids = ")
json.dump(ckan_names_ids, f, sort_keys=True)
f.write(";\n\n")
f.write("var tags_mod_types = ")
json.dump(tags_mod_types, f)
f.write(";\n\n")
f.write("var tags_mod_descriptors = ")
json.dump(tags_mod_descriptors, f)
f.write(";\n\n")
f.write("var tags_descriptions = ")
json.dump(tags_descriptions, f)
f.write(";\n\n")
f.write(js)
if __name__ == "__main__":
main()