misc (D-Bus, installation): added a .service file for D-Bus auto-launch feature + installation from setup.py (path adaptation now use regex).
This commit is contained in:
parent
75c79aba58
commit
3d3d9733ef
3 changed files with 45 additions and 15 deletions
|
|
@ -10,3 +10,6 @@ compinit
|
||||||
### end of .zshrc completion ###
|
### end of .zshrc completion ###
|
||||||
|
|
||||||
Then, you should be able to complete a jp command line by pressing [TAB].
|
Then, you should be able to complete a jp command line by pressing [TAB].
|
||||||
|
|
||||||
|
* org.goffi.SAT.service:
|
||||||
|
This file is used by D-Bus to know how to launch the backend, you have to put in in D-Bus services dir (usually /usr/share/dbus-1/services)
|
||||||
|
|
|
||||||
3
misc/org.goffi.SAT.service
Normal file
3
misc/org.goffi.SAT.service
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
[D-BUS Service]
|
||||||
|
Name=org.goffi.SAT
|
||||||
|
Exec=sat
|
||||||
52
setup.py
52
setup.py
|
|
@ -28,6 +28,7 @@ import sys
|
||||||
import subprocess
|
import subprocess
|
||||||
from stat import ST_MODE
|
from stat import ST_MODE
|
||||||
import shutil
|
import shutil
|
||||||
|
import re
|
||||||
|
|
||||||
# seen here: http://stackoverflow.com/questions/7275295
|
# seen here: http://stackoverflow.com/questions/7275295
|
||||||
try:
|
try:
|
||||||
|
|
@ -60,6 +61,17 @@ AUTO_DEB_OPT = 'autodeb' # automaticaly install debs
|
||||||
NO_X_OPT = 'nox' # don't install X dependant packages
|
NO_X_OPT = 'nox' # don't install X dependant packages
|
||||||
CLEAN_OPT = 'clean' # remove previous installation directories
|
CLEAN_OPT = 'clean' # remove previous installation directories
|
||||||
PURGE_OPT = 'purge' # remove building and previous installation directories
|
PURGE_OPT = 'purge' # remove building and previous installation directories
|
||||||
|
DBUS_DIR = 'dbus-1/services'
|
||||||
|
DBUS_FILE = 'misc/org.goffi.SAT.service'
|
||||||
|
|
||||||
|
# Following map describe file to adapt with installation path:
|
||||||
|
# key is the self attribute to get (e.g.: sh_script_path will modify self.sh_script_path file)
|
||||||
|
# value is a dict where key is the regex of the part to change, and value is either the string
|
||||||
|
# to replace or a tuple with a template and values to replace (if value to replace is a string,
|
||||||
|
# the attribute from self with that name will be used).
|
||||||
|
FILE_ADJ = {'sh_script_path': {r'PYTHON *=.*': 'PYTHON="{}"'.format(sys.executable)},
|
||||||
|
'dbus_service_path': {r'Exec *=.*': ('Exec={}', 'sh_script_path')},
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class MercurialException(Exception):
|
class MercurialException(Exception):
|
||||||
|
|
@ -79,20 +91,30 @@ def module_installed(module_name):
|
||||||
|
|
||||||
class CustomInstall(install):
|
class CustomInstall(install):
|
||||||
|
|
||||||
def custom_auto_options(self):
|
def adapt_files(self):
|
||||||
"""Change options for twistd in the shell script
|
"""Adapt files to installed environments
|
||||||
Mainly change the paths"""
|
|
||||||
sh_buffer = ""
|
|
||||||
with open(self.sh_script_path, 'r') as sh_file:
|
|
||||||
for ori_line in sh_file:
|
|
||||||
if ori_line.startswith('PYTHON='):
|
|
||||||
dest_line = 'PYTHON="%s"\n' % sys.executable
|
|
||||||
else:
|
|
||||||
dest_line = ori_line
|
|
||||||
sh_buffer += dest_line
|
|
||||||
|
|
||||||
with open(self.sh_script_path, 'w') as sh_file:
|
Mainly change the paths
|
||||||
sh_file.write(sh_buffer)
|
"""
|
||||||
|
def adapter(ordered_replace, match_obj):
|
||||||
|
"""do file adjustment, getting self attribute when needed"""
|
||||||
|
idx = match_obj.lastindex - 1
|
||||||
|
repl_data = ordered_replace[idx][1]
|
||||||
|
if isinstance(repl_data, tuple):
|
||||||
|
template = repl_data[0]
|
||||||
|
args = [getattr(self, arg) if isinstance(arg, basestring) else arg for arg in repl_data[1:]]
|
||||||
|
return template.format(*args)
|
||||||
|
return repl_data
|
||||||
|
|
||||||
|
for file_attr, replace_data in FILE_ADJ.iteritems():
|
||||||
|
file_path = getattr(self, file_attr)
|
||||||
|
ordered_replace = [(regex, repl) for regex, repl in replace_data.iteritems()]
|
||||||
|
regex = '|'.join(('({})'.format(regex) for regex, dummy in ordered_replace))
|
||||||
|
with open(file_path, 'r') as f:
|
||||||
|
buff = f.read()
|
||||||
|
buff = re.sub(regex, lambda match_obj: adapter(ordered_replace, match_obj), buff)
|
||||||
|
with open(file_path, 'w') as f:
|
||||||
|
f.write(buff)
|
||||||
|
|
||||||
def custom_create_links(self):
|
def custom_create_links(self):
|
||||||
"""Create symbolic links to executables"""
|
"""Create symbolic links to executables"""
|
||||||
|
|
@ -109,6 +131,7 @@ class CustomInstall(install):
|
||||||
def run(self):
|
def run(self):
|
||||||
self.sh_script_path = os.path.join(self.install_lib, NAME, 'sat.sh')
|
self.sh_script_path = os.path.join(self.install_lib, NAME, 'sat.sh')
|
||||||
self.sh_script_links = [(self.sh_script_path, os.path.join(self.install_scripts, LAUNCH_DAEMON_COMMAND))]
|
self.sh_script_links = [(self.sh_script_path, os.path.join(self.install_scripts, LAUNCH_DAEMON_COMMAND))]
|
||||||
|
self.dbus_service_path = os.path.join(self.install_data, 'share', DBUS_DIR, os.path.basename(DBUS_FILE))
|
||||||
sys.stdout.write('running pre installation stuff\n')
|
sys.stdout.write('running pre installation stuff\n')
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
if PURGE_OPT in install_opt:
|
if PURGE_OPT in install_opt:
|
||||||
|
|
@ -118,7 +141,7 @@ class CustomInstall(install):
|
||||||
install.run(self)
|
install.run(self)
|
||||||
sys.stdout.write('running post installation stuff\n')
|
sys.stdout.write('running post installation stuff\n')
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
self.custom_auto_options()
|
self.adapt_files()
|
||||||
self.custom_create_links()
|
self.custom_create_links()
|
||||||
|
|
||||||
def confirm(self, message):
|
def confirm(self, message):
|
||||||
|
|
@ -261,6 +284,7 @@ setup(name=NAME,
|
||||||
'sat_frontends': ['wix/COPYING']},
|
'sat_frontends': ['wix/COPYING']},
|
||||||
data_files=[(os.path.join(sys.prefix, 'share/locale/fr/LC_MESSAGES'), ['i18n/fr/LC_MESSAGES/sat.mo']),
|
data_files=[(os.path.join(sys.prefix, 'share/locale/fr/LC_MESSAGES'), ['i18n/fr/LC_MESSAGES/sat.mo']),
|
||||||
('share/doc/%s' % NAME, ['CHANGELOG', 'COPYING', 'INSTALL', 'README', 'README4TRANSLATORS']),
|
('share/doc/%s' % NAME, ['CHANGELOG', 'COPYING', 'INSTALL', 'README', 'README4TRANSLATORS']),
|
||||||
|
(os.path.join('share', DBUS_DIR), (DBUS_FILE,)),
|
||||||
],
|
],
|
||||||
scripts=['frontends/src/jp/jp', 'frontends/src/primitivus/primitivus', 'frontends/src/wix/wix'],
|
scripts=['frontends/src/jp/jp', 'frontends/src/primitivus/primitivus', 'frontends/src/wix/wix'],
|
||||||
zip_safe=False,
|
zip_safe=False,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue