def Validate(self, answer): # Validate format try: port = int(answer) except ValueError: raise ValidationError('Value entered must be digits.') # Validate range if port < 1 or port > 65535: raise ValidationError('Port values must be within 1 and 65535.') # Validate whether the port is available. We try to open the port and # listen, and if it fails, we use netstat to try to figure out what's # using it. sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) error = '' try: sock.bind(('', port)) except socket.error: netstat = run('/bin/netstat', '-nvpa', ignoreErrors=True, noLogging=True) error = 'port %s is in use' % port if netstat['retCode'] == 0: for procPort, procPID, procName in re.findall( '^\S+\s+\S+\s+\S+\s+\S+\:(\d+)\s+\S+\s+\S+\s+(\d+)\/(\S+)', netstat['stdout'], re.MULTILINE): if port == int(procPort): name = run('/bin/ps', '-o', 'comm=', procPID, ignoreErrors=True, noLogging=True)['stdout'] name = name.rstrip() or procName # If we're scanning for a process, allow the port to be used # if it's in use by a process matching the given name. if self.process and self.process in name: error = '' else: error = 'port %s is in use by %s' % (port, name) break finally: # Make sure to release the port. sock.close() if error and not 'deferred-gtk' in ui.TYPE: raise ValidationError('The VMware Installer has detected that %s. ' 'The installing product will not run ' 'properly if its port is in use.' % error) return answer
def Validate(self, answer): try: answer = int(answer) except ValueError: raise ValidationError('Value entered must be an integer.') if answer < self.min or answer > self.max: raise ValidationError( 'The value must be greater than %d and less than %d.' % (self.min, self.max)) return answer
def Validate(self, answer): if answer is None: return None if not isinstance(answer, str): raise ValidationError('TextEntry must be a string') return answer.strip()
def Validate(self, answer): if not isinstance(answer, str): raise ValidationError('Directory must be a string') # If it's not required accept the given answer as long as it is # empty. if not self._required and not answer.strip(): return '' answer = path(answer.strip()) if not answer: raise ValidationError('Directory must be non-empty') if not answer.isabs(): raise ValidationError('Directory is not an absolute path') if answer.isfile(): raise ValidationError('Path is an existing file') if not answer.exists() and self._mustExist: raise ValidationError('Directory path does not exist') if not answer.isdir() and self._mustExist: raise ValidationError('Directory path is not a directory') if not answer.access(os.W_OK) and self._writeable and self._mustExist: raise ValidationError('Directory path is not writeable') return answer
def Validate(self, answer): answer = answer.lower() # Yes! if answer in ['y']: answer = 'yes' # No! if answer in ['n']: answer = 'no' if answer in ['quit', 'q']: raise AbortError() if answer not in ['yes', 'no']: raise ValidationError('Answer must be yes, y, no, or n') return answer
def Validate(self, answer): """ Validate that the given answer contains the expected directories @raises: ValidationError """ super(InitDir, self).Validate(answer) # Accept a blank entry for those systems that don't have rc?.d style # init directories. if answer == '': return answer rcdirs = ('rc0.d', 'rc1.d', 'rc2.d', 'rc3.d', 'rc4.d', 'rc5.d', 'rc6.d') answer = path(answer) if all([(answer / rc).exists() for rc in rcdirs]): return answer else: raise ValidationError('%s is not an init directory' % answer)
def Validate(self, answer): ports = answer.split('/') # Validate integers try: for i in range(2): num = int(ports[i]) except ValueError: raise ValidationError('Values entered must be digits.') # Now validate range try: for i in range(2): num = int(ports[i]) if num < 1 or num > 65535: raise ValueError except ValueError: raise ValidationError('Port values must be within 1 and 65535.') # Now check to be sure the ports are free. http = ports[0] https = ports[1] # run this just once and use the results in the following loop self.netstat = run('/bin/netstat', '-nvpa', ignoreErrors=True, noLogging=True) errorString = '' inUse = [] for port in ports: # Try to open the port for listening. If we fail, assume it's taken and use netstat to # try and figure out what's using it. sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: sock.bind(('', int(port))) except socket.error as e: # If we've already found an error, add an " and " to the error message. if errorString: errorString = errorString + ' and ' # Cannot bind the socket. Use netstat to find out why. if self.netstat['retCode'] == 0: txt = self.netstat['stdout'] # Scan ports in use to find our port allPorts = re.findall( '^\S+\s+\S+\s+\S+\s+\S+\:(\d+)\s+\S+\s+\S+\s+(\d+)\/(\S+)', txt, re.MULTILINE) for procs in allPorts: if port == procs[0]: # Find the real name of the process name = run('/bin/ps', '-o', 'comm=', procs[1], ignoreErrors=True, noLogging=True)['stdout'] if name: name = name.rstrip() # If we're scanning for a process, allow the port to be used # if it's in use by a process matching the given name. if self.process and self.process in name: continue errorString = errorString + 'port %s is in use by %s' % ( procs[0], name) else: errorString = errorString + 'port %s is in use' % procs[ 0] break else: errorString = errorString + 'port %s is in use' % port finally: # Make sure to release the port. sock.close() if errorString: errorString = 'The VMware Installer has detected that ' + errorString + \ '. The installing product will not run properly if its ports are in use.' raise ValidationErrorNonFatal(errorString) return answer