2 Project: BlueHi: A plugin for Canola
3 File name: bluetooth_manager.py
5 Description: This software was developed in Zagaia Project
8 Antonio R. de C. Junior <brankinhu@gmail.com>
9 Henry Miller M. Bilby <henrymiller.engenheiro@gmail.com>
10 Mauricio Figueiredo <mauricio.figueiredo@fucapi.br>
11 Samuel de Oliveira Fagundes <sf.oliveira@gmail.com>
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or
16 (at your option) any later version.
18 This program is distributed in the hope that it will be useful, but
19 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23 You should have received a copy of the GNU General Public License along
24 with this program; if not, write to the Free Software Foundation, Inc.,
25 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 from lightblue import BluetoothError
32 from lightblue.obex import OBEXError
34 class BluetoothManager:
36 def search_devices(self):
37 print "def search_devices(self):"
38 self.devices = lightblue.finddevices()
41 def connect(self, address):
42 port = self.find_port(address)
44 self.list = [address, port]
46 print "Nao foi possivel estabelecer conexao com o dispositivo"
49 def send_file(self, path):
50 address = self.list[0]
52 file_length = self.get_file_lenght(path)
53 file_name = self.get_file_name(path)
55 client = lightblue.obex.OBEXClient(address, port)
58 put_response = client.put({"name": file_name, "length": file_length}, file(path))
59 if put_response.code != lightblue.obex.OK:
60 print "Cancelado pelo usuario"
71 def find_services(self, address):
72 return lightblue.findservices(address)
74 def find_port(self, address):
76 services = self.find_services(address)
79 if i[2] == "OBEX Object Push":
83 def get_file_lenght(self, file):
84 return int(os.path.getsize(file))
86 def get_file_name(self, file):
87 file = file.split("/")