Move autostart to python
This commit is contained in:
parent
4117c3a3f1
commit
d8da338833
1
MANIFEST.in
Normal file
1
MANIFEST.in
Normal file
@ -0,0 +1 @@
|
|||||||
|
include comfortable_swipe/res/comfortable-swipe.desktop
|
||||||
@ -1,20 +1,21 @@
|
|||||||
import sys
|
import sys
|
||||||
from comfortable_swipe import service
|
from comfortable_swipe import service
|
||||||
|
from comfortable_swipe.cpp import service as cpp_service
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
if len(sys.argv) <= 1:
|
if len(sys.argv) <= 1:
|
||||||
service.help()
|
service.help()
|
||||||
else:
|
else:
|
||||||
dict(
|
dict(
|
||||||
start=service.start,
|
start=cpp_service.start,
|
||||||
stop=service.stop,
|
stop=cpp_service.stop,
|
||||||
restart=service.restart,
|
restart=cpp_service.restart,
|
||||||
autostart=service.autostart,
|
autostart=service.autostart,
|
||||||
buffer=service.buffer,
|
buffer=cpp_service.buffer,
|
||||||
help=service.help,
|
help=cpp_service.help,
|
||||||
config=service.config,
|
config=cpp_service.config,
|
||||||
debug=service.debug,
|
debug=cpp_service.debug,
|
||||||
status=service.status
|
status=cpp_service.status
|
||||||
)[sys.argv[1]]()
|
)[sys.argv[1]]()
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
0
comfortable_swipe/cpp/.gitkeep
Normal file
0
comfortable_swipe/cpp/.gitkeep
Normal file
8
comfortable_swipe/res/comfortable-swipe.desktop
Normal file
8
comfortable_swipe/res/comfortable-swipe.desktop
Normal 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
|
||||||
14
comfortable_swipe/service.py
Normal file
14
comfortable_swipe/service.py
Normal 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
26
comfortable_swipe/util.py
Normal 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__))
|
||||||
@ -2,7 +2,7 @@
|
|||||||
#define __COMFORTABLE_SWIPE__python_cpp__
|
#define __COMFORTABLE_SWIPE__python_cpp__
|
||||||
|
|
||||||
#include "service/_python.cpp"
|
#include "service/_python.cpp"
|
||||||
#include "util/_python.cpp"
|
// #include "util/_python.cpp"
|
||||||
#include "comfortable-swipe.cpp"
|
#include "comfortable-swipe.cpp"
|
||||||
|
|
||||||
#endif /* __COMFORTABLE_SWIPE__python_cpp__ */
|
#endif /* __COMFORTABLE_SWIPE__python_cpp__ */
|
||||||
@ -2,7 +2,7 @@
|
|||||||
#define __COMFORTABLE_SWIPE__service_index_cpp__
|
#define __COMFORTABLE_SWIPE__service_index_cpp__
|
||||||
|
|
||||||
#include "_index.hpp"
|
#include "_index.hpp"
|
||||||
#include "autostart.cpp"
|
// #include "autostart.cpp"
|
||||||
#include "buffer.cpp"
|
#include "buffer.cpp"
|
||||||
#include "config.cpp"
|
#include "config.cpp"
|
||||||
#include "debug.cpp"
|
#include "debug.cpp"
|
||||||
@ -10,7 +10,7 @@ extern "C"
|
|||||||
{
|
{
|
||||||
namespace service
|
namespace service
|
||||||
{
|
{
|
||||||
void autostart();
|
// void autostart();
|
||||||
void buffer();
|
void buffer();
|
||||||
void config();
|
void config();
|
||||||
void debug();
|
void debug();
|
||||||
@ -20,7 +20,7 @@ namespace comfortable_swipe::service::python
|
|||||||
__comfortable_swipe_void_method(start);
|
__comfortable_swipe_void_method(start);
|
||||||
__comfortable_swipe_void_method(stop);
|
__comfortable_swipe_void_method(stop);
|
||||||
__comfortable_swipe_void_method(restart);
|
__comfortable_swipe_void_method(restart);
|
||||||
__comfortable_swipe_void_method(autostart);
|
// __comfortable_swipe_void_method(autostart);
|
||||||
__comfortable_swipe_void_method(buffer);
|
__comfortable_swipe_void_method(buffer);
|
||||||
__comfortable_swipe_void_method(help);
|
__comfortable_swipe_void_method(help);
|
||||||
__comfortable_swipe_void_method(config);
|
__comfortable_swipe_void_method(config);
|
||||||
@ -35,7 +35,7 @@ namespace comfortable_swipe::service::python
|
|||||||
{ "start", &start, METH_VARARGS , "starts 3/4-finger gesture service" },
|
{ "start", &start, METH_VARARGS , "starts 3/4-finger gesture service" },
|
||||||
{ "stop", &stop, METH_VARARGS , "stops 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" },
|
{ "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" },
|
{ "buffer", &buffer, METH_VARARGS , "parses output of libinput debug-events" },
|
||||||
{ "help", &help, METH_VARARGS , "shows the help dialog" },
|
{ "help", &help, METH_VARARGS , "shows the help dialog" },
|
||||||
{ "config", &config, METH_VARARGS , "locates the config file " },
|
{ "config", &config, METH_VARARGS , "locates the config file " },
|
||||||
33
setup.py
33
setup.py
@ -11,26 +11,29 @@ from setuptools.command.develop import develop
|
|||||||
from setuptools.command.install import install
|
from setuptools.command.install import install
|
||||||
from wheel.bdist_wheel import bdist_wheel
|
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)
|
__BIN__ = os.path.dirname(sys.executable)
|
||||||
__SHARE__ = os.path.join(sys.prefix, 'local', 'share')
|
__SHARE__ = os.path.join(sys.prefix, 'local', 'share')
|
||||||
__CWD__ = os.getcwd()
|
__CWD__ = os.getcwd()
|
||||||
__DIR__ = os.path.abspath(os.path.dirname(__file__))
|
__DIR__ = os.path.abspath(os.path.dirname(__file__))
|
||||||
|
__RES__ = os.path.join(__DIR__, PYTHON_NAME, 'res')
|
||||||
__URL__ = 'https://github.com/Hikari9/comfortable-swipe-ubuntu'
|
__URL__ = 'https://github.com/Hikari9/comfortable-swipe-ubuntu'
|
||||||
|
|
||||||
NAME = 'comfortable-swipe'
|
|
||||||
PYTHON_NAME = NAME.replace('-', '_')
|
|
||||||
VERSION = '1.1.0-beta'
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# make sure working directory is here
|
# make sure working directory is here
|
||||||
os.chdir(__DIR__)
|
os.chdir(__DIR__)
|
||||||
|
|
||||||
# assign program variables
|
# assign config
|
||||||
CONFIG = os.path.join(__SHARE__, NAME, NAME + '.conf')
|
CONFIG = os.path.join(__SHARE__, NAME, NAME + '.conf')
|
||||||
|
DEFAULT_CONFIG = os.path.join(__RES__, 'defaults.conf')
|
||||||
|
|
||||||
# prioritize the higher indices
|
# prioritize the higher indices
|
||||||
conf_paths = [
|
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(os.getenv('HOME'), '.config', 'comfortable-swipe', 'comfortable-swipe.conf'),
|
||||||
os.path.join('/usr/local/share', 'comfortable-swipe', 'comfortable-swipe.conf'),
|
os.path.join('/usr/local/share', 'comfortable-swipe', 'comfortable-swipe.conf'),
|
||||||
CONFIG
|
CONFIG
|
||||||
@ -47,11 +50,11 @@ try:
|
|||||||
README = README_file.read()
|
README = README_file.read()
|
||||||
|
|
||||||
# read C++ libraries for comfortable swipe
|
# read C++ libraries for comfortable swipe
|
||||||
extension_names = ['service', 'util']
|
extension_names = ['service']
|
||||||
extensions = [Extension(
|
extensions = [Extension(
|
||||||
name='{}.{}'.format(PYTHON_NAME, extension_name),
|
name='{}.cpp.{}'.format(PYTHON_NAME, extension_name),
|
||||||
define_macros=list(cpp_macros.items()),
|
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'],
|
extra_compile_args=['-O2', '-Wno-unused-result'],
|
||||||
libraries=['xdo']
|
libraries=['xdo']
|
||||||
) for extension_name in extension_names]
|
) for extension_name in extension_names]
|
||||||
@ -74,7 +77,7 @@ try:
|
|||||||
# new installation or upgrading from old version, copy to new location
|
# new installation or upgrading from old version, copy to new location
|
||||||
copyfile(conf_files[-1], CONFIG)
|
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
|
# new installation - copy default configuration
|
||||||
print('Copying configuration file to', CONFIG)
|
print('Copying configuration file to', CONFIG)
|
||||||
|
|
||||||
@ -94,11 +97,10 @@ try:
|
|||||||
|
|
||||||
def pre_uninstall(self):
|
def pre_uninstall(self):
|
||||||
# remove autostart config
|
# remove autostart config
|
||||||
from comfortable_swipe import util
|
from comfortable_swipe.util import autostart_path
|
||||||
autostart_filename = str(util.autostart_filename)
|
from comfortable_swipe.service import autostart
|
||||||
if os.path.exists(autostart_filename):
|
if os.path.exists(autostart_path()):
|
||||||
print('Removing autostart', autostart_filename)
|
autostart()
|
||||||
os.remove(autostart_filename)
|
|
||||||
|
|
||||||
|
|
||||||
def post_uninstall(self):
|
def post_uninstall(self):
|
||||||
@ -145,8 +147,9 @@ try:
|
|||||||
author='Rico Tiongson',
|
author='Rico Tiongson',
|
||||||
author_email='thericotiongson@gmail.com',
|
author_email='thericotiongson@gmail.com',
|
||||||
url=__URL__,
|
url=__URL__,
|
||||||
# zip_safe=False,
|
zip_safe=False,
|
||||||
packages=find_packages(),
|
packages=find_packages(),
|
||||||
|
include_package_data=True,
|
||||||
entry_points=dict(console_scripts=['{}=comfortable_swipe.__main__:main'.format(NAME)]),
|
entry_points=dict(console_scripts=['{}=comfortable_swipe.__main__:main'.format(NAME)]),
|
||||||
ext_modules=extensions,
|
ext_modules=extensions,
|
||||||
cmdclass=cmdclass
|
cmdclass=cmdclass
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user