SrpmCommand.pre_sdist()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
from __future__ import absolute_import
2
from setuptools import setup, Command
3
4
import glob
5
import os.path
6
import os
7
import subprocess
8
import sys
9
10
sys.path.insert(0, os.path.dirname(__file__))  # load anyconfig from this dir.
11
12
from anyconfig.globals import PACKAGE, VERSION
13
14
15
# For daily snapshot versioning mode:
16
if os.environ.get("_SNAPSHOT_BUILD", None) is not None:
17
    import datetime
18
    VERSION = VERSION + datetime.datetime.now().strftime(".%Y%m%d")
19
20
21
_LONG_DESC = """
22
python-anyconfig [#]_ is a `MIT licensed <http://opensource.org/licenses/MIT>`_
23
python library provides common APIs to load and dump configuration files in
24
various formats with some useful features such as contents merge, templates,
25
query, schema validation and generation support.
26
27
- Home: https://github.com/ssato/python-anyconfig
28
- (Latest) Doc: http://python-anyconfig.readthedocs.org/en/latest/
29
- PyPI: https://pypi.python.org/pypi/anyconfig
30
- Copr RPM repos: https://copr.fedoraproject.org/coprs/ssato/python-anyconfig/
31
32
.. [#] This name took an example from the 'anydbm' python standard library.
33
"""
34
35
def list_filepaths(tdir):
36
    return [f for f in glob.glob(os.path.join(tdir, '*')) if os.path.isfile(f)]
37
38
39
# TBD:
40
# data_files = [("share/man/man1", list_filepaths("docs/"))]
41
data_files = [("share/man/man1", ["docs/anyconfig_cli.1"])]
42
43
44
class SrpmCommand(Command):
45
46
    user_options = []
47
    build_stage = "s"
48
49
    curdir = os.path.abspath(os.curdir)
50
    rpmspec = os.path.join(curdir, "pkg/package.spec")
51
    gen_readme = os.path.join(curdir, "pkg/gen-readme.sh")
52
53
    def initialize_options(self):
54
        pass
55
56
    def finalize_options(self):
57
        pass
58
59
    def run(self):
60
        self.pre_sdist()
61
        self.run_command('sdist')
62
        # Dirty hack.
63
        self.copy_file("dist/%s-%s.tar.gz" % (PACKAGE, VERSION),
64
                       "dist/RELEASE_%s.tar.gz" % VERSION)
65
        self.build_rpm()
66
67
    def pre_sdist(self):
68
        c = open(self.rpmspec + ".in").read()
69
        open(self.rpmspec, "w").write(c.replace("@VERSION@", VERSION))
70
        subprocess.check_call(self.gen_readme, shell=True)
71
72
    def build_rpm(self):
73
        rpmbuild = os.path.join(self.curdir, "pkg/rpmbuild-wrapper.sh")
74
        workdir = os.path.join(self.curdir, "dist")
75
76
        cmd_s = "%s -w %s -s %s %s" % (rpmbuild, workdir, self.build_stage,
77
                                       self.rpmspec)
78
        subprocess.check_call(cmd_s, shell=True)
79
80
81
class RpmCommand(SrpmCommand):
82
83
    build_stage = "b"
84
85
86
_CLASSIFIERS = ["Development Status :: 4 - Beta",
87
                "Intended Audience :: Developers",
88
                "Programming Language :: Python",
89
                "Programming Language :: Python :: 2",
90
                "Programming Language :: Python :: 3",
91
                "Programming Language :: Python :: 2.7",
92
                "Programming Language :: Python :: 3.4",
93
                "Programming Language :: Python :: 3.5",
94
                "Programming Language :: Python :: 3.6",
95
                "Programming Language :: Python :: 3.7",
96
                "Environment :: Console",
97
                "Operating System :: OS Independent",
98
                "Topic :: Software Development :: Libraries :: Python Modules",
99
                "Topic :: Text Processing :: Markup",
100
                "Topic :: Utilities",
101
                "License :: OSI Approved :: MIT License"]
102
103
104
setup(name=PACKAGE,
105
      version=VERSION,
106
      description=("Library provides common APIs to load and dump configuration "
107
                   "files in various formats"),
108
      long_description=_LONG_DESC,
109
      author="Satoru SATOH",
110
      author_email="[email protected]",
111
      license="MIT",
112
      url="https://github.com/ssato/python-anyconfig",
113
      classifiers=_CLASSIFIERS,
114
      packages=["anyconfig"],
115
      include_package_data=True,
116
      cmdclass={
117
          "srpm": SrpmCommand,
118
          "rpm":  RpmCommand,
119
      },
120
      entry_points=open(os.path.join(os.curdir,
121
                                     "pkg/entry_points.txt")).read(),
122
      data_files=data_files)
123
124
# vim:sw=4:ts=4:et:
125