check.py : Fix sorting in python2.
This commit is contained in:
parent
c4cbc7ef65
commit
2615904e42
1 changed files with 6 additions and 8 deletions
14
check.py
14
check.py
|
@ -5,8 +5,6 @@ import sys
|
||||||
# print("This script requires Python 3.")
|
# print("This script requires Python 3.")
|
||||||
# exit(1)
|
# exit(1)
|
||||||
|
|
||||||
from collections import defaultdict
|
|
||||||
from collections import namedtuple
|
|
||||||
from os import path
|
from os import path
|
||||||
import string
|
import string
|
||||||
import collections
|
import collections
|
||||||
|
@ -15,7 +13,7 @@ import argparse
|
||||||
import csv
|
import csv
|
||||||
import re
|
import re
|
||||||
|
|
||||||
FILE_HEADER = "# Game Controller DB for SDL in post 2.0.6 format\n\
|
FILE_HEADER = "# Game Controller DB for SDL in 2.0.6 format\n\
|
||||||
# Source: https://github.com/gabomdq/SDL_GameControllerDB\n"
|
# Source: https://github.com/gabomdq/SDL_GameControllerDB\n"
|
||||||
|
|
||||||
mappings_dict = {
|
mappings_dict = {
|
||||||
|
@ -80,7 +78,9 @@ class Mapping:
|
||||||
mapping.pop(0)
|
mapping.pop(0)
|
||||||
self.set_platform(mapping)
|
self.set_platform(mapping)
|
||||||
self.set_keys(mapping)
|
self.set_keys(mapping)
|
||||||
self.remove_empty_mappings()
|
|
||||||
|
# Remove empty mappings.
|
||||||
|
self.__keys = {k:v for (k,v) in self.__keys.items() if v is not ""}
|
||||||
|
|
||||||
|
|
||||||
def set_guid(self, guid):
|
def set_guid(self, guid):
|
||||||
|
@ -149,9 +149,6 @@ class Mapping:
|
||||||
if throw:
|
if throw:
|
||||||
raise ValueError("Duplicate keys detected.", error_msg)
|
raise ValueError("Duplicate keys detected.", error_msg)
|
||||||
|
|
||||||
def remove_empty_mappings(self):
|
|
||||||
self.__keys = {k:v for (k,v) in self.__keys.items() if v is not ""}
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
ret = "Mapping {\n guid: %s\n name: %s\n platform: %s\n" \
|
ret = "Mapping {\n guid: %s\n name: %s\n platform: %s\n" \
|
||||||
% (self.guid, self.name, self.platform)
|
% (self.guid, self.name, self.platform)
|
||||||
|
@ -165,7 +162,8 @@ class Mapping:
|
||||||
|
|
||||||
def serialize(self):
|
def serialize(self):
|
||||||
ret = "%s,%s," % (self.guid, self.name)
|
ret = "%s,%s," % (self.guid, self.name)
|
||||||
for key,val in self.__keys.items():
|
sorted_keys = sorted(self.__keys.items())
|
||||||
|
for key,val in sorted_keys:
|
||||||
ret += "%s:%s," % (key, val)
|
ret += "%s:%s," % (key, val)
|
||||||
ret += "platform:%s," % (self.platform)
|
ret += "platform:%s," % (self.platform)
|
||||||
return ret
|
return ret
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue