#!/usr/bin/env python # # Author: Sascha Silbe # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 3 # as published by the Free Software Foundation. # # 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. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . """ Installer for gdatastore """ from distutils import log from distutils.command.install import install as _install from distutils.core import Command, setup from distutils.util import convert_path import glob import os import subprocess import sys class install_dbus(Command): # pylint: disable=C0103,R0904 """Install D-Bus service files.""" description = 'create D-Bus service files from templates' user_options = [ ('install-dir=', 'd', "base directory for installing data files " "(default: installation base dir)"), ('root=', None, "install everything relative to this alternate root directory"), ('force', 'f', "force installation (overwrite existing files)"), ] boolean_options = ['force'] def initialize_options(self): # pylint: disable=W0201 self.install_dir = None self.outfiles = [] self.root = None self.force = 0 def finalize_options(self): self.set_undefined_options('install', ('install_data', 'install_dir'), ('root', 'root'), ('force', 'force'), ) def run(self): self.mkpath(self.install_dir) service_file_names = [] dbus_dir = convert_path(os.path.join(self.install_dir, 'share/dbus-1/services')) self.mkpath(dbus_dir) for template_file_name in glob.glob('*.service.in'): service_file_name = template_file_name[:-3] service_path = os.path.join(dbus_dir, service_file_name) log.info('Writing %s', service_path) if not self.dry_run: self.process_template(template_file_name, service_path) self.outfiles.append(service_path) def process_template(self, template_path, service_path): """Copy template_path to service_path, replacing format specifiers. """ variables = {'install_dir': self.install_dir[len(self.root or ''):]} with file(service_path, 'w') as service_file: for line in file(template_path): service_file.write(line % variables) class install(_install): # pylint: disable=C0103,R0904 """'install' command with support for D-Bus service files""" sub_commands = _install.sub_commands + [('install_dbus', None)] class Test(Command): """Command to run test suite""" description = 'run test suite' user_options = [] def initialize_options(self): pass def finalize_options(self): pass def run(self): sys.exit(subprocess.call(['tests/runalltests.py'])) setup(name='gdatastore', version='0.1', #url='', description='a generic blob+metadata storage not only for Sugar', author='Sascha Silbe', author_email='sascha-pgp@silbe.org', license='GPLv3', cmdclass={'install': install, 'install_dbus': install_dbus, 'test': Test}, packages=['gdatastore'], scripts=['bin/gdatastore-service'], )