forked from John-Gee/HFRSteam
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmapper.py
More file actions
45 lines (37 loc) · 1.46 KB
/
mapper.py
File metadata and controls
45 lines (37 loc) · 1.46 KB
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
import os.path
class Mapper:
LINK = '<->'
__mappingfile = ''
__mapping = {}
def __init__(self, mappingfile):
if(os.path.exists(mappingfile)):
self.__mappingfile = mappingfile
self.__mapping = dict()
f = open(self.__mappingfile, 'r')
for line in iter(f):
line = line.strip()
# remove the quotes needed to protect spaces at the end of
# names when steam messed up
line = line[1:-1]
if (self.LINK in line):
couple = line.split(self.LINK)
if (len(couple) == 2):
self.__mapping[couple[0].lower()] = couple[1].lower()
def save_mapping(self):
if ((self.__mapping == None) or (len(self.__mapping) == 0)):
return
f = open(self.__mappingfile, 'w')
for key in sorted(self.__mapping):
line = '"{0}{1}{2}"'.format(key, self.LINK, self.__mapping[key])
f.write(line)
f.write(os.linesep)
def add_to_mapping(self, left, right):
if (left not in self.__mapping):
self.__mapping[left.lower()] = right.lower()
else:
print('Impossible to add mapping, {0} is already in the mapper'.
format(left))
def get_mapping(self, left):
if (left.lower() in self.__mapping):
return self.__mapping[left.lower()]
return None