Example #1
0
	def search(self, params, return_callback=None):
		try: 
			if HEUri.getPath(params[0])  != "":
				if self.__server == None:
					self.__server = WSDL.Proxy(self.__wsdl_path)
				else:
					raise HEException.HEException("WSDL file is not set")
				if self.__key != None:
					length = 10
					if len(params) == 2:
						length = HEUri.getPath(params[1])
					results = self.__server.doGoogleSearch(self.__key, HEUri.getPath(params[0]) , 0, length, False, "", False, "", "utf-8", "utf-8")
					result = []
					for data in results.resultElements:
						cur = []
						cur.append(data.URL)
						cur.append(data.title)
						cur.append(data.summary)
						result.append(cur)
					if return_callback:
						return_callback(result)
					else:
						return result
				else:
					raise HEException.HEException("Key is not set")
			else:
				raise HEException.HEException("Search string is empty")
		except:
			raise HEException.HEException("Problem with search")
	def go_up(self, params, return_callback=None):
		params[0] = self.checkUri(params[0])
		pos = HEUri.getPath(params[0]).rfind("/")
		if pos == 0:
			 return_callback(params[0])
		else:
			params[0] = HEUri.getUri("file", HEUri.getPath(params[0])[0:HEUri.getPath(params[0])[0:len(HEUri.getPath(params[0]))-2].rfind("/")])
			return_callback(params[0])
	def get(self, params, return_callback=None):
		params[0] = self.checkUri(params[0])
		if os.path.exists(HEUri.getPath(params[0])):
			item_list = os.listdir(HEUri.getPath(params[0]))
			tmp_list = [params[0]]
		
			for item in item_list:
				if os.path.isdir(HEUri.getPath(params[0])+"/"+item):
					tmp_list.append(params[0]+"/"+item)
				else:
					tmp_list.append(params[0]+"/"+item)
			
			return_callback(tmp_list)
		else:
			raise HEException.HEException("path "+params[0]+" does not exist")
Example #4
0
	def set_wsdl(self, params, callback=None):
		params[0] = "/" + HEUri.getPath(params[0])
		if params[0] != "" and os.path.isfile(params[0]):
			self.__wsdl_path = params[0]
			return "OK"
		else:
			raise HEException.HEException("WSDL path is empty or the WSDL file does not exist")
Example #5
0
	def set_key(self, params, callbacks=None):
		params[0] = HEUri.getPath(params[0])
		if params[0] != "":
			self.__key = params[0]
			return "OK"
		else:
			raise HEException.HEException("Google API Key is empty")
	def checkUri(self, uri):
		if HEUri.getPath(uri) == "":
			uri = HEUri.getUri("file","/")
		while string.find(HEUri.getPath(uri), "//") != -1:
			uri = HEUri.getUri("file", string.replace(HEUri.getPath(uri), "//", "/"))
		if HEUri.getPath(uri)[len(HEUri.getPath(uri))-1] != "/":
			uri += "/"
		return uri
Example #7
0
	def request(self, instruction, params, return_cb, error_cb):
		if len(params) >= 1:
			plugin_type = HEUri.getPluginType(params[0])
			# check if the plugin is loaded
			if not self.__plugins.has_key(plugin_type):
				try:
					self.loadPlugin(plugin_type)
				except HEException.HEException, e:
					raise e
				print "[HECore]\t'"+plugin_type+"' loaded"
			# check if the backend provides this request and excute it
			method = self.__plugins[plugin_type].getInstruction(instruction)
			if method:
				try:
					thread = RequestThread(method, params, return_cb)
					thread.start()
					return "OK"
				except HEException.HEException, e:
					return "Error"
	def stat(self, params, return_callback=None):
		params[0] = self.checkUri(params[0])
		if os.path.exists(HEUri.getPath(params[0])):
			return_callback(os.stat(HEUri.getPath(params[0]))[ST_SIZE])
		else:
			raise HEException.HEException("path "+params[0]+" does not exist")
	def exists(self, params, return_callback=None):
		params[0] = self.checkUri(params[0])
		if os.path.exists(HEUri.getPath(params[0])):
			return_callback(True)
		else:
			return_callback(False)
	def remove(self, params, return_callback=None):
		params[0] = self.checkUri(params[0])
		if os.path.exists(HEUri.getPath(params[0])):
			os.remove(HEUri.getPath(params[0]))
		else:
			raise HEException.HEException("path "+params[0]+" does not exist")