Package moap :: Package util :: Module usermap
[hide private]
[frames] | no frames]

Source Code for Module moap.util.usermap

 1  # -*- Mode: Python; test-case-name: moap.test.test_util_usermap -*- 
 2  # vi:si:et:sw=4:sts=4:ts=4 
 3   
 4  """ 
 5  User map class. 
 6  """ 
 7   
8 -class UserMapException(Exception):
9 pass
10
11 -class UserMap(list):
12 """ 13 I add parse methods to a dictionary to parse a username mapping string. 14 The string contains one entry per line. 15 Each line contains an old username and a new username, separated by 16 a colon. 17 """
18 - def parse(self, text):
19 i = -1 20 for line in text.strip().split('\n'): 21 i += 1 22 if line.startswith('#'): 23 continue 24 try: 25 old, new = line.split(':') 26 except ValueError: 27 raise UserMapException("Could not parse line %d (%s)" % ( 28 i, line)) 29 self.append((old, new))
30
31 - def parseFromPath(self, path):
32 text = open(path).read() 33 self.parse(text)
34