-
Notifications
You must be signed in to change notification settings - Fork 0
/
remap.py
36 lines (33 loc) · 910 Bytes
/
remap.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
#
# A really simple account-name remapping module.
#
# Copyright 2017 Jonathan Corbet.
# This program may be distributed under the terms of the GNU General
# Public License, version 2 or later.
#
from __future__ import print_function
Mappings = { }
def load_mapfile(file):
try:
mf = open(file, 'r')
except IOError:
print('Unable to open map file %s, doing without' % (file))
return
for line in mf.readlines():
if not line or line[0] == '#':
continue
sline = line.split('|')
if len(sline) != 2:
print('Funky map line:', line)
continue
Mappings[sline[0].strip()] = sline[1].strip()
mf.close()
def remap(acct):
try:
return Mappings[acct]
except KeyError:
smap = acct.split(':')
try:
return Mappings[smap[-1]]
except KeyError:
return acct