forked from ssato/python-anyconfig
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
48 lines (35 loc) · 1.39 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
from __future__ import absolute_import
import glob
import os.path
import os
import re
import setuptools
import setuptools.command.bdist_rpm
# It might throw IndexError and so on.
VERSION = [re.search(r'^VERSION = "([^"]+)"', l).groups()[0] for l
in open(glob.glob("src/*/globals.py")[0]).readlines()
if "VERSION" in l][0]
# For daily snapshot versioning mode:
if os.environ.get("_SNAPSHOT_BUILD", None) is not None:
import datetime
VERSION = VERSION + datetime.datetime.now().strftime(".%Y%m%d")
class bdist_rpm(setuptools.command.bdist_rpm.bdist_rpm):
"""Override the default content of the RPM SPEC.
"""
spec_tmpl = os.path.join(os.path.abspath(os.curdir),
"pkg/package.spec.in")
def _replace(self, line):
"""Replace some strings in the RPM SPEC template"""
if "@VERSION@" in line:
return line.replace("@VERSION@", VERSION)
if "Source0:" in line: # Dirty hack
return "Source0: %{pkgname}-%{version}.tar.gz"
return line
def _make_spec_file(self):
return [self._replace(l.rstrip()) for l
in open(self.spec_tmpl).readlines()]
setuptools.setup(version=VERSION,
cmdclass=dict(bdist_rpm=bdist_rpm),
package_dir={'': 'src'},
data_files=[("share/man/man1", ["docs/anyconfig_cli.1"])])
# vim:sw=4:ts=4:et: