Move autostart to python

This commit is contained in:
Rico Tiongson 2019-03-03 19:24:50 +08:00
parent 4117c3a3f1
commit d8da338833
39 changed files with 81 additions and 28 deletions

1
MANIFEST.in Normal file
View File

@ -0,0 +1 @@
include comfortable_swipe/res/comfortable-swipe.desktop

View File

@ -1,20 +1,21 @@
import sys
from comfortable_swipe import service
from comfortable_swipe.cpp import service as cpp_service
def main():
if len(sys.argv) <= 1:
service.help()
else:
dict(
start=service.start,
stop=service.stop,
restart=service.restart,
start=cpp_service.start,
stop=cpp_service.stop,
restart=cpp_service.restart,
autostart=service.autostart,
buffer=service.buffer,
help=service.help,
config=service.config,
debug=service.debug,
status=service.status
buffer=cpp_service.buffer,
help=cpp_service.help,
config=cpp_service.config,
debug=cpp_service.debug,
status=cpp_service.status
)[sys.argv[1]]()
if __name__ == '__main__':

View File

View File

@ -0,0 +1,8 @@
[Desktop Entry]
Type=Application
Exec=comfortable-swipe start
Hidden=false
NoDisplay=false
X-GNOME-Autostart-enabled=true
Name=Comfortable Swipe
Comment=3 or 4 finger swipe gestures

View File

@ -0,0 +1,14 @@
from __future__ import print_function
import os
from comfortable_swipe.util import autostart_path, autostart_template
def autostart():
autostart = autostart_path()
if os.path.exists(autostart):
os.remove(autostart)
print('Autostart switched off')
else:
with open(autostart, 'w') as file:
file.write(autostart_template())
print('Autostart switched on')

26
comfortable_swipe/util.py Normal file
View File

@ -0,0 +1,26 @@
import os
from distutils.spawn import find_executable
__EXE__ = 'comfortable-swipe'
__DIR__ = os.path.dirname(__file__)
__RES__ = os.path.join(__DIR__, 'res')
def conf_filename():
return os.path.join(sys.prefix, 'local', 'share', __EXE__, __EXE__ + '.conf')
def autostart_path():
return os.path.join(
os.getenv('XDG_CONFIG_HOME', os.path.join(os.getenv('HOME'), '.config')),
'autostart',
__EXE__ + '.desktop'
)
def autostart_template():
autostart_template_filename = os.path.join(__RES__, __EXE__ + '.desktop')
with open(autostart_template_filename, 'r') as file:
contents = file.read()
return contents.replace('Exec=' + __EXE__, 'Exec=' + find_executable(__EXE__))

View File

@ -2,7 +2,7 @@
#define __COMFORTABLE_SWIPE__python_cpp__
#include "service/_python.cpp"
#include "util/_python.cpp"
// #include "util/_python.cpp"
#include "comfortable-swipe.cpp"
#endif /* __COMFORTABLE_SWIPE__python_cpp__ */

View File

@ -2,7 +2,7 @@
#define __COMFORTABLE_SWIPE__service_index_cpp__
#include "_index.hpp"
#include "autostart.cpp"
// #include "autostart.cpp"
#include "buffer.cpp"
#include "config.cpp"
#include "debug.cpp"

View File

@ -10,7 +10,7 @@ extern "C"
{
namespace service
{
void autostart();
// void autostart();
void buffer();
void config();
void debug();

View File

@ -20,7 +20,7 @@ namespace comfortable_swipe::service::python
__comfortable_swipe_void_method(start);
__comfortable_swipe_void_method(stop);
__comfortable_swipe_void_method(restart);
__comfortable_swipe_void_method(autostart);
// __comfortable_swipe_void_method(autostart);
__comfortable_swipe_void_method(buffer);
__comfortable_swipe_void_method(help);
__comfortable_swipe_void_method(config);
@ -35,7 +35,7 @@ namespace comfortable_swipe::service::python
{ "start", &start, METH_VARARGS , "starts 3/4-finger gesture service" },
{ "stop", &stop, METH_VARARGS , "stops 3/4-finger gesture service" },
{ "restart", &restart, METH_VARARGS , "stops then starts 3/4-finger gesture service" },
{ "autostart", &autostart, METH_VARARGS , "automatically run on startup (toggleable)" },
// { "autostart", &autostart, METH_VARARGS , "automatically run on startup (toggleable)" },
{ "buffer", &buffer, METH_VARARGS , "parses output of libinput debug-events" },
{ "help", &help, METH_VARARGS , "shows the help dialog" },
{ "config", &config, METH_VARARGS , "locates the config file " },

View File

@ -11,26 +11,29 @@ from setuptools.command.develop import develop
from setuptools.command.install import install
from wheel.bdist_wheel import bdist_wheel
NAME = 'comfortable-swipe'
PYTHON_NAME = NAME.replace('-', '_')
VERSION = '1.1.0-beta'
__BIN__ = os.path.dirname(sys.executable)
__SHARE__ = os.path.join(sys.prefix, 'local', 'share')
__CWD__ = os.getcwd()
__DIR__ = os.path.abspath(os.path.dirname(__file__))
__RES__ = os.path.join(__DIR__, PYTHON_NAME, 'res')
__URL__ = 'https://github.com/Hikari9/comfortable-swipe-ubuntu'
NAME = 'comfortable-swipe'
PYTHON_NAME = NAME.replace('-', '_')
VERSION = '1.1.0-beta'
try:
# make sure working directory is here
os.chdir(__DIR__)
# assign program variables
# assign config
CONFIG = os.path.join(__SHARE__, NAME, NAME + '.conf')
DEFAULT_CONFIG = os.path.join(__RES__, 'defaults.conf')
# prioritize the higher indices
conf_paths = [
os.path.join(__DIR__, 'defaults.conf'),
DEFAULT_CONFIG,
os.path.join(os.getenv('HOME'), '.config', 'comfortable-swipe', 'comfortable-swipe.conf'),
os.path.join('/usr/local/share', 'comfortable-swipe', 'comfortable-swipe.conf'),
CONFIG
@ -47,11 +50,11 @@ try:
README = README_file.read()
# read C++ libraries for comfortable swipe
extension_names = ['service', 'util']
extension_names = ['service']
extensions = [Extension(
name='{}.{}'.format(PYTHON_NAME, extension_name),
name='{}.cpp.{}'.format(PYTHON_NAME, extension_name),
define_macros=list(cpp_macros.items()),
sources=[os.path.join(__DIR__, 'lib', '_python.cpp')],
sources=[os.path.join('cpp', '_python.cpp')],
extra_compile_args=['-O2', '-Wno-unused-result'],
libraries=['xdo']
) for extension_name in extension_names]
@ -74,7 +77,7 @@ try:
# new installation or upgrading from old version, copy to new location
copyfile(conf_files[-1], CONFIG)
if conf_files[-1] == os.path.join(__DIR__, 'defaults.conf'):
if conf_files[-1] == DEFAULT_CONFIG:
# new installation - copy default configuration
print('Copying configuration file to', CONFIG)
@ -94,11 +97,10 @@ try:
def pre_uninstall(self):
# remove autostart config
from comfortable_swipe import util
autostart_filename = str(util.autostart_filename)
if os.path.exists(autostart_filename):
print('Removing autostart', autostart_filename)
os.remove(autostart_filename)
from comfortable_swipe.util import autostart_path
from comfortable_swipe.service import autostart
if os.path.exists(autostart_path()):
autostart()
def post_uninstall(self):
@ -145,8 +147,9 @@ try:
author='Rico Tiongson',
author_email='thericotiongson@gmail.com',
url=__URL__,
# zip_safe=False,
zip_safe=False,
packages=find_packages(),
include_package_data=True,
entry_points=dict(console_scripts=['{}=comfortable_swipe.__main__:main'.format(NAME)]),
ext_modules=extensions,
cmdclass=cmdclass