1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
#!/usr/bin/env python
#
# Author: Sascha Silbe <sascha-pgp@silbe.org>
#
# 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 <http://www.gnu.org/licenses/>.
"""
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'],
)
|