2017-11-23 14:10:28 -03:00
|
|
|
#!/usr/bin/env python
|
2018-01-20 19:44:13 -05:00
|
|
|
'''
|
|
|
|
Simple DirectMedia Layer
|
|
|
|
Copyright (C) 2017-2018 Philippe Groarke <philippe.groarke@gmail.com>
|
|
|
|
This software is provided 'as-is', without any express or implied
|
|
|
|
warranty. In no event will the authors be held liable for any damages
|
|
|
|
arising from the use of this software.
|
|
|
|
Permission is granted to anyone to use this software for any purpose,
|
|
|
|
including commercial applications, and to alter it and redistribute it
|
|
|
|
freely, subject to the following restrictions:
|
|
|
|
1. The origin of this software must not be misrepresented; you must not
|
|
|
|
claim that you wrote the original software. If you use this software
|
|
|
|
in a product, an acknowledgment in the product documentation would be
|
|
|
|
appreciated but is not required.
|
|
|
|
2. Altered source versions must be plainly marked as such, and must not be
|
|
|
|
misrepresented as being the original software.
|
|
|
|
3. This notice may not be removed or altered from any source distribution.
|
|
|
|
'''
|
2016-07-06 04:17:47 +05:30
|
|
|
|
|
|
|
import sys
|
2018-01-08 21:07:44 -05:00
|
|
|
# if sys.version_info[0] != 3:
|
|
|
|
# print("This script requires Python 3.")
|
|
|
|
# exit(1)
|
|
|
|
|
2018-01-08 22:25:11 -05:00
|
|
|
from os import path
|
2018-01-10 13:22:57 -05:00
|
|
|
from collections import OrderedDict
|
2018-01-08 21:07:44 -05:00
|
|
|
import string
|
2017-10-07 16:34:07 -04:00
|
|
|
import collections
|
2017-10-07 20:12:35 -04:00
|
|
|
import shutil
|
2017-10-07 20:56:20 -04:00
|
|
|
import argparse
|
2018-01-08 21:07:44 -05:00
|
|
|
import csv
|
|
|
|
import re
|
2018-01-20 19:13:15 -05:00
|
|
|
import copy
|
2016-07-06 04:17:47 +05:30
|
|
|
|
2018-01-20 16:35:37 -05:00
|
|
|
FILE_HEADER = "# Game Controller DB for SDL in %s format\n" \
|
2018-01-09 14:05:23 -05:00
|
|
|
"# Source: https://github.com/gabomdq/SDL_GameControllerDB\n"
|
2018-01-08 21:07:44 -05:00
|
|
|
|
2018-12-01 10:52:53 -05:00
|
|
|
sdl_version = "2.0.9"
|
2018-01-20 16:35:37 -05:00
|
|
|
|
2018-01-10 13:22:57 -05:00
|
|
|
mappings_dict = OrderedDict([
|
|
|
|
("Windows", {}),
|
|
|
|
("Mac OS X", {}),
|
|
|
|
("Linux", {}),
|
|
|
|
("Android", {}),
|
2018-01-10 13:46:20 -05:00
|
|
|
("iOS", {}),
|
2018-01-10 13:22:57 -05:00
|
|
|
])
|
2018-01-08 21:07:44 -05:00
|
|
|
|
2018-01-20 19:13:15 -05:00
|
|
|
header_mappings_dict = copy.deepcopy(mappings_dict)
|
|
|
|
|
2018-01-09 16:20:44 -05:00
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
parser.add_argument("input_file", help="database file to check, " \
|
|
|
|
"ex. gamecontrollerdb.txt")
|
|
|
|
parser.add_argument("--format", help="sorts, formats and removes duplicates",
|
|
|
|
action="store_true")
|
|
|
|
parser.add_argument("--convert_guids", help="convert Windows and macOS " \
|
|
|
|
"GUIDs to the newer SDL 2.0.5 format",
|
|
|
|
action="store_true")
|
|
|
|
parser.add_argument("--add_missing_platform", help="adds a platform "\
|
|
|
|
"field if it is missing on Windows and Mac OS X 2.0.4 entries",
|
|
|
|
action="store_true")
|
|
|
|
parser.add_argument("--import_header", metavar="sdl_header",
|
|
|
|
help="imports and overrides mappings using SDL_gamecontrollerdb.h")
|
|
|
|
|
2018-01-08 21:07:44 -05:00
|
|
|
class Mapping:
|
2018-01-10 17:22:45 -05:00
|
|
|
GUID_REGEX = re.compile(r"^(xinput|[0-9a-fA-F]{32,32})$")
|
|
|
|
|
2018-01-08 21:07:44 -05:00
|
|
|
BUTTON_REGEXES = {
|
|
|
|
"+a": re.compile(r"^[0-9]+\~?$"),
|
|
|
|
"-a": re.compile(r"^[0-9]+\~?$"),
|
|
|
|
"a": re.compile(r"^[0-9]+\~?$"),
|
|
|
|
"b": re.compile(r"^[0-9]+$"),
|
2018-04-14 11:57:51 -04:00
|
|
|
"h": re.compile(r"^[0-9]+\.(1|2|4|8)$"),
|
2018-01-08 21:07:44 -05:00
|
|
|
}
|
|
|
|
|
2018-01-09 16:20:44 -05:00
|
|
|
def __init__(self, mapping_string, line_number, add_missing_platform = False):
|
2018-07-04 16:56:11 -04:00
|
|
|
if not mapping_string.endswith(",\n") and not mapping_string.endswith(","):
|
|
|
|
raise ValueError("Mapping should end with comma (,)")
|
|
|
|
|
2018-01-08 21:07:44 -05:00
|
|
|
self.guid = ""
|
|
|
|
self.name = ""
|
|
|
|
self.platform = ""
|
2018-01-09 16:20:44 -05:00
|
|
|
self.line_number = 0
|
2018-01-08 21:07:44 -05:00
|
|
|
self.__keys = {
|
|
|
|
"+leftx": "",
|
|
|
|
"+lefty": "",
|
|
|
|
"+rightx": "",
|
2018-01-16 14:16:52 +02:00
|
|
|
"+righty": "",
|
2018-01-08 21:07:44 -05:00
|
|
|
"-leftx": "",
|
|
|
|
"-lefty": "",
|
|
|
|
"-rightx": "",
|
|
|
|
"-righty": "",
|
|
|
|
"a": "",
|
|
|
|
"b": "",
|
|
|
|
"back": "",
|
|
|
|
"dpdown": "",
|
|
|
|
"dpleft": "",
|
|
|
|
"dpright": "",
|
|
|
|
"dpup": "",
|
|
|
|
"guide": "",
|
|
|
|
"leftshoulder": "",
|
|
|
|
"leftstick": "",
|
|
|
|
"lefttrigger": "",
|
|
|
|
"leftx": "",
|
|
|
|
"lefty": "",
|
|
|
|
"rightshoulder": "",
|
|
|
|
"rightstick": "",
|
|
|
|
"righttrigger": "",
|
|
|
|
"rightx": "",
|
|
|
|
"righty": "",
|
|
|
|
"start": "",
|
|
|
|
"x": "",
|
|
|
|
"y": "",
|
|
|
|
}
|
|
|
|
|
2018-01-09 16:20:44 -05:00
|
|
|
self.line_number = line_number
|
|
|
|
reader = csv.reader([mapping_string], skipinitialspace=True)
|
2018-01-08 21:07:44 -05:00
|
|
|
mapping = next(reader)
|
|
|
|
mapping = list(filter(None, mapping))
|
|
|
|
self.set_guid(mapping[0])
|
|
|
|
mapping.pop(0)
|
|
|
|
self.set_name(mapping[0])
|
|
|
|
mapping.pop(0)
|
2018-01-09 14:05:23 -05:00
|
|
|
self.set_platform(mapping, add_missing_platform)
|
2018-01-08 21:07:44 -05:00
|
|
|
self.set_keys(mapping)
|
2018-01-08 22:58:55 -05:00
|
|
|
|
|
|
|
# Remove empty mappings.
|
|
|
|
self.__keys = {k:v for (k,v) in self.__keys.items() if v is not ""}
|
2018-01-08 21:07:44 -05:00
|
|
|
|
|
|
|
|
|
|
|
def set_guid(self, guid):
|
2018-01-20 16:35:37 -05:00
|
|
|
global sdl_version
|
|
|
|
|
2018-01-10 17:22:45 -05:00
|
|
|
if not self.GUID_REGEX.match(guid):
|
2018-01-08 21:07:44 -05:00
|
|
|
raise ValueError("GUID malformed.", guid)
|
|
|
|
|
2018-01-20 19:13:15 -05:00
|
|
|
if sdl_version == "2.0.4" or sdl_version == "2.0.5":
|
2018-01-20 16:35:37 -05:00
|
|
|
self.guid = guid
|
|
|
|
return
|
|
|
|
|
|
|
|
if guid[20:32] == "504944564944":
|
|
|
|
raise ValueError("GUID in SDL 2.0.4 format, please update your "\
|
|
|
|
"mapping software.")
|
|
|
|
|
|
|
|
if guid[4:16] == "000000000000" and guid[20:32] == "000000000000":
|
|
|
|
raise ValueError("GUID in SDL 2.0.4 format, please update your "\
|
|
|
|
"mapping software.")
|
|
|
|
|
2018-01-08 21:07:44 -05:00
|
|
|
self.guid = guid
|
|
|
|
|
|
|
|
|
|
|
|
def set_name(self, name):
|
|
|
|
name = re.sub(r" +", " ", name)
|
|
|
|
self.name = name
|
|
|
|
|
|
|
|
|
2018-01-09 14:05:23 -05:00
|
|
|
def __get_missing_platform(self):
|
|
|
|
if self.guid[20:32] == "504944564944":
|
|
|
|
print("Adding 'platform:Windows' to %s" % (self.name))
|
|
|
|
return ("platform:Windows")
|
|
|
|
elif self.guid[4:16] == "000000000000" \
|
|
|
|
and self.guid[20:32] == "000000000000":
|
|
|
|
print("Adding 'platform:Mac OS X' to %s" % (self.name))
|
|
|
|
return ("platform:Mac OS X")
|
|
|
|
else:
|
|
|
|
raise ValueError("Add missing platform : Cannot determine platform"\
|
|
|
|
" confidently.")
|
|
|
|
|
|
|
|
|
|
|
|
def set_platform(self, mapping, add_missing_platform):
|
|
|
|
remove_field_from_mapping = True
|
2018-01-08 21:07:44 -05:00
|
|
|
platform_kv = next((x for x in mapping if "platform:" in x), None)
|
|
|
|
if platform_kv == None:
|
2018-01-09 14:05:23 -05:00
|
|
|
if add_missing_platform:
|
|
|
|
platform_kv = self.__get_missing_platform()
|
|
|
|
remove_field_from_mapping = False
|
|
|
|
else:
|
|
|
|
raise ValueError("Required 'platform' field not found.")
|
2018-01-08 21:07:44 -05:00
|
|
|
|
|
|
|
platform = platform_kv.split(':')[1]
|
|
|
|
if platform not in mappings_dict.keys():
|
|
|
|
raise ValueError("Invalid platform.", platform)
|
|
|
|
|
|
|
|
self.platform = platform
|
2018-01-09 14:05:23 -05:00
|
|
|
if not remove_field_from_mapping:
|
|
|
|
return
|
2018-01-08 21:07:44 -05:00
|
|
|
index = mapping.index(platform_kv)
|
|
|
|
mapping.pop(index)
|
|
|
|
|
|
|
|
|
|
|
|
def set_keys(self, mapping):
|
|
|
|
throw = False
|
|
|
|
error_msg = ""
|
|
|
|
|
|
|
|
for kv in mapping:
|
|
|
|
button_key, button_val = kv.split(':')
|
|
|
|
|
|
|
|
if not button_key in self.__keys:
|
|
|
|
raise ValueError("Unrecognized key.", button_key)
|
|
|
|
|
|
|
|
# Gather duplicates.
|
|
|
|
if self.__keys[button_key] is not "":
|
|
|
|
throw = True
|
|
|
|
error_msg += "%s (was %s:%s), " \
|
|
|
|
% (kv, button_key, self.__keys[button_key])
|
2016-07-06 04:17:47 +05:30
|
|
|
continue
|
2017-10-14 13:14:05 -04:00
|
|
|
|
2018-01-08 21:07:44 -05:00
|
|
|
for butt,regex in self.BUTTON_REGEXES.items():
|
|
|
|
if not button_val.startswith(butt):
|
|
|
|
continue
|
2017-11-23 14:00:47 -03:00
|
|
|
|
2018-01-08 21:07:44 -05:00
|
|
|
val = button_val.replace(butt, "")
|
|
|
|
if not regex.match(val):
|
|
|
|
raise ValueError("Invalid value.", butt, val)
|
2017-10-07 19:04:18 -04:00
|
|
|
|
2018-01-08 21:07:44 -05:00
|
|
|
self.__keys[button_key] = button_val
|
|
|
|
break
|
2017-10-07 20:12:35 -04:00
|
|
|
|
2018-01-08 21:07:44 -05:00
|
|
|
if throw:
|
|
|
|
raise ValueError("Duplicate keys detected.", error_msg)
|
2017-12-17 16:16:20 -05:00
|
|
|
|
2018-01-08 21:07:44 -05:00
|
|
|
def __str__(self):
|
|
|
|
ret = "Mapping {\n guid: %s\n name: %s\n platform: %s\n" \
|
|
|
|
% (self.guid, self.name, self.platform)
|
2017-10-07 20:12:35 -04:00
|
|
|
|
2018-01-08 21:07:44 -05:00
|
|
|
ret += " Keys {\n"
|
|
|
|
for key,val in self.__keys.items():
|
|
|
|
ret += " %s: %s\n" % (key, val)
|
2017-12-17 16:16:20 -05:00
|
|
|
|
2018-01-08 21:07:44 -05:00
|
|
|
ret += " }\n}"
|
|
|
|
return ret
|
|
|
|
|
2018-01-20 19:13:15 -05:00
|
|
|
def __eq__(self, other):
|
|
|
|
ret = True
|
|
|
|
ret &= self.guid == other.guid
|
|
|
|
ret &= self.name == other.name
|
|
|
|
ret &= self.platform == other.platform
|
|
|
|
ret &= self.__keys == other.__keys
|
|
|
|
return ret
|
|
|
|
|
|
|
|
def __ne__(self, other):
|
|
|
|
return not self.__eq__(other)
|
2018-01-09 14:05:23 -05:00
|
|
|
|
2018-01-08 21:07:44 -05:00
|
|
|
def serialize(self):
|
|
|
|
ret = "%s,%s," % (self.guid, self.name)
|
2018-01-08 22:58:55 -05:00
|
|
|
sorted_keys = sorted(self.__keys.items())
|
|
|
|
for key,val in sorted_keys:
|
2018-01-08 21:07:44 -05:00
|
|
|
ret += "%s:%s," % (key, val)
|
|
|
|
ret += "platform:%s," % (self.platform)
|
|
|
|
return ret
|
2017-10-07 20:12:35 -04:00
|
|
|
|
2018-01-09 14:05:23 -05:00
|
|
|
|
|
|
|
# https://hg.libsdl.org/SDL/rev/20855a38e048
|
|
|
|
def convert_guid(self):
|
|
|
|
if self.platform == "Windows":
|
|
|
|
if self.guid[20:32] != "504944564944":
|
2018-01-11 14:51:54 -05:00
|
|
|
return False
|
2018-01-09 14:05:23 -05:00
|
|
|
|
|
|
|
guid = self.guid
|
2017-10-07 23:43:37 -04:00
|
|
|
guid = guid[:20] + "000000000000"
|
|
|
|
guid = guid[:16] + guid[4:8] + guid[20:]
|
|
|
|
guid = guid[:8] + guid[:4] + guid[12:]
|
|
|
|
guid = "03000000" + guid[8:]
|
|
|
|
guid = guid.lower()
|
2018-01-11 14:51:54 -05:00
|
|
|
print("%s : Converted %s GUID. From %s to %s" \
|
|
|
|
%(self.platform, self.name, self.guid, guid))
|
2018-01-09 14:05:23 -05:00
|
|
|
self.guid = guid
|
|
|
|
|
|
|
|
elif self.platform == "Mac OS X":
|
|
|
|
if self.guid[4:16] != "000000000000" \
|
|
|
|
or self.guid[20:32] != "000000000000":
|
2018-01-11 14:51:54 -05:00
|
|
|
return False
|
2018-01-09 14:05:23 -05:00
|
|
|
|
|
|
|
guid = self.guid
|
2017-10-07 23:43:37 -04:00
|
|
|
guid = guid[:20] + "000000000000"
|
|
|
|
guid = guid[:8] + guid[:4] + guid[12:]
|
|
|
|
guid = "03000000" + guid[8:]
|
|
|
|
guid = guid.lower()
|
2018-01-11 14:51:54 -05:00
|
|
|
print("%s : Converted %s GUID. From %s to %s" \
|
|
|
|
% (self.platform, self.name, self.guid, guid))
|
2018-01-09 14:05:23 -05:00
|
|
|
self.guid = guid
|
2017-10-07 23:43:37 -04:00
|
|
|
|
2018-01-11 14:51:54 -05:00
|
|
|
else:
|
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
2017-10-14 13:14:05 -04:00
|
|
|
|
2018-01-20 19:13:15 -05:00
|
|
|
def import_header(mappings_dict, filepath, debug_out = False):
|
2018-01-09 16:20:44 -05:00
|
|
|
class Platform:
|
|
|
|
XINPUT = 0
|
|
|
|
WINDOWS = 1
|
|
|
|
OSX = 2
|
|
|
|
LINUX = 3
|
|
|
|
ANDROID = 4
|
2018-01-10 13:46:20 -05:00
|
|
|
IOS = 5
|
|
|
|
NONE = 6
|
2018-01-09 16:20:44 -05:00
|
|
|
|
|
|
|
current_platform = Platform.NONE
|
|
|
|
|
|
|
|
input_file = open(filepath, mode="r")
|
|
|
|
for lineno, line in enumerate(input_file):
|
|
|
|
if "#if SDL_JOYSTICK_XINPUT" in line:
|
|
|
|
current_platform = Platform.XINPUT
|
|
|
|
continue
|
|
|
|
elif "#if SDL_JOYSTICK_DINPUT" in line:
|
|
|
|
current_platform = Platform.WINDOWS
|
|
|
|
continue
|
|
|
|
elif "#if defined(__MACOSX__)" in line:
|
|
|
|
current_platform = Platform.OSX
|
|
|
|
continue
|
|
|
|
elif "#if defined(__LINUX__)" in line:
|
|
|
|
current_platform = Platform.LINUX
|
|
|
|
continue
|
|
|
|
elif "#if defined(__ANDROID__)" in line:
|
|
|
|
current_platform = Platform.ANDROID
|
|
|
|
continue
|
2018-01-10 13:46:20 -05:00
|
|
|
elif "#if defined(SDL_JOYSTICK_MFI)" in line:
|
|
|
|
current_platform = Platform.IOS
|
|
|
|
continue
|
2018-01-09 16:20:44 -05:00
|
|
|
elif "#endif" in line:
|
|
|
|
current_platform = Platform.NONE
|
|
|
|
continue
|
|
|
|
|
|
|
|
if current_platform == Platform.NONE:
|
|
|
|
continue
|
|
|
|
|
|
|
|
mapping_string = line[line.find('"') + 1:]
|
|
|
|
mapping_string = mapping_string[:mapping_string.find('"')]
|
|
|
|
|
|
|
|
if current_platform == Platform.XINPUT:
|
|
|
|
mapping_string += "platform:Windows,"
|
|
|
|
if current_platform == Platform.WINDOWS:
|
|
|
|
mapping_string += "platform:Windows,"
|
|
|
|
if current_platform == Platform.OSX:
|
|
|
|
mapping_string += "platform:Mac OS X,"
|
|
|
|
if current_platform == Platform.LINUX:
|
|
|
|
mapping_string += "platform:Linux,"
|
|
|
|
if current_platform == Platform.ANDROID:
|
|
|
|
mapping_string += "platform:Android,"
|
2018-01-10 13:46:20 -05:00
|
|
|
if current_platform == Platform.IOS:
|
|
|
|
mapping_string += "platform:iOS,"
|
2018-01-09 16:20:44 -05:00
|
|
|
|
|
|
|
try:
|
|
|
|
mapping = Mapping(mapping_string, lineno + 1)
|
|
|
|
except ValueError as e:
|
|
|
|
print("\nError at line #" + str(lineno + 1))
|
|
|
|
print(e.args)
|
|
|
|
print("Ignoring mapping")
|
|
|
|
print(line)
|
|
|
|
continue
|
2018-01-10 13:55:33 -05:00
|
|
|
|
|
|
|
if debug_out:
|
|
|
|
print("%s : Importing %s" % (mapping.platform, mapping.name))
|
|
|
|
|
2018-01-10 13:46:20 -05:00
|
|
|
mappings_dict[mapping.platform][mapping.guid] = mapping
|
2018-01-09 16:20:44 -05:00
|
|
|
input_file.close()
|
|
|
|
|
|
|
|
|
2017-10-07 19:04:18 -04:00
|
|
|
def main():
|
2018-01-09 16:20:44 -05:00
|
|
|
global mappings_dict # { "platform": { "guid": Mapping }}
|
2018-01-20 19:13:15 -05:00
|
|
|
global header_mappings_dict # { "platform": { "guid": Mapping }}
|
2018-01-20 16:35:37 -05:00
|
|
|
global sdl_version
|
2018-01-09 16:20:44 -05:00
|
|
|
global parser
|
2017-10-07 20:56:20 -04:00
|
|
|
args = parser.parse_args()
|
2018-01-09 16:20:44 -05:00
|
|
|
success = True
|
2017-10-07 20:56:20 -04:00
|
|
|
|
2018-01-20 16:35:37 -05:00
|
|
|
if "204" in args.input_file:
|
|
|
|
sdl_version = "2.0.4"
|
|
|
|
elif "205" in args.input_file:
|
|
|
|
sdl_version = "2.0.5"
|
|
|
|
|
2018-01-09 14:05:23 -05:00
|
|
|
if args.add_missing_platform:
|
2018-01-20 16:35:37 -05:00
|
|
|
if sdl_version != "2.0.4":
|
|
|
|
print("Cannot add missing platforms on newer SDL database.")
|
|
|
|
args.add_missing_platform = False
|
|
|
|
else:
|
|
|
|
print("Will try to add missing platforms. Requires SDL 2.0.4 GUID.")
|
|
|
|
if not args.format:
|
|
|
|
print("Use --format option to save database. Running in debug "\
|
|
|
|
"output mode...")
|
2017-10-14 13:14:05 -04:00
|
|
|
|
2018-01-09 16:20:44 -05:00
|
|
|
|
2018-01-08 21:07:44 -05:00
|
|
|
# Tests.
|
2018-01-09 14:05:23 -05:00
|
|
|
print("\nApplying checks.")
|
2018-01-08 21:07:44 -05:00
|
|
|
|
2018-01-20 19:13:15 -05:00
|
|
|
import_header(header_mappings_dict,
|
|
|
|
"data/SDL_gamecontrollerdb" + sdl_version + ".h", False)
|
|
|
|
|
2018-01-09 16:20:44 -05:00
|
|
|
input_file = open(args.input_file, mode="r")
|
2018-01-08 21:07:44 -05:00
|
|
|
for lineno, line in enumerate(input_file):
|
|
|
|
if line.startswith('#') or line == '\n':
|
|
|
|
continue
|
|
|
|
try:
|
2018-01-09 14:05:23 -05:00
|
|
|
mapping = Mapping(line, lineno + 1, args.add_missing_platform)
|
2018-01-08 21:07:44 -05:00
|
|
|
except ValueError as e:
|
2018-01-09 14:05:23 -05:00
|
|
|
print("\nError at line #" + str(lineno + 1))
|
2018-01-08 21:07:44 -05:00
|
|
|
print(e.args)
|
2018-01-09 14:05:23 -05:00
|
|
|
print("In mapping")
|
2018-01-08 21:07:44 -05:00
|
|
|
print(line)
|
|
|
|
success = False
|
|
|
|
continue
|
|
|
|
|
|
|
|
if mapping.guid in mappings_dict[mapping.platform]:
|
2018-01-20 19:13:15 -05:00
|
|
|
print("\nDuplicate detected at line #" + str(lineno + 1))
|
2018-01-08 21:07:44 -05:00
|
|
|
prev_mapping = mappings_dict[mapping.platform][mapping.guid]
|
2018-01-09 16:20:44 -05:00
|
|
|
print("Previous mapping at line #" + str(prev_mapping.line_number))
|
2018-01-09 14:05:23 -05:00
|
|
|
print("In mapping")
|
2018-01-08 21:07:44 -05:00
|
|
|
print(line)
|
|
|
|
success = False
|
|
|
|
continue
|
2017-10-14 13:14:05 -04:00
|
|
|
|
2018-01-20 19:13:15 -05:00
|
|
|
if mapping.guid in header_mappings_dict[mapping.platform]:
|
|
|
|
if mapping != header_mappings_dict[mapping.platform][mapping.guid]:
|
|
|
|
print("\nCannot modify upstream SDL header mapping at line #" \
|
|
|
|
+ str(lineno + 1))
|
|
|
|
print("If you have problems with an official SDL mapping, " \
|
|
|
|
"please report the issue or send a pull request to " \
|
|
|
|
"the SDL project : libsdl.org.")
|
|
|
|
print("In mapping")
|
|
|
|
print(line)
|
|
|
|
success = False
|
|
|
|
continue
|
|
|
|
|
2018-01-08 21:07:44 -05:00
|
|
|
mappings_dict[mapping.platform][mapping.guid] = mapping
|
|
|
|
input_file.close()
|
2017-10-14 13:14:05 -04:00
|
|
|
|
2017-10-07 19:04:18 -04:00
|
|
|
if success:
|
2017-10-07 20:56:20 -04:00
|
|
|
print("No mapping errors found.")
|
2017-10-07 19:04:18 -04:00
|
|
|
else:
|
|
|
|
sys.exit(1)
|
2017-10-07 13:29:58 -04:00
|
|
|
|
2018-01-09 16:20:44 -05:00
|
|
|
|
2018-01-09 14:05:23 -05:00
|
|
|
# Misc tools.
|
2018-01-09 16:20:44 -05:00
|
|
|
|
2018-01-09 14:05:23 -05:00
|
|
|
if args.convert_guids:
|
|
|
|
print("Converting GUIDs to SDL 2.0.5+ format.")
|
|
|
|
if not args.format:
|
|
|
|
print("Use --format option to save database. Running in debug " \
|
|
|
|
"output mode...")
|
|
|
|
for platform,p_dict in mappings_dict.items():
|
|
|
|
for guid,mapping in p_dict.items():
|
2018-01-11 14:51:54 -05:00
|
|
|
if mapping.convert_guid():
|
|
|
|
del mappings_dict[platform][guid]
|
|
|
|
if mapping.guid in mappings_dict[platform]:
|
|
|
|
print("\nDuplicate detected when converting GUID.")
|
|
|
|
prev_mapping = mappings_dict[platform][mapping.guid]
|
|
|
|
print("Previous mapping %s" % prev_mapping.name)
|
|
|
|
print("Ignoring new mapping")
|
|
|
|
print(mapping.serialize())
|
|
|
|
print("\n")
|
|
|
|
continue
|
|
|
|
mappings_dict[platform][mapping.guid] = mapping
|
2018-01-09 14:05:23 -05:00
|
|
|
|
2018-01-09 16:20:44 -05:00
|
|
|
if args.import_header is not None:
|
2018-01-20 19:13:15 -05:00
|
|
|
print("Importing mappings from %s" % args.import_header)
|
2018-01-09 16:20:44 -05:00
|
|
|
if not args.format:
|
|
|
|
print("Use --format option to save database. Running in debug "\
|
|
|
|
"output mode...")
|
2018-01-20 19:13:15 -05:00
|
|
|
import_header(mappings_dict, args.import_header, not args.format)
|
2018-01-09 16:20:44 -05:00
|
|
|
|
2018-01-08 21:07:44 -05:00
|
|
|
if args.format:
|
|
|
|
print("\nFormatting db.")
|
2018-01-08 22:25:11 -05:00
|
|
|
out_filename = path.splitext(input_file.name)[0] + "_format.txt"
|
|
|
|
out_file = open(out_filename, 'w')
|
2018-01-20 16:35:37 -05:00
|
|
|
out_file.write(FILE_HEADER % sdl_version)
|
2018-01-08 21:07:44 -05:00
|
|
|
for platform,p_dict in mappings_dict.items():
|
|
|
|
out_file.write("\n")
|
|
|
|
out_file.write("# " + platform + "\n")
|
|
|
|
sorted_p_dict = sorted(p_dict.items(),
|
2018-02-19 17:43:56 -05:00
|
|
|
key=lambda x: ("%s\x00%s" % (x[1].name, x[0])).lower())
|
2018-01-08 21:07:44 -05:00
|
|
|
|
|
|
|
for guid,mapping in sorted_p_dict:
|
|
|
|
out_file.write(mapping.serialize() + "\n")
|
|
|
|
|
|
|
|
out_file.close()
|
2018-01-08 22:25:11 -05:00
|
|
|
backup_filename = (path.join(path.split(input_file.name)[0],
|
|
|
|
".bak." + path.split(input_file.name)[1]))
|
|
|
|
shutil.copyfile(input_file.name, backup_filename)
|
|
|
|
shutil.move(out_filename, input_file.name)
|
2018-01-08 21:07:44 -05:00
|
|
|
|
|
|
|
|
2017-10-07 19:04:18 -04:00
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|
2018-01-08 21:07:44 -05:00
|
|
|
|