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

Source Code for Module buildslave.util

 1  # This file is part of Buildbot.  Buildbot is free software: you can 
 2  # redistribute it and/or modify it under the terms of the GNU General Public 
 3  # License as published by the Free Software Foundation, version 2. 
 4  # 
 5  # This program is distributed in the hope that it will be useful, but WITHOUT 
 6  # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 
 7  # FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more 
 8  # details. 
 9  # 
10  # You should have received a copy of the GNU General Public License along with 
11  # this program; if not, write to the Free Software Foundation, Inc., 51 
12  # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 
13  # 
14  # Copyright Buildbot Team Members 
15   
16  import types 
17  import time 
18 19 -def remove_userpassword(url):
20 if '@' not in url: 21 return url 22 if '://' not in url: 23 return url 24 25 # urlparse would've been nice, but doesn't support ssh... sigh 26 protocol_url = url.split('://') 27 protocol = protocol_url[0] 28 repo_url = protocol_url[1].split('@')[-1] 29 30 return protocol + '://' + repo_url
31
32 33 -def now(_reactor=None):
34 if _reactor and hasattr(_reactor, "seconds"): 35 return _reactor.seconds() 36 else: 37 return time.time()
38
39 -class Obfuscated:
40 """An obfuscated string in a command"""
41 - def __init__(self, real, fake):
42 self.real = real 43 self.fake = fake
44
45 - def __str__(self):
46 return self.fake
47
48 - def __repr__(self):
49 return `self.fake`
50
51 - def __eq__(self, other):
52 return other.__class__ is self.__class__ and \ 53 other.real == self.real and \ 54 other.fake == self.fake
55 56 @staticmethod
57 - def to_text(s):
58 if isinstance(s, (str, unicode)): 59 return s 60 else: 61 return str(s)
62 63 @staticmethod
64 - def get_real(command):
65 rv = command 66 if type(command) == types.ListType: 67 rv = [] 68 for elt in command: 69 if isinstance(elt, Obfuscated): 70 rv.append(elt.real) 71 else: 72 rv.append(Obfuscated.to_text(elt)) 73 return rv
74 75 @staticmethod
76 - def get_fake(command):
77 rv = command 78 if type(command) == types.ListType: 79 rv = [] 80 for elt in command: 81 if isinstance(elt, Obfuscated): 82 rv.append(elt.fake) 83 else: 84 rv.append(Obfuscated.to_text(elt)) 85 return rv
86