├── setup.cfg
├── MANIFEST.in
├── .gitignore
├── src
├── textoter
│ ├── __init__.py
│ ├── data
│ │ ├── textoter.desktop
│ │ └── textoter.glade
│ └── textoter.py
└── btphonelib
│ ├── __init__.py
│ └── btphone.py
├── screenshot.png
├── CHANGES.txt
├── setup.py
├── pyproject.toml
├── README.md
└── LICENSE
/setup.cfg:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/MANIFEST.in:
--------------------------------------------------------------------------------
1 | include data/*
2 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *~
2 | __pycache__
3 | dist
4 | tmp
--------------------------------------------------------------------------------
/src/textoter/__init__.py:
--------------------------------------------------------------------------------
1 | from .textoter import main
2 |
--------------------------------------------------------------------------------
/src/btphonelib/__init__.py:
--------------------------------------------------------------------------------
1 | from .btphone import BTPhone
2 |
--------------------------------------------------------------------------------
/screenshot.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/agardelein/textoter/HEAD/screenshot.png
--------------------------------------------------------------------------------
/src/textoter/data/textoter.desktop:
--------------------------------------------------------------------------------
1 | [Desktop Entry]
2 | Encoding=UTF-8
3 | Name=textoter
4 | Exec=textoter
5 | Type=Application
6 | Terminal=false
--------------------------------------------------------------------------------
/CHANGES.txt:
--------------------------------------------------------------------------------
1 | * Version 0.52
2 | Fixed issue #1 where Textoter crashed in case of no configuration file
3 | Fixed issue #2 missing dependency
4 | Updated documentation
5 |
--------------------------------------------------------------------------------
/setup.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python3
2 |
3 | import setuptools
4 | from os import path
5 |
6 | def get_long_description():
7 | # From https://packaging.python.org/guides/making-a-pypi-friendly-readme/
8 | this_directory = path.abspath(path.dirname(__file__))
9 | with open(path.join(this_directory, 'README.md'), encoding='utf-8') as f:
10 | long_description = f.read()
11 | return long_description
12 |
13 | setuptools.setup(
14 | long_description=get_long_description(),
15 | )
16 |
--------------------------------------------------------------------------------
/pyproject.toml:
--------------------------------------------------------------------------------
1 | [build-system]
2 | requires = ["setuptools>=61.0"]
3 | build-backend = "setuptools.build_meta"
4 |
5 | [project]
6 | name = "textoter"
7 | version = "0.51"
8 | authors = [
9 | { name="Arnaud Gardelein", email="arnaud@oscopy.org" },
10 | ]
11 | description="Send SMS from your mobile phone. Phone is connected via Bluetooth"
12 | # dynamic = ["long_description"]
13 | readme = "README.md"
14 | requires-python = ">3.10"
15 | classifiers = [
16 | "Programming Language :: Python :: 3",
17 | "License :: OSI Approved :: GNU General Public License v3 (GPLv3)",
18 | "Topic :: Communications :: Telephony",
19 | "Topic :: Desktop Environment :: Gnome",
20 | "Intended Audience :: End Users/Desktop",
21 | ]
22 | keywords = ["gtk" ,"sms" ,"mms" ,"bluetooth" ,"phone" ,"send" ,"texto"]
23 | dependencies = [
24 | "xdg",
25 | "pyxdg",
26 | "vobject",
27 | "PyGObject",
28 | ]
29 |
30 | [project.urls]
31 | Homepage = "https://github.com/agardelein/textoter"
32 | Issues = "https://github.com/agardelein/textoter/issues"
33 |
34 | [project.scripts]
35 | textoter = "textoter:main"
36 |
37 | [tool.setuptools.packages.find]
38 | where = ["src"]
39 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | textoter
2 | ========
3 | Textoter is a software under GPLv3 license to write SMS and send them using a phone connected with Bluetooth.
4 |
5 | It just works, no need to install additional apps on the phone.
6 |
7 | It is written as an alternative to the phone's proprietary interface.
8 |
9 | 
10 |
11 | Features
12 | ========
13 | * Use Bluetooth
14 | * No need of additional apps on your phone
15 | * Import contacts from phone
16 | * Contact name completion
17 | * Notification on message status
18 |
19 | Tested on
20 | ---------
21 | * Samsumg A41
22 | * Nokia 800 Tough
23 |
24 | Installing Textoter
25 | ===================
26 | Dependencies
27 | ------------
28 | Textoter is a Gnome application, written in Python. It uses bluez stack /via/ DBus. The contacts are parsed using `vobject`.
29 | To detect phone capabilities, textoter uses `sdptool` from `bluez` package.
30 |
31 | Install
32 | -------
33 | First you may need to install dependencies, for instance on Debian derivatives:
34 |
35 | apt-get install bluez gnome-bluetooth python3-vobject python3-gi python3-pip
36 |
37 | And then textoter:
38 |
39 | pip install textoter
40 |
41 | User interface
42 | ==============
43 | To be detected by Textoter, your phone should have been connected at least one time with the computer using the [GNOME's Bluetooth interface](https://help.gnome.org/users/gnome-help/stable/bluetooth-connect-device.html.en).
44 | Some phones even need to be paired with computer.
45 |
46 | Starting Textoter
47 | -----------------
48 | From GNOME Shell, start to type in the search bar `textoter` and click when it appears.
49 |
50 | From command line launch Textoter with:
51 |
52 | textoter
53 |
54 | Phone selection
55 | --------------
56 | On startup Textoter detects the available phones and list them in `Devices`.
57 | Select the phone from this drop-down list.
58 |
59 | Recipient
60 | ---------
61 | To define the recipient, either:
62 | * type directly the phone number in the `To :` field, preferrably in international format `+123456789`
63 | * Use phone's contacts
64 |
65 | For the latter:
66 | * load the phone contacts by clicking on the `phone` icon-button. Depending on your phone settigs, you may have to confirm that the computer can access phone's contacts.
67 | * select in the drop-down list the contact. You can also type the contact name and Textoter will propose a list of possible completions.
68 |
69 | Message
70 | -------
71 | Type the message in the text area under `Message`.
72 |
73 | Send
74 | ----
75 | Click on the `Send` button. Textoter then transmit the message to the phone. Depending on your phone, you will have to confirm that the computer can access phone messages.
76 |
77 | Quit
78 | ----
79 | Click on `Quit` button. Textoter then save the current phone and exits.
80 | On subsequent launch, textoter will reuse the last phone selected.
81 |
82 | Contributing
83 | ============
84 | Bug can be reported on [GitHub](https://github.com/agardelein/textoter/issues)
85 |
86 | Credits
87 | =======
88 | Written by Arnaud Gardelein, using code configuration from [oscopy](https://github.com/agardelein/oscopy).
89 |
--------------------------------------------------------------------------------
/src/textoter/data/textoter.glade:
--------------------------------------------------------------------------------
1 |
2 |
3 |
17 |
18 |
19 |
31 |
39 |
44 |
49 |
270 |
271 |
272 |
273 |
274 |
275 |
276 |
277 |
--------------------------------------------------------------------------------
/src/textoter/textoter.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python3
2 | # Textoter: A stupid application to send sms using Bluetooth Phone
3 | # Copyright (C) 2018 - 2021 Arnaud Gardelein
4 |
5 | # This program is free software: you can redistribute it and/or modify
6 | # it under the terms of the GNU General Public License as published by
7 | # the Free Software Foundation, either version 3 of the License, or
8 | # (at your option) any later version.
9 | #
10 | # This program is distributed in the hope that it will be useful, but
11 | # WITHOUT ANY WARRANTY; without even the implied warranty of
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | # General Public License for more details.
14 | #
15 |
16 | import gi
17 | gi.require_version('Gtk', '3.0')
18 | gi.require_version('Notify', '0.7')
19 | from gi.repository import Gtk
20 | from gi.repository import Notify
21 | from gi.repository import Pango
22 | import sys, os, stat
23 | import tempfile
24 | import configparser
25 | from xdg import BaseDirectory
26 | import locale
27 | from btphonelib import BTPhone
28 | from importlib.resources import files
29 |
30 | UIFILE = 'textoter.glade'
31 |
32 | class TextoterWindow(Gtk.ApplicationWindow):
33 | # The main window
34 | def __init__(self, app, btmessage):
35 | Gtk.ApplicationWindow.__init__(self, title='Textoter', application=app)
36 | self.builder = Gtk.Builder()
37 | self.app = app
38 | self.btmessage = btmessage
39 | btmessage.set_iface_added_callback(self.interface_added)
40 | btmessage.set_iface_removed_callback(self.interface_removed)
41 | uifile = files('textoter.data').joinpath(UIFILE)
42 | try:
43 | self.builder = Gtk.Builder.new_from_file(str(uifile))
44 | except:
45 | print(f"UI File not found: {uifile}")
46 | sys.exit()
47 |
48 | b = self.builder.get_object('TextoterBox')
49 | handlers = {'OkButton_clicked_cb': self.ok_clicked,
50 | 'CancelButton_clicked_cb': self.cancel_clicked,
51 | 'PhoneButton_clicked_cb': self.phone_ab_clicked,
52 | }
53 | self.builder.connect_signals(handlers)
54 |
55 | self.ab_store = self.builder.get_object('ab_store')
56 |
57 | self.add(b)
58 | self.set_default_size(300, 500)
59 | self.phone_number_entry = self.builder.get_object('PhoneNumberEntry')
60 | self.sms_content_text_view = self.builder.get_object('SMSTextView')
61 | self.store = self.builder.get_object('store')
62 | for num in self.app.actions['history_list'][1]:
63 | iter = self.store.append([num])
64 | cbx = self.builder.get_object('PhoneNumberComboBox')
65 | cbx.set_entry_text_column(3)
66 | cbx.clear()
67 | r = Gtk.CellRendererText()
68 | cbx.pack_start(r, False)
69 | cbx.add_attribute(r, 'text', 0)
70 | r = Gtk.CellRendererText(style=Pango.Style.ITALIC)
71 | cbx.pack_start(r, False)
72 | cbx.add_attribute(r, 'text', 1)
73 | self.pn_cbx = cbx
74 |
75 | ec = Gtk.EntryCompletion.new()
76 | self.phone_number_entry.set_completion(ec)
77 | ec.set_model(self.ab_store)
78 | ec.set_text_column(3)
79 | ec.set_inline_selection(True)
80 | ec.set_inline_completion(True)
81 | ec.set_popup_completion(True)
82 | # FIXME: Setting CellRenderer appears not to work
83 | ec.clear()
84 | r = Gtk.CellRendererText()
85 | ec.pack_start(r, False)
86 | ec.add_attribute(r, 'text', 0)
87 | r = Gtk.CellRendererText(style=Pango.Style.ITALIC)
88 | ec.pack_start(r, False)
89 | ec.add_attribute(r, 'text', 1)
90 |
91 | cbx = self.builder.get_object('dev_cbx')
92 | self.dev_store = self.builder.get_object('dev_store')
93 | r = Gtk.CellRendererText()
94 | cbx.pack_start(r, True)
95 | cbx.add_attribute(r, 'text', 1)
96 | self.dev_cbx = cbx
97 |
98 | for dev, name in self.btmessage.get_devices().items():
99 | self.interface_added(dev, name)
100 |
101 | def ok_clicked(self, button):
102 | # Send message
103 |
104 | # Retrieve device
105 | iter = self.dev_cbx.get_active_iter()
106 | if iter is not None:
107 | model = self.dev_cbx.get_model()
108 | row = model[iter]
109 | my_devad = row[0]
110 | iter = self.pn_cbx.get_active_iter()
111 | num = None
112 | if iter is None:
113 | # Attemp to retrieve number from entry text
114 | print('Iter is None')
115 | t = self.phone_number_entry.get_text()
116 | for row in self.ab_store:
117 | if t == row[3]:
118 | num = row[1]
119 | if num is None:
120 | # Check whether a bare number has been entered
121 | try:
122 | float(t)
123 | except ValueError:
124 | num = None
125 | else:
126 | num = t
127 | else:
128 | model = self.pn_cbx.get_model()
129 | row = model[iter]
130 | num = row[1]
131 | print(num)
132 | if num is None:
133 | return
134 |
135 | # Process specific for France
136 | if locale.getlocale()[0].startswith('fr') and\
137 | (num.startswith('06') or num.startswith('07')):
138 | num = '+33' + num[1:]
139 |
140 | tb = self.sms_content_text_view.get_buffer()
141 | t = tb.get_text(tb.get_start_iter(),tb.get_end_iter(), True)
142 | if not t:
143 | return
144 |
145 | # Create the file in the outgoing directory
146 | content = '\n'.join((' '.join(('To:', num)), '', t))
147 | fp = tempfile.NamedTemporaryFile(mode='w+t', delete=False, prefix='arnaud-', dir='/tmp')
148 | os.chmod(fp.name, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)
149 | m = self.btmessage.prepare_message(num, t)
150 | print('m <{}>'.format(m))
151 | fp.write(m)
152 | fp.close()
153 | port = self.app.actions['ports'].get(my_devad, None)
154 | res = self.btmessage.create_session(my_devad, port)
155 | if not res:
156 | iter = self.dev_store.get_iter(self.dev_cbx.get_active())
157 | self.send_notification('No connection with phone', 'Unable to send message to {} ({})'.format(self.dev_store.get_value(iter, 1), my_devad))
158 | else:
159 | res = self.btmessage.push_message(fp.name)
160 | self.btmessage.remove_session()
161 | self.app.actions['ports'] = {my_devad: self.btmessage.port}
162 | if res:
163 | self.send_notification('Message sent', 'To %s' % num)
164 | tb.delete(tb.get_start_iter(),tb.get_end_iter())
165 | else:
166 | self.send_notification('Message failed', 'To %s' % num)
167 |
168 | # Manage history
169 | history_list = self.app.actions['history_list'][1]
170 | if num in history_list:
171 | history_list.remove(num)
172 | history_list = [num]
173 | history_list.extend(self.app.actions['history_list'][1])
174 | history_list = history_list[0:10]
175 | self.app.actions['history_list'] = (self.app.actions['history_list'][0],
176 | history_list)
177 | # Manage history in the store
178 | def func(model, path, iter, num):
179 | # Remove the first occurrence of number
180 | if model.get_value(iter, 0) == num:
181 | model.remove(iter)
182 | return True
183 | else:
184 | return False
185 | self.store.foreach(func, num)
186 | iter = self.store.prepend([num])
187 |
188 | # Manage device
189 | self.app.actions['device'] = (self.app.actions['device'][0], my_devad)
190 |
191 | def cancel_clicked(self, button):
192 | # Quit
193 | self.app.write_config()
194 | sys.exit()
195 |
196 | def phone_ab_clicked(self, button):
197 | iter = self.dev_store.get_iter(self.dev_cbx.get_active())
198 | devad = self.dev_store.get_value(iter, 0)
199 | vcards = self.btmessage.read_phonebook(devad)
200 | if not vcards:
201 | self.send_notification('No connection with phone', 'Unable to load contacts from {} ({})'.format(self.dev_store.get_value(iter, 1), devad))
202 | return
203 | for vcard in vcards:
204 | for tel in vcard.contents.get('tel', [None]):
205 | if tel is None:
206 | continue
207 | self.ab_store.append([vcard.fn.value,
208 | tel.value,
209 | '', # Type - FIXME TO BE FILLED
210 | '{} ({})'.format(vcard.fn.value,
211 | tel.value)])
212 |
213 | def send_notification(self, title, text, file_path_to_icon=''):
214 | # Used to create and show the notification
215 | n = Notify.Notification.new(title, text, file_path_to_icon)
216 | n.set_timeout(5000)
217 | n.show()
218 |
219 | def interface_added(self, dev, name):
220 | """ Update the device list with new device
221 | """
222 | store = self.dev_store
223 | iter = store.get_iter_first()
224 | while iter is not None:
225 | if store[iter][0] == dev:
226 | # Found item with same address
227 | break
228 | iter = store.iter_next(iter)
229 | if iter is None:
230 | iter = store.append([dev, name])
231 | else:
232 | store.set_row(iter, [dev, name])
233 | if dev == self.app.actions['device'][1]:
234 | self.dev_cbx.set_active_iter(iter)
235 |
236 | def interface_removed(self, dev):
237 | """ Remove device from the device list
238 | """
239 | store = self.dev_store
240 | iter = store.get_iter_first()
241 | while iter is not None:
242 | if store[iter][0] == dev:
243 | store.remove(iter)
244 | break
245 | iter = store.iter_next(iter)
246 |
247 | class TextoterApplication(Gtk.Application):
248 |
249 | SECTION = 'Textoter'
250 | HISTORY_LIST = 'numbers'
251 | DEVICE = 'device'
252 |
253 | def __init__(self):
254 | Gtk.Application.__init__(self)
255 | Notify.init('Textoter')
256 | self.win = None
257 | self.bt = BTPhone()
258 |
259 | def do_activate(self):
260 | # Setup the main window
261 | win = TextoterWindow(self, self.bt)
262 | win.show_all()
263 | self.win = win
264 |
265 | def do_startup(self):
266 | # Read the configuration file, connect monitor to directories
267 | Gtk.Application.do_startup(self)
268 | self.init_config()
269 | self.read_config()
270 |
271 | def init_config(self):
272 | # Initialize configuration stuff
273 | path = BaseDirectory.save_config_path('textoter')
274 | self.config_file = os.path.join(path, 'textoter')
275 | section = TextoterApplication.SECTION
276 | self.config = configparser.RawConfigParser()
277 | self.config.add_section(section)
278 |
279 | # Defaults
280 | self.config.set(section, TextoterApplication.HISTORY_LIST, '')
281 | self.config.set(section, TextoterApplication.DEVICE, '')
282 |
283 | def sanitize_list(self, lst):
284 | # Remove leading and trailing white spaces when creating the list
285 | return [x for x in [x.strip() for x in lst] if len(x) > 0]
286 |
287 | def actions_from_config(self, config):
288 | # Retrieve infos from configuration file
289 | section = TextoterApplication.SECTION
290 |
291 | history_list = config.get(section, TextoterApplication.HISTORY_LIST)
292 | history_list = self.sanitize_list(history_list.split(';'))
293 | device = config.get(section, TextoterApplication.DEVICE)
294 | device = device.strip()
295 | actions = {
296 | 'history_list': (True, history_list),
297 | 'device': (True, device),
298 | 'ports': {},
299 | }
300 | for s in config.sections():
301 | if s in [TextoterApplication.SECTION]:
302 | continue
303 | actions['ports'][s] = config.getint(s, 'port')
304 | print(actions)
305 | return actions
306 |
307 | def actions_to_config(self, actions, config):
308 | # Send infos to configuration file
309 | section = TextoterApplication.SECTION
310 | history_list = ';'.join(actions['history_list'][1])
311 | device = actions['device'][1]
312 | config.set(section, TextoterApplication.HISTORY_LIST, history_list)
313 | config.set(section, TextoterApplication.DEVICE, device)
314 | for dev, port in actions['ports'].items():
315 | if not config.has_section(dev):
316 | config.add_section(dev)
317 | config.set(dev, 'port', port)
318 |
319 | def read_config(self):
320 | # Just read the configuration file
321 | self.config.read(self.config_file)
322 | self.actions = self.actions_from_config(self.config)
323 |
324 | def write_config(self):
325 | # Just write the configuration file
326 | self.actions_to_config(self.actions, self.config)
327 | with open(self.config_file, 'w') as f:
328 | self.config.write(f)
329 |
330 | # Go !
331 | def main():
332 | app = TextoterApplication()
333 | exit_status = app.run(sys.argv)
334 | sys.exit(exit_status)
335 |
336 | if __name__ == '__main__':
337 | main()
338 |
339 |
--------------------------------------------------------------------------------
/src/btphonelib/btphone.py:
--------------------------------------------------------------------------------
1 | # bt.py: A library to communicate with a phone using Bluetooth
2 | # Copyright (C) 2018 - 2021 Arnaud Gardelein
3 |
4 | # This program is free software: you can redistribute it and/or modify
5 | # it under the terms of the GNU General Public License as published by
6 | # the Free Software Foundation, either version 3 of the License, or
7 | # (at your option) any later version.
8 | #
9 | # This program is distributed in the hope that it will be useful, but
10 | # WITHOUT ANY WARRANTY; without even the implied warranty of
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 | # General Public License for more details.
13 | #
14 |
15 | import gi
16 | from gi.repository import GLib
17 | from gi.repository import Gio
18 | from subprocess import run
19 | import io
20 | import traceback
21 | import xml.etree.ElementTree as ET
22 | import vobject
23 | import time
24 | DBUS_NAME = 'org.bluez.obex'
25 | DBUS_PATH = '/org/bluez/obex'
26 | DBUS_SYS_NAME = 'org.bluez'
27 | DBUS_SYS_PATH = '/org/bluez'
28 | HCI = 'hci'
29 |
30 | header = 'BEGIN:BMSG\r\nVERSION:1.0\r\nSTATUS:READ\r\nTYPE:MMS\r\nFOLDER:null\r\nBEGIN:BENV\r\n'
31 | footer = 'END:BENV\r\nEND:BMSG\r\n'
32 | vcard2 = 'BEGIN:VCARD\r\nVERSION:2.1\r\nN:null;;;;\r\nTEL:{}\r\nEND:VCARD\r\n'
33 | body2 = 'BEGIN:BBODY\r\nLENGTH:{}\r\nBEGIN:MSG\r\n{}\r\nEND:MSG\r\nEND:BBODY\r\n'
34 | msg_header = 'BEGIN:MSG\r\n'
35 | msg_footer = '\r\nEND:MSG\r\n'
36 | msg_length = 'BEGIN:BBODY\r\nLENGTH:{}\r\n'
37 |
38 | class BTPhone:
39 | """ A class representing a phone connected using Bluetooth
40 |
41 | The object has two main objectives:
42 | 1. Read the phone book
43 | 2. Send a message
44 | Both use OBEX through DBus to communication with the device.
45 |
46 | The sequence to use the object after instanciation is:
47 | 1. Read the phone book with read_phonebook()
48 | 2. Prepare message in bMesssage format with prepare_message()
49 | 3. Create a session to send the message
50 | 4. Send the message with push_message()
51 | 5. Close the session
52 | """
53 | def __init__(self, bus_name=DBUS_NAME, bus_path=DBUS_PATH):
54 | self.bus_name = bus_name
55 | self.bus_path = bus_path
56 | self.bus = Gio.bus_get_sync(Gio.BusType.SESSION)
57 | self.sysbus = Gio.bus_get_sync(Gio.BusType.SYSTEM)
58 | self.paths2dev = {}
59 | self.path = None
60 | self.port = None
61 | self.iface_added_cb = None
62 | self.iface_removed_cb = None
63 | self.signal_subscribe('org.freedesktop.DBus.ObjectManager',
64 | 'InterfacesAdded',
65 | self.interfaces_added,
66 | None,
67 | bus=self.sysbus,
68 | name=DBUS_SYS_NAME,
69 | path='/')
70 | self.signal_subscribe('org.freedesktop.DBus.ObjectManager',
71 | 'InterfacesRemoved',
72 | self.interfaces_removed,
73 | None,
74 | bus=self.sysbus,
75 | name=DBUS_SYS_NAME,
76 | path='/')
77 | # Initialize the list on first time
78 | self.get_devices()
79 |
80 | def read_phonebook(self, devad):
81 | """ Read the PhoneBook of devad
82 |
83 | While transferring the data on Bluetooth link, poll the status
84 | every 0.1 s.
85 |
86 | Parameters
87 | ----------
88 | devad: str
89 | The device address to read the phonebook from
90 |
91 | Returns
92 | -------
93 | list of vcard
94 | The list of the parsed vcards
95 | """
96 | vcards = []
97 | # Retrieve the Bluetooth port
98 | port = self.get_device_port(devad, service_id='0x112f')
99 |
100 | # Perform session to retrieve the phonebook
101 | self.create_session(devad, port, target='pbap')
102 | self.select_pb()
103 | res = self.pullall_pb()
104 | if res is None:
105 | return vcards
106 | fn = res[1]['Filename']
107 | transfer_path = res[0]
108 | status = res[1]['Status']
109 |
110 | # Wait for transfer completion
111 | while status == 'queued':
112 | # poll every 0.1 s
113 | time.sleep(0.1)
114 | res = self.get_transfer_status(transfer_path)
115 | if res is None:
116 | break
117 | status = res[0]
118 | data = ''
119 | # Process vcards file
120 | with open(fn, 'r') as f:
121 | for line in f:
122 | data = data + line
123 | if 'END:VCARD' in line:
124 | vcards.append(vobject.readOne(data))
125 | data = ''
126 |
127 | # Close the session, this delete the temporary transfer file
128 | self.remove_session()
129 | return vcards
130 |
131 | def find_service(self, record, service_id='0x1132'):
132 | """ Parse XML to find relevant record including port for MAP
133 | Return port, None if not found
134 |
135 | Parameters
136 | ----------
137 | record: str
138 | A service record in XML format
139 |
140 | service_id: str (default '0x1132')
141 | The service to find
142 |
143 | Returns
144 | -------
145 | int or None
146 | The port related to service_id, None if not found
147 | """
148 | root = ET.fromstring(record)
149 | if root.find('./attribute[@id="0x0001"]/sequence/uuid[@value="{}"]'.format(service_id)) is not None:
150 | port = root.find('./attribute[@id="0x0004"]/sequence/sequence/uuid[@value="0x0003"]/../uint8')
151 | print(port.attrib)
152 | if port is None:
153 | return None
154 | else:
155 | return int(port.attrib['value'], 16)
156 |
157 | def get_device_port(self, devad, service_id='0x1132'):
158 | """ Lookup for service on device
159 |
160 | Browse device using sdptool with XML output, then parse the XML
161 | sdptool is run on a separate process, output is captured.
162 | Capture is then analyzed with self.find_service()
163 |
164 | Parameters
165 | ----------
166 | devad: str
167 | The device to scan
168 |
169 | service_id: str (default '0x1132')
170 | The service ID to lookup, in hex format
171 | """
172 | res = run(['/usr/bin/sdptool', 'browse', '--xml', devad],
173 | capture_output=True,
174 | encoding='utf-8')
175 | b_in = io.StringIO(res.stdout)
176 | record = ''
177 | for line in b_in:
178 | if line.strip().startswith(''):
182 | # Record completed
183 | record = record + line
184 | # Parse data recorded so far
185 | self.port = self.find_service(record, service_id)
186 | if self.port is not None:
187 | break
188 | else:
189 | # Append line
190 | if line.strip().startswith('<'):
191 | record = record + line
192 | else:
193 | continue
194 | return self.port
195 |
196 | def introspect(self, bus, name, path):
197 | """ Instrospect an object on DBus
198 |
199 | Parameters
200 | ----------
201 | bus: Gio.DBusConnection
202 | The bus to use
203 |
204 | name: str
205 | The name of the bus to use
206 |
207 | path: str
208 | The path to use
209 |
210 | Returns
211 | -------
212 | res: GLib.Variant or None (default None)
213 | The object introspection results
214 | """
215 | res = self.bus_call_sync('org.freedesktop.DBus.Introspectable',
216 | 'Introspect',
217 | name=name, path=path, bus=bus,
218 | reply=GLib.VariantType('(s)'))
219 | return res
220 |
221 | def get_properties(self, bus, name, path):
222 | """ Returns properties of a device
223 |
224 | Parameters
225 | ----------
226 | bus: Gio.DBusConnection
227 | The bus to use
228 |
229 | name: str
230 | The name of the bus to use
231 |
232 | path: str
233 | The path to use
234 |
235 | Returns
236 | -------
237 | res: GLib.Variant or None (default None)
238 | The object properties
239 | """
240 | args = GLib.Variant('(s)', ('org.bluez.Device1',)) # Parameters
241 | reply = GLib.VariantType('(a{sv})') # reply_type
242 | res = self.bus_call_sync('org.freedesktop.DBus.Properties',
243 | 'GetAll',
244 | name=name, path=path, bus=bus,
245 | args=args, reply=reply)
246 | return res
247 |
248 | def get_devices(self):
249 | """ Retrieve list of Bluetooth Devices
250 |
251 | Use DBus's GetManagedObjects
252 |
253 | Returns
254 | -------
255 | devs: dict of str:str pairs
256 | A dict associating the bluetooth device address with its name
257 | """
258 | # Look for adapter
259 | res = self.bus_call_sync('org.freedesktop.DBus.ObjectManager',
260 | 'GetManagedObjects',
261 | bus=self.sysbus,
262 | name=DBUS_SYS_NAME,
263 | path='/')
264 | devs = {}
265 | for path, dev in res[0].items():
266 | mydev = dev.get('org.bluez.Device1', None)
267 | if mydev is not None:
268 | devs[mydev.get('Address', None)] = mydev.get('Name', None)
269 | self.interfaces_added(None, None, None, None, None,
270 | (path, dev), None)
271 | return devs
272 |
273 | def create_session(self, dev=None, port=None, target='map'):
274 | """ Create session on DBus client
275 |
276 | Parameters
277 | ----------
278 | dev: str or None (default None)
279 | The device address to use
280 |
281 | port: int or None (default None)
282 | The RFCOMM port to use, if None the device is scanned to retrieve
283 | the service.
284 |
285 | target: str (default 'map')
286 | The target service name
287 |
288 | Returns
289 | -------
290 | self.path: tuple containing one objectpath
291 | The path to the created session
292 | """
293 | # FIXME: What happens when dev is None ?
294 | if port is None:
295 | print('Scanning device')
296 | self.get_device_port(dev)
297 | print('port:', self.port)
298 | else:
299 | print('Using already known port', port)
300 | self.port = port
301 | if self.port is None:
302 | return None
303 | args = GLib.Variant('(sa{sv})', (dev,
304 | {'Target': GLib.Variant('s', target),
305 | 'Channel': GLib.Variant('y', self.port),}))
306 | self.path = self.bus_call_sync('org.bluez.obex.Client1',
307 | 'CreateSession',
308 | path=self.bus_path,
309 | args=args)
310 |
311 | print('path:', self.path)
312 | return self.path
313 |
314 | def remove_session(self):
315 | """ Remove session from DBus client
316 | """
317 | res = self.bus_call_sync('org.bluez.obex.Client1',
318 | 'RemoveSession',
319 | args=self.path, name=self.bus_name,
320 | path=self.bus_path)
321 | return
322 |
323 | def push_message(self, filename):
324 | """ Push message to phone for transmission
325 | """
326 | args = GLib.Variant('(ssa{sv})', (filename, '/telecom/msg/outbox', {},))
327 | res = self.bus_call_sync('org.bluez.obex.MessageAccess1',
328 | 'PushMessage',
329 | args=args)
330 | return res[1]['Status'] == 'queued'
331 |
332 | def select_pb(self, location='int', pb='pb'):
333 | """ Select Phonebook
334 | """
335 | args = GLib.Variant('(ss)', (location, pb))
336 | res = self.bus_call_sync('org.bluez.obex.PhonebookAccess1',
337 | 'Select',
338 | args=args)
339 | return res
340 |
341 | def pullall_pb(self):
342 | """ Retrieve contacts from Phonebook
343 | """
344 | args = GLib.Variant('(sa{sv})', ('', {},))
345 | res = self.bus_call_sync('org.bluez.obex.PhonebookAccess1',
346 | 'PullAll',
347 | args=args)
348 | return res
349 |
350 | def list_pb(self):
351 | """ List Phonebook directories
352 | """
353 | args = GLib.Variant('(a{sv})', ({},))
354 | res = self.bus_call_sync('org.bluez.obex.PhonebookAccess1',
355 | 'List',
356 | args=args
357 | )
358 | return res
359 |
360 | def get_transfer_status(self, path):
361 | """ Check wether transfer is completed, on completion returns None
362 |
363 | To do this, get properties of transfer on path.
364 |
365 | Parameters
366 | ----------
367 | path: string
368 | The path to the transfer
369 |
370 | Returns
371 | -------
372 | res: tuple or None
373 | None when the transfer is completed
374 | """
375 | args = GLib.Variant('(ss)', ('org.bluez.obex.Transfer1', 'Status'))
376 | res = self.bus_call_sync('org.freedesktop.DBus.Properties',
377 | 'Get',
378 | args=args, path=path)
379 | return res
380 |
381 | def bus_call_sync(self, iface, method, args=None, timeout=240000,
382 | flags=Gio.DBusCallFlags.NONE,
383 | name=None,
384 | path=None,
385 | reply=None,
386 | bus=None,
387 | ):
388 | """ Make a call to DBus object call_sync() with default arguments,
389 | manage GLib.Error and TypeError.
390 |
391 | Parameters
392 | ----------
393 | iface: str
394 | The DBus interface to use
395 |
396 | method: str
397 | The DBus method to call on iface
398 |
399 | args: GLib.Variant or None (default None)
400 | The arguments to pass to called method
401 |
402 | timeout: int (default to 240000)
403 | Timeout value
404 |
405 | flags: Gio.DBusCallFlags (default Gio.DBusCallFlags.NONE)
406 | Flags to pass to call_sync()
407 |
408 | name: str or None (default None)
409 | The name of the bus to use, self.bus_name if None
410 |
411 | path: str or None (default None)
412 | The path to use, self.path[0] if None
413 |
414 | reply: GLib.Variant or None (default None)
415 | The reply to expect from method
416 |
417 | bus: Gio.DBusConnection or None (default None)
418 | The bus to use, self.bus if None
419 |
420 | Returns
421 | -------
422 | res: tuple or None
423 | The result from method call. None if GLib.Error or TypeError were raised
424 | """
425 | print('bus_call_sync', iface, method)
426 | if name is None:
427 | name = self.bus_name
428 | if path is None:
429 | if self.path is None:
430 | return None
431 | else:
432 | path = self.path[0]
433 | if bus is None:
434 | bus = self.bus
435 | try:
436 | res = bus.call_sync(name,
437 | path,
438 | iface,
439 | method,
440 | args,
441 | reply, # Reply type
442 | flags,
443 | timeout,
444 | None, # Cancellable
445 | )
446 | except GLib.Error as e:
447 | print(e.message)
448 | res = None
449 | except TypeError as e:
450 | print(e.message)
451 | res = None
452 | finally:
453 | return res
454 |
455 | def prepare_message(self, num, t):
456 | """ Prepare a message as bMessage format
457 |
458 | Based on https://www.bluetooth.com/specifications/specs/message-access-profile-1-4-2/
459 |
460 | Parameters
461 | ----------
462 | num: str
463 | The destination phone number
464 |
465 | t: str
466 | The text of the message to prepare
467 |
468 | Returns
469 | -------
470 | m: str
471 | The message in bMessage format
472 | """
473 | my_msg = msg_header + t.replace('\n', '\r\n') + msg_footer
474 | my_msg_l = msg_length.format(len(my_msg)) + my_msg
475 | m = header + vcard2.format(num) + my_msg_l + footer
476 | return m
477 |
478 | def set_iface_added_callback(self, callback):
479 | """ Set the callback to use when an interface is added
480 |
481 | Parameter
482 | ---------
483 | callback: callable(str, str)
484 | The callback to use, two arguments are provided,
485 | the device address and the device name
486 | """
487 | self.iface_added_cb = callback
488 |
489 | def set_iface_removed_callback(self, callback):
490 | """ Set the callback to use when an interface is removed
491 |
492 | Parameter
493 | ---------
494 | callback: callable(str)
495 | The callback to use, two arguments are provided,
496 | the device address
497 | """
498 | self.iface_removed_cb = callback
499 |
500 | def interfaces_added(self, bus, name, path, iface, signal_name, args, user_args):
501 | """ When a device is added, update self.paths2dev, call the callback
502 |
503 | Parameters
504 | ----------
505 | bus: Gio.DBusConnection or None (default None)
506 | The bus to use, self.bus if None
507 |
508 | name: str or None (default None)
509 | The name of the bus to use, self.bus_name if None
510 |
511 | path: str or None (default None)
512 | The path to use, self.path[0] if None
513 |
514 | iface: str
515 | The DBus interface to use
516 |
517 | signal_name: str
518 | The DBus signal to subscribe on iface
519 |
520 | args: GLib.Variant
521 | The arguments passed from the signal
522 |
523 | user_args:
524 | Not used
525 | """
526 | opath, dev = args
527 | mydev = dev.get('org.bluez.Device1', None)
528 | if mydev is not None:
529 | if self.iface_added_cb is not None:
530 | self.iface_added_cb(mydev.get('Address', None),
531 | mydev.get('Name', None))
532 | self.paths2dev[str(opath)] = mydev.get('Address', None)
533 |
534 | def interfaces_removed(self, bus, name, path, iface, signal_name, args, user_args):
535 | """ When a device is removed, update self.paths2dev, call the callback
536 |
537 | Parameters
538 | ----------
539 | bus: Gio.DBusConnection or None (default None)
540 | The bus to use, self.bus if None
541 |
542 | name: str or None (default None)
543 | The name of the bus to use, self.bus_name if None
544 |
545 | path: str or None (default None)
546 | The path to use, self.path[0] if None
547 |
548 | iface: str
549 | The DBus interface to use
550 |
551 | signal_name: str
552 | The DBus signal to subscribe on iface
553 |
554 | args: GLib.Variant
555 | The arguments passed from the signal
556 |
557 | user_args:
558 | Not used
559 | """
560 | opath, ifaces = args[0], args[1]
561 | if 'org.bluez.Device1' in ifaces:
562 | if self.iface_removed_cb is not None:
563 | self.iface_removed_cb(self.paths2dev.get(str(opath), None))
564 | del self.paths2dev[str(opath)]
565 |
566 | def signal_subscribe(self, iface, signal_name, callback, args,
567 | name=None,
568 | path=None,
569 | bus=None,
570 | ):
571 | """ Call signal_subscribe on bus
572 |
573 | Parameters
574 | ----------
575 | iface: str
576 | The DBus interface to use
577 |
578 | signal_name: str
579 | The DBus signal to subscribe on iface
580 |
581 | callback: callable
582 | The callback to use
583 |
584 | args: GLib.Variant or None (default None)
585 | The arguments to pass to called method
586 |
587 | name: str or None (default None)
588 | The name of the bus to use, self.bus_name if None
589 |
590 | path: str or None (default None)
591 | The path to use, self.path[0] if None
592 |
593 | bus: Gio.DBusConnection or None (default None)
594 | The bus to use, self.bus if None
595 |
596 | Returns
597 | -------
598 | int
599 | The subscription id
600 | """
601 | if name is None:
602 | name = self.bus_name
603 | if path is None:
604 | path = self.path[0]
605 | if bus is None:
606 | bus = self.bus
607 | return bus.signal_subscribe(name, # sender
608 | iface, # interface name
609 | signal_name,
610 | path, # object path
611 | None, # arg0
612 | Gio.DBusSignalFlags.NONE, # flags
613 | callback, # callback
614 | None, # user data
615 | )
616 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------