Add the tuhi.in startup script

As a <builddir>/tuhi and <builddir>/tuhi.devel version. The latter runs
in-tree, the former is the one to be installed.

This is this type of script for a number of reasons. The quickest integration would
be to just use multiprocessing and call into the python module instead of
running other generated scripts. But that doesn't work, GLib doesn't like that
much (the GTK UI crashes). See
https://jameswestby.net/weblog/tech/14-caution-python-multiprocessing-and-glib-dont-mix.html

Another option would be to have a single thread because with GObjects we don't
need to care, right? Except that we do because the DBus bindings use sync
calls and that hangs when we have the server in the same process in a single
thread. Fixing the bindings is a bit more involved.

So meanwhile, let's just go for a script that executes the right targets as
separate processes and let the kernel take care of 'threading', that's what
it's there for after all.
pull/145/head
Peter Hutterer 2019-07-18 11:48:05 +10:00
parent ea162610fd
commit d2bfbc49b4
3 changed files with 74 additions and 3 deletions

View File

@ -19,6 +19,8 @@ Devices tested and known to be supported:
Building Tuhi
-------------
To build and run Tuhi from the repository directly:
```
$> git clone http://github.com/tuhiproject/tuhi
$> cd tuhi
@ -32,11 +34,18 @@ Tuhi requires Python v3.6 or above.
Install Tuhi
---------------
To install and run Tuhi:
```
$> git clone http://github.com/tuhiproject/tuhi
$> cd tuhi
$> meson builddir
$> ninja -C builddir install
```
Run Tuhi with:
```
$> tuhi
```

View File

@ -24,6 +24,8 @@ podir = join_paths(meson.source_root(), 'po')
desktopdir = join_paths(datadir, 'applications')
icondir = join_paths(datadir, 'icons', 'hicolor', 'scalable', 'apps')
metainfodir = join_paths(datadir, 'metainfo')
libexecdir = join_paths(get_option('prefix'), get_option('libexecdir'), 'tuhi')
i18n = import('i18n')
@ -41,6 +43,28 @@ install_subdir('tuhi',
install_dir: python_dir,
exclude_directories: '__pycache__')
# We have three startup scripts:
# - tuhi: starts server and GUI
# - tuhi-gui: starts the GUI only
# - tuhi-server: starts the server only
#
# tuhi-server can run as-is, we don't need meson for it. But for the other
# two we build a {name}.devel version that uses the in-tree files.
# For that we need to replace a few paths, in the installed versions we just
# use the normal dirs.
#
config_tuhi = configuration_data()
config_tuhi.set_quoted('libexecdir', libexecdir)
config_tuhi.set('devel', '')
config_tuhi_devel = configuration_data()
config_tuhi_devel.set_quoted('libexecdir', '')
config_tuhi_devel.set('devel', '''
tuhi_gui = '@1@/tuhi-gui.devel'
tuhi_server = '@0@/tuhi-server.py'
print('Running from source tree, using local files')
'''.format(meson.source_root(), meson.build_root()))
config_tuhigui = configuration_data()
config_tuhigui.set('pkgdatadir', pkgdatadir)
config_tuhigui.set('localedir', localedir)
@ -52,12 +76,21 @@ config_tuhigui_devel.set('localedir', join_paths(meson.build_root(), 'po'))
config_tuhigui_devel.set('devel', '''
sys.path.insert(1, '@0@')
print('Running from source tree, using local files')
'''.format(meson.source_root()))
'''.format(meson.source_root(), meson.build_root()))
configure_file(input: 'tuhi.in',
output: 'tuhi',
configuration: config_tuhi,
install_dir: bindir)
configure_file(input: 'tuhi.in',
output: 'tuhi.devel',
configuration: config_tuhi_devel)
configure_file(input: 'tuhi-gui.in',
output: 'tuhi-gui',
configuration: config_tuhigui,
install_dir: bindir)
install_dir: libexecdir)
configure_file(input: 'tuhi-gui.in',
output: 'tuhi-gui.devel',
@ -66,7 +99,7 @@ configure_file(input: 'tuhi-gui.in',
configure_file(input: 'tuhi-server.py',
output: 'tuhi-server',
copy: true,
install_dir: bindir)
install_dir: libexecdir)
meson.add_install_script('meson_install.sh')

29
tuhi.in Executable file
View File

@ -0,0 +1,29 @@
#!/usr/bin/env python3
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
import os
import subprocess
tuhi_server = os.path.join(@libexecdir@, 'tuhi-server')
tuhi_gui = os.path.join(@libexecdir@, 'tuhi-gui')
@devel@
if __name__ == '__main__':
tuhi = subprocess.Popen(tuhi_server)
try:
subprocess.run(tuhi_gui)
except KeyboardInterrupt:
pass
tuhi.terminate()