Example #1
0
	def __init__(self, host, port, username = "", password = ""):
		"""
		"""

		if not Validator.validate_non_empty_string(host):
			raise InvalidParameterError("host", "Must be non-empty String")
		if not Validator.validate_integer(port):
			raise InvalidParameterError("port", "Must be an integer value")
		if not Validator.validate_string(username):
			raise InvalidParameterError("username", "Must be a string value")
		if not Validator.validate_string(password):
			raise InvalidParameterError("password", "Must be a string value")

		super(SqlClient, self).__init__()

		self.__host = host
		self.__port = port
		self.__username = username
		self.__password = password
		self.__platform = Platform.get_current()
Example #2
0
	def get_instance(cls, project, parameters):
		"""
		Creates an instance of a SshServer object and returns it.

		@param project: An instance of a Project, sent as None the first time get_object is called when supposedly it is asked to create an instance of Project.
		@param parameters: A dictionary of parameters that are sent to the constructor.
			Expected keys are "id", "os" and "host".
			Optional keys are "port", "username", "password", "certificate_file", "passphrase" and "root".

		@return: An instance of SshServer
		"""

		parameters = project.process_node_parameters(
			parameters,
			["id", "host", "os"],
			{"port": 22, "username": "", "password": "", "certificate_file" : "", "passphrase" : "", "root" : ""},
			{"id": "variable_name", "host": "non_empty_string", "os" : "non_empty_string", "port": "integer", "username": "******", "password": "******", "certificate_file" : "string", "passphrase" : "string", "root" : "string"}
			)

		platform_instance = Platform.get_instance(parameters["os"])

		return SshServer(parameters["id"], platform_instance, parameters["host"], parameters["port"], parameters["username"], parameters["password"], parameters["certificate_file"], parameters["passphrase"], parameters["root"])
Example #3
0
	def download(cls, url, destination, replace = False, retry = 1):
		"""
		downloads a file from the web
		
		@param url: the url of the file to be downloaded
		@param destination: the destination where the file will be downloaded to
		@param replace: if set True then the downloaded file will replae any existinf file
		@param retry: number of retries
		
		@rtype: bool
		@return: True on success
		
		@raise FileDownloadError: if error during downloading
		"""
		if not Validator.validate(url, "url"):
			raise InvalidParameterError("url", "should be a non-empty string starts with 'http://'")
		if not Validator.validate(destination, "non_empty_string"):
			raise InvalidParameterError('destination', 'should be non-empty string')
		if not Validator.validate(replace, 'boolean'):
			raise InvalidParameterError('replace', 'should be a boolean value')
		if not Validator.validate(retry, 'integer'):
			raise InvalidParameterError('getting', 'should be an integer value')
		
		separator = Platform.get_current().get_separator()
		
		if not (re.match(r'/', destination) or re.match(r'[a-zA-Z]:\\', destination)):
			destination = destination.rstrip(separator)
		
		while retry:
			retry -= 1
			try:
				result = urllib2.urlopen(url, "")
				
				if os.path.exists(destination):
					if os.path.isdir(destination):
						if result.headers.has_key('content-disposition'):
							tmp = result.headers.dict['content-disposition']
							index = tmp.find('filename=')
							if index == -1:
								name = 'attachment'
							else:
								name = tmp[index+9: ]
								name = name.split(' ')[0]
						else:
							name = result.geturl()
							name = name.split('?')[0]
							name = name.rstrip('/')
							index = name.rfind('/')
							name = name[index+1:]
						
						destination = destination + separator + name
					
					else:
						if os.path.isfile(destination):
							if replace:
								os.remove(destination)
							else:
								raise FileExistsError, 'the destination file already exists'
						else:
							raise FileExistsError, 'destination is non-file, system cannot replace a non file'
					
				file = open(destination, "wb")
				
				buffer = result.read(4096)
				
				while len(buffer) != 0:
					file.write(buffer)
					buffer = result.read(4096)
				
				file.close()	
				
			except Exception, e:
				if retry == 0:
					raise FileDownloadError, str(e)
			
			else:
				break
Example #4
0
	def __init__(self, root = ""):
		
		platform = Platform.get_current()
		super(LocalClient, self).__init__(platform, root)