Package buildslave :: Module util
[frames] | no frames]

Source Code for Module buildslave.util

 1  import types 
 2  import time 
3 4 -def remove_userpassword(url):
5 if '@' not in url: 6 return url 7 if '://' not in url: 8 return url 9 10 # urlparse would've been nice, but doesn't support ssh... sigh 11 protocol_url = url.split('://') 12 protocol = protocol_url[0] 13 repo_url = protocol_url[1].split('@')[-1] 14 15 return protocol + '://' + repo_url
16
17 18 -def now(_reactor=None):
19 if _reactor and hasattr(_reactor, "seconds"): 20 return _reactor.seconds() 21 else: 22 return time.time()
23
24 -class Obfuscated:
25 """An obfuscated string in a command"""
26 - def __init__(self, real, fake):
27 self.real = real 28 self.fake = fake
29
30 - def __str__(self):
31 return self.fake
32
33 - def __repr__(self):
34 return `self.fake`
35
36 - def __eq__(self, other):
37 return other.__class__ is self.__class__ and \ 38 other.real == self.real and \ 39 other.fake == self.fake
40 41 @staticmethod
42 - def to_text(s):
43 if isinstance(s, (str, unicode)): 44 return s 45 else: 46 return str(s)
47 48 @staticmethod
49 - def get_real(command):
50 rv = command 51 if type(command) == types.ListType: 52 rv = [] 53 for elt in command: 54 if isinstance(elt, Obfuscated): 55 rv.append(elt.real) 56 else: 57 rv.append(Obfuscated.to_text(elt)) 58 return rv
59 60 @staticmethod
61 - def get_fake(command):
62 rv = command 63 if type(command) == types.ListType: 64 rv = [] 65 for elt in command: 66 if isinstance(elt, Obfuscated): 67 rv.append(elt.fake) 68 else: 69 rv.append(Obfuscated.to_text(elt)) 70 return rv
71