Commit Graph

118 Commits (master)

Author SHA1 Message Date
Benjamin Tissoires 3eca8da251 kete: add live debugging mode
Just start/stop live mode, the debug happens in the tuhi process.

That's enough until we figure out the DBus API if we need one
2018-02-14 06:23:25 +10:00
Benjamin Tissoires 41a3c85b59 kete: export the connected state of the bluez device to the tuhiketedevice
We need this in the live mode as the connection will be longer than
the usual retrieval of the data.
2018-02-14 06:23:25 +10:00
Benjamin Tissoires e4e0a3b8aa kete: rename the script from tuhi-kete.py to kete.py
Python doesn't really like minus signs in file names, especially
when you start importing the modules. Rename kete from tuhi-kete.py
to kete.py so it makes it easier to have other scripts in the tools
folder to borrow code from kete.
2018-02-14 06:23:25 +10:00
Benjamin Tissoires 590de68269 kete: make Searcher and Listener symmetrical regarding logs
The 'searching' notification was only emitted when it goes to stop, which
means we do not get notifications when it starts.
This makes SearchStopped signal redundant for the generic case, but allows
to get notifications if the search failed to start.

Rest is just making sure we have the same handling of events in Listener
and Searcher.
2018-02-13 14:51:40 +01:00
Benjamin Tissoires d8808e144f kete: better handling of clean up of connection/disconnection of signals
If stop() is called more than once, we might try to disconnect the
signals more than once, which raises some errors.
Better having one central place that handles the disconnect properly.
2018-02-13 14:51:40 +01:00
Peter Hutterer 58220efe31 kete: don't assume all devices are unregistered when searching
Instead, wait for the signal from tuhi and then go for it.

Fixes #80
2018-02-13 14:51:40 +01:00
Peter Hutterer 94bc52efb6 kete: if listening/searching is stopped by the daemon, clean up after us 2018-02-13 14:49:39 +01:00
Benjamin Tissoires abfb0db6a8 kete: catch the ServiceUnknown exception in TuhiKeteDevice
This allows to have more symmetrical handling of the Searcher and
the Listener
2018-02-13 14:49:17 +01:00
Benjamin Tissoires c86c318d6b kete: rename the history file to be histfile
for googleability, as being said
2018-02-07 09:15:59 +01:00
Benjamin Tissoires e63785b5b2 kete: persistent history
We write the history immediately after receiving a new command,
just in case something bad happens.

Fixes #54
2018-02-07 09:38:31 +10:00
Benjamin Tissoires 9829fa6822 flatpak: ship tuhi-kete in the sandbox
To be able to run tuhi-kete, we need a tuhi server running. Provide a
script that spawns one if none is running.

Running simple 'python3 setup.py --install' started to go havoc by
complaining that /app/lib/python3.6/site-packages/easy-install.pth
was read-only.

The solution mentioned in https://github.com/flatpak/flatpak-builder/issues/5
didn't do the trick.

So using https://stackoverflow.com/questions/6301003/stopping-setup-py-from-installing-as-egg/27175492#27175492
as a trick to install the dependencies without the egg part

To start tuhi-kete:
$> flatpak run --command=tuhi-kete org.freedesktop.tuhi

Note that currently the fetched files are not available outside of the
sandbox

Related to #62
2018-02-06 09:03:47 +01:00
Peter Hutterer 5e82d1b378 Rename "pair" to "register"
"pair" is alrady taken by Bluetooth and since we have a bluetooth device here,
it can cause confusion. Use "register" instead, with an explanation in the
README for the more paranoid of us.

Fixes #67
2018-02-02 09:23:08 +01:00
Benjamin Tissoires fc219e4c57 janitor: silence deprecated warnings
While running the app in flatpak, there are a few deprecation warnings
coming in:
PyGIDeprecationWarning: GObject.SIGNAL_RUN_FIRST is deprecated;
	use GObject.SignalFlags.RUN_FIRST instead
PyGIDeprecationWarning: GObject.property is deprecated;
	use GObject.Property instead
PyGIDeprecationWarning: GObject.MainLoop is deprecated;
	use GLib.MainLoop instead
2018-02-02 10:46:47 +10:00
Peter Hutterer b305d6e287 kete: ignore dbus errors during StopSearch
we may call StopSearch after the daemon vanished and while we're stopping all
the workers. Ignore the ServiceUnknown error here.
2018-02-02 09:56:24 +10:00
Peter Hutterer ddef5ea38a kete: allow 'help' even when not connected 2018-02-02 08:55:48 +10:00
Peter Hutterer 02e8cf53ce kete: while disconnected, print a message to that effect
$> ./tools/tuhi-kete.py
Tuhi shell control
WARNING: Tuhi daemon not running
tuhi> list
Not connected to the Tuhi daemon

Better than just a noop
2018-02-02 08:55:13 +10:00
Peter Hutterer 1f93db6ca0 kete: improve some messaging
In the normal mode (without -v) we'd see the errors, but not the messages when
we reconnect. Elevate the "connected to" message to info so it shows up.

And slight rewording, which may or may not be better.
2018-02-02 08:27:23 +10:00
Benjamin Tissoires 3e444d6a0c kete: make the shell survive the disappearing of the daemon
We need to move the mainloop in the Shell as we need to watch on the
name there.

Fixes #55
2018-02-02 08:13:30 +10:00
Benjamin Tissoires 277523c7d5 kete: stop listening when pairing a device
Or the internal state of kete is that the device is listening while
tuhi says it is not.
2018-02-02 08:13:30 +10:00
Benjamin Tissoires db2f37c561 kete: do_fetch: do not remember the worker
There is no stop() method attached to Fetcher, so we don't really need
to remember we called it once to call a NOOP
2018-02-02 08:13:30 +10:00
Benjamin Tissoires 5368e49f5d kete: rename 'list' command into 'devices'
'list' and 'listen' are just too close to each other, meaning the
completion stops at 'list' while the lazy developer/tester want to
do a 'listen'.

Change the name of the less used command so we have separate spaces
for completion
2018-02-02 08:13:30 +10:00
Benjamin Tissoires 0c829754cd tools: add the parse_log script we used to dump the raw btsnoop logs
Better keep this in a public place where it won't vanish from our disks.
Note that this is a python 2 script (because btsnoop), and it should not
be part of the installation, ever.
2018-02-02 08:00:41 +10:00
Peter Hutterer 31e1f2ad3b Export the Bluez device's object path
Rather than proxying all metadata (name, address, ...) add a reference to the
bluez device instead.

Fixes #60
2018-02-01 10:13:39 +10:00
Benjamin Tissoires 501c891a12 kete: bubble up the dbus vanished errors
Not much is done for now, but the shell is notified, which is a big step
2018-01-31 17:03:25 +01:00
Benjamin Tissoires 9b18339890 kete: remove pointless indirection class Printer
In this case, it's easier to just iterate in the do_list() call than
having a Worker element
2018-01-31 17:03:24 +01:00
Benjamin Tissoires 0bc516b13c kete: do_search: make sure we have only one searcher element
This prevents duplicate signals to be sent when the search stops
2018-01-31 17:03:24 +01:00
Benjamin Tissoires a164ea291e kete: clean up the Searcher class
now that there is no more standalone commands, the Searcher can be striped
off of its interactive bits.
2018-01-31 17:03:13 +01:00
Benjamin Tissoires c2ceba7483 kete: clean up a little bit the Worker class
The Worker subclasses now only need to implement run() and stop().
2018-01-31 16:06:09 +01:00
Benjamin Tissoires e4b0f9768d kete: drop TuhiKeteShellWorker and directly use TuhiKeteShell 2018-01-31 16:06:09 +01:00
Benjamin Tissoires 5757bcfab1 kete: move the mainloop thread into the manager
The manager handles the mainloop, so it's easier if it handles the
attached thread too.
2018-01-31 16:06:09 +01:00
Peter Hutterer 8affec2002 kete: drop the _run/_stop indirection, not necessary 2018-01-31 15:47:29 +01:00
Peter Hutterer dba5ddc60c kete: drop the non-interactive bits from tuhi-kete
Fixes #51
2018-01-31 15:47:29 +01:00
Benjamin Tissoires 5889052fb1 kete: fix log errors when the device is not paired anymore
Tuhi raise -EACCES if the UUID stored is not valid anymore.
Instead of shouting some obscure error, we should notify the
user that a pairing need to happen or the device will not talk
to us.

Also fix a small sign mistake in calling os.strerror() for general
errors

Fixes #6
2018-01-31 10:21:57 +10:00
Peter Hutterer e647e20426 Export the battery level/charge state 2018-01-30 18:53:55 +10:00
Benjamin Tissoires a2df5b6ac1 kete/prompt: show meaning of the timestamps
workaround for cumberness of having to type timestamps.

Instead of having some fancy formatted timestamp, help the user
by displaying the translated value
2018-01-30 10:57:17 +10:00
Benjamin Tissoires eb0175bb19 kete: remove one debugging statement used for development
this just messes up the prompt and was meant to be removed before being
pushed/merge into master
2018-01-29 13:59:39 +01:00
Benjamin Tissoires 9f118bbe15 janitor: convert double quotes into single quotes
Let's the developers of tuhi to consume more energy in their monitor
to light up more pixel when displaying single quotes whereas double
quotes.

It also makes the whole bit more uniform.

Fixes #32
2018-01-29 21:18:06 +10:00
Benjamin Tissoires 04f25a0a38 drop .format(), switch to f{} everywhere
and change some double quotes into single quotes when encountering them.

It's a new project, so force use of Python 3.6 right now

Fixes #29
2018-01-29 21:18:06 +10:00
Benjamin Tissoires 2aa8b0dc95 kete/prompt: make completion case insensitive
because there is a high chance users will not use uppercase for
the device addresses
2018-01-29 21:02:23 +10:00
Benjamin Tissoires e7a38c3bdc kete/prompt: add command completion
allows to be much more efficient with the prompt.

I wonder if we can not reuse the argparse facilities somehow
2018-01-29 21:02:23 +10:00
Benjamin Tissoires 08bdaffd89 kete: remove custom namespace class Args
We are using argparse in the various prompt function that already
provide a NameSpace class. We can just reuse it instead of rebuilding
everything.

Given that we enforce/parse the type of the arguments, there is no
need to do more processing.
2018-01-29 21:02:23 +10:00
Benjamin Tissoires 1d3bf40a8c kete/prompt: do_fetch: allow for devices in pairable mode to be paired
this is something quite useful actually
2018-01-29 11:09:25 +01:00
Peter Hutterer 6ad3851afd wacom: set the device time to UTC time on pairing
And let us handle the local time zone conversions in the client, because
having timestamps in localtime in the daemon is confusing and error-prone (how
is the client supposed to know what localtime was?)
2018-01-29 09:44:50 +01:00
Peter Hutterer dfdface640 Colorise the output log
Modified version from
https://stackoverflow.com/questions/384076/how-can-i-color-python-logging-output

Modifications (from that post) include:
* make flake8 happy by removing whitespaces and whatnot
* move everything into a class
* add the LIGHT_* colors
* remove the magic 30+ offset, assign the real color codes instead
* remove the $BG feature, we don't need background colors
2018-01-29 09:14:53 +01:00
Peter Hutterer 7d86305b52 kete: ignore errors during exit
Errors that occur during shutdown because one of the things hasn't been set up
in the expected way do not matter. For the shell we still require a manual
user exit though.

  File "./tools/tuhi-kete.py", line 344, in stop
    self.manager.disconnect(self.s1)
AttributeError: 'Searcher' object has no attribute 's1'

  File "./tools/tuhi-kete.py", line 267, in _on_name_vanished
    self.mainloop.quit()
AttributeError: 'NoneType' object has no attribute 'quit'
2018-01-29 10:12:04 +10:00
Peter Hutterer 8b50a7c2da kete/prompt: improve the help messages
Now that we have a prompt, make the various help <cmd> messages detailed
enough that someone who doesn't know tuhi well can still figure it out.
2018-01-29 10:12:04 +10:00
Benjamin Tissoires 03672a68f6 kete/prompt: add info command
convenient function to list the currently available drawings
2018-01-29 10:12:04 +10:00
Benjamin Tissoires dd84145b3b kete/prompt: implement pairing
we have to tweak a little the Searcher class for it to not prompt the
request whether to pair to the device or not.
2018-01-29 10:00:22 +10:00
Benjamin Tissoires c1a11280c0 kete/prompt: implement fetch 2018-01-29 10:00:22 +10:00
Benjamin Tissoires 60252f8649 kete/prompt: use argparse instead of home made parser 2018-01-29 09:08:22 +10:00
Benjamin Tissoires b33afcce0c kete/prompt: filter out EOF from the list of commands in the help
It doesn't make any sense to show this.
2018-01-29 09:08:22 +10:00
Benjamin Tissoires 72d19ffdad kete/prompt: re-write the last line
If a log message comes in the background, it will clear the current
command.
Rewrite the current line buffer from readline so we get more user
friendly.
2018-01-29 09:08:22 +10:00
Benjamin Tissoires a833ff2b4c kete/prompt: interleave the logs in a better way with the prompt
We overwrite the current formatter to display or not
the prompt depending if we are in the prompt or not.

To prevent races between the background events and our
current configuration, we acquire/release the lock on
the current handler.
2018-01-29 09:08:22 +10:00
Benjamin Tissoires 8bd79d6b79 kete: add a prompt for interactive commands
Only list and listen commands are currently implemented.

The Ctrl-C handling has been a little bit tricky. The default GLib
mainloop tends to add its own SIGINT handler, which prevents us to
gracefully handle the KeyboardInterrupt exception during cmdloop().

So we need to create the mainloop in TuhiKeteShellWorker directly,
but bypassing the GLib.Mainloop() python facility.
2018-01-29 09:08:22 +10:00
Benjamin Tissoires e1e5a9357b kete: fix disconnect signals on Searcher
We should disconnect the signals on stop() no matter what state we are
2018-01-29 09:08:22 +10:00
Benjamin Tissoires 403eb51ea7 kete: have a common worker implementation
For the various commands, it is easier if we have a common interface
than just a simple function call.

Each current command runs something before the mainloop is created, and
then something after the mainloop is terminated. Having such a worker
allows us to have only one place where we start the mainloop, meaning
that the interactive prompt will not try to start it more than once,
and most above, will not kill it in the middle of a command while other
commands are still running.
2018-01-29 09:08:22 +10:00
Benjamin Tissoires 8e1bba496f kete: use logger instead of plain prints for device notifications 2018-01-29 09:08:22 +10:00
Benjamin Tissoires 5a5a2bc2b8 kete: validate the device address before processing it 2018-01-29 09:08:22 +10:00
Peter Hutterer 4efc415aa1 kete: disconnect from the device/manager signals on exit
Otherwise we resubscribe if we repeatedly call listen in interactive mode
2018-01-25 16:02:34 +10:00
Peter Hutterer 6ad127da3a kete: handle Listening property changes correctly
Previously the assumption was that any change in that property is only from
True to False
2018-01-25 16:02:34 +10:00
Benjamin Tissoires d4c5f2c081 kete: remove unused local variables 2018-01-25 14:58:28 +10:00
Peter Hutterer a9b6ea68e5 kete: on fetch, write the file as svg into $PWD
Again, very rudimentary but we're planning on making kete a bit better anyway.

Also note that this doesn't make use of the tuhi.drawing module on purpose,
parsing the format twice avoids some bugs and also keeps tuhi-kete separate
from the tuhi daemon.

Part of #7
2018-01-25 14:56:11 +10:00
Peter Hutterer 7a31a994fb dbus: return the drawings as array of timestamps
As we're planning to cache the data locally, the timestamps are a
unique-enough way that makes it possible to access a specific drawing.
And this way we can also delete some drawings without all other indices
shifting around.

Fixes #16
2018-01-25 14:55:10 +10:00
Peter Hutterer 3d516530c6 wacom: throw the exception (if any) to the "done" handler
Attach an errno to all exceptions, so we can bubble that up to the client
and display a message.

Fixes #24
2018-01-25 14:55:10 +10:00
Peter Hutterer a8ea4eb01b kete: improve an error message
This is a debugging tool, but still...
2018-01-25 09:18:59 +10:00
Peter Hutterer b3fad1be1b kete: ignore errors during StopListening
If the daemon goes away while we're listening, this is not a real problem.
2018-01-25 09:18:59 +10:00
Peter Hutterer 2ee934a81d kete: don't let a second client start searching 2018-01-24 19:25:00 +10:00
Benjamin Tissoires 6fa14b65f2 kete: Move the file in a tools folder
This is an unbelievable commit. This just moves one file in a new dir,
and this fixes bug #19.
2018-01-23 19:42:23 +10:00