check.py : Flag changes to upstreamm official SDL mappings.

This commit is contained in:
Philippe Groarke 2018-01-20 19:13:15 -05:00
parent c5910cb1fb
commit 6854c08b46
6 changed files with 326 additions and 19 deletions

View file

@ -13,6 +13,7 @@ import shutil
import argparse
import csv
import re
import copy
FILE_HEADER = "# Game Controller DB for SDL in %s format\n" \
"# Source: https://github.com/gabomdq/SDL_GameControllerDB\n"
@ -27,6 +28,8 @@ mappings_dict = OrderedDict([
("iOS", {}),
])
header_mappings_dict = copy.deepcopy(mappings_dict)
parser = argparse.ArgumentParser()
parser.add_argument("input_file", help="database file to check, " \
"ex. gamecontrollerdb.txt")
@ -110,7 +113,7 @@ class Mapping:
if not self.GUID_REGEX.match(guid):
raise ValueError("GUID malformed.", guid)
if sdl_version == "2.0.4":
if sdl_version == "2.0.4" or sdl_version == "2.0.5":
self.guid = guid
return
@ -206,6 +209,16 @@ class Mapping:
ret += " }\n}"
return ret
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)
def serialize(self):
ret = "%s,%s," % (self.guid, self.name)
@ -251,7 +264,7 @@ class Mapping:
return True
def import_header(filepath, debug_out = False):
def import_header(mappings_dict, filepath, debug_out = False):
class Platform:
XINPUT = 0
WINDOWS = 1
@ -261,7 +274,6 @@ def import_header(filepath, debug_out = False):
IOS = 5
NONE = 6
global mappings_dict # { "platform": { "guid": Mapping }}
current_platform = Platform.NONE
input_file = open(filepath, mode="r")
@ -325,6 +337,7 @@ def import_header(filepath, debug_out = False):
def main():
global mappings_dict # { "platform": { "guid": Mapping }}
global header_mappings_dict # { "platform": { "guid": Mapping }}
global sdl_version
global parser
args = parser.parse_args()
@ -349,6 +362,9 @@ def main():
# Tests.
print("\nApplying checks.")
import_header(header_mappings_dict,
"data/SDL_gamecontrollerdb" + sdl_version + ".h", False)
input_file = open(args.input_file, mode="r")
for lineno, line in enumerate(input_file):
if line.startswith('#') or line == '\n':
@ -364,7 +380,7 @@ def main():
continue
if mapping.guid in mappings_dict[mapping.platform]:
print("Duplicate detected at line #" + str(lineno + 1))
print("\nDuplicate detected at line #" + str(lineno + 1))
prev_mapping = mappings_dict[mapping.platform][mapping.guid]
print("Previous mapping at line #" + str(prev_mapping.line_number))
print("In mapping")
@ -372,6 +388,18 @@ def main():
success = False
continue
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
mappings_dict[mapping.platform][mapping.guid] = mapping
input_file.close()
@ -403,11 +431,11 @@ def main():
mappings_dict[platform][mapping.guid] = mapping
if args.import_header is not None:
print("Importing mappings from SDL_gamecontrollerdb.h.")
print("Importing mappings from %s" % args.import_header)
if not args.format:
print("Use --format option to save database. Running in debug "\
"output mode...")
import_header(args.import_header, not args.format)
import_header(mappings_dict, args.import_header, not args.format)
if args.format:
print("\nFormatting db.")