-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
executable file
·94 lines (73 loc) · 2.74 KB
/
setup.py
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
#!/usr/bin/python3
#
# sd-keepaneye, keeping an eye on systemd.
# Copyright (C) 2021 Alexandre Rossi <[email protected]>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# 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, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
import glob
import os
import shutil
import setuptools
import setuptools.command.build_py
def newer(fpath1, fpath2):
if os.path.isfile(fpath2):
return os.path.getmtime(fpath1) > os.path.getmtime(fpath2)
else:
return True
class build_manpages(setuptools.Command):
description = 'Build manpages'
user_options = []
manpages = None
mandir = os.path.join(os.path.dirname(__file__), 'man')
executable = shutil.which('pandoc')
def initialize_options(self):
pass
def finalize_options(self):
self.manpages = glob.glob(os.path.join(self.mandir, '*.md'))
def __get_man_section(self, filename):
# filename should be file.mansection.md
return filename.split('.')[-2]
def run(self):
data_files = self.distribution.data_files
for manpagesrc in self.manpages:
manpage = os.path.splitext(manpagesrc)[0] # remove '.md' at the end
section = manpage[-1:]
if newer(manpagesrc, manpage):
cmd = (self.executable, '-s', '-t', 'man',
'-o', manpage,
manpagesrc)
self.spawn(cmd)
targetpath = os.path.join('share', 'man', 'man%s' % section)
data_files.append((targetpath, (manpage, ), ))
class build(setuptools.command.build_py.build_py):
def run(self):
if build_manpages.executable is not None:
self.run_command('build_manpages')
super(build, self).run()
setuptools.setup(
name='sd-keepaneye',
version='0.8',
description='Keeping an eye on systemd',
author='Alexandre Rossi',
author_email='[email protected]',
url='https://sml.zincube.net/~niol/repositories.git/sd-keepaneye/about/',
scripts=['keepaneye'],
packages=['sdkeepaneye'],
data_files=[],
cmdclass = {
'build_py' : build,
'build_manpages': build_manpages,
},
)