File: setup.py

package info (click to toggle)
python2-pythondialog 3.3.0-2~bpo8%2B1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-backports
  • size: 2,760 kB
  • sloc: python: 3,829; makefile: 150
file content (148 lines) | stat: -rwxr-xr-x 6,164 bytes parent folder | download | duplicates (3)
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#! /usr/bin/env python
# -*- coding: utf-8 -*-

# setup.py --- Setup script for pythondialog
# Copyright (c) 2002, 2003, 2004, 2009, 2010, 2013, 2014, 2015  Florent Rougon
#
# This file is part of pythondialog.
#
# pythondialog is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# pythondialog 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
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
# MA  02110-1301 USA.

from __future__ import with_statement, unicode_literals, print_function
import os, sys, subprocess, traceback
from distutils.core import setup
from io import open


PACKAGE = "pythondialog"
# This is OK because dialog.py has no dependency outside the standard library.
from dialog import __version__ as VERSION


def run_gitlog_to_changelog(after_this_commit, output=None):
    args = [ "gitlog-to-changelog", "--format=%s%n%n%b%n", "--",
             "{0}..".format(after_this_commit) ]
    try:
        subprocess.check_call(args, stdout=output)
    except os.error:
        print(traceback.format_exc(), file=sys.stderr)

        # If the following message contained non-ASCII characters and stderr
        # were not a tty (e.g., redirection or pipe), this would fail in
        # Python 2. demo.py has the correct infrastructure for this issue,
        # however this would be a bit overkill here.
        print("""\
Error (see above for a traceback): unable to run {prg}
================================================={underlining}
Maybe this program is not installed on your system. You can download it from:

  {url}

Note: if you have problems with the infamous shell+Perl crap in the first lines
of that file, you can replace it with a simple shebang line such as
"#! /usr/bin/perl".""".format(
   prg=args[0],
   underlining="=" * len(args[0]),
   url="http://git.savannah.gnu.org/gitweb/?p=gnulib.git;a=blob_plain;"
       "f=build-aux/gitlog-to-changelog"), file=sys.stderr)
        sys.exit(1)


def generate_changelog(ch_name, write_to_stdout=False):
    print("Converting the Git log into ChangeLog format...", end=' ',
          file=sys.stderr)
    orig_ch_name = "{0}.init".format(ch_name)
    # Most recent commit in the file referenced by 'orig_ch_name' (normally,
    # ChangeLog.init)
    last_commit_in_ch_init = "b69a76b550d62fd5965a3e37957aa3fbc11e1a5f"

    if write_to_stdout:
        run_gitlog_to_changelog(last_commit_in_ch_init)

        with open(orig_ch_name, "r", encoding="utf-8") as orig_ch:
            # Make sure the output is encoded in UTF-8
            sys.stdout.write(("\n" + orig_ch.read()).encode("utf-8"))
    else:
        tmp_ch_name = "{0}.new".format(ch_name)

        try:
            with open(tmp_ch_name, "w", encoding="utf-8") as tmp_ch:
                run_gitlog_to_changelog(last_commit_in_ch_init, output=tmp_ch)

                with open(orig_ch_name, "r", encoding="utf-8") as orig_ch:
                    tmp_ch.write("\n" + orig_ch.read())

            os.rename(tmp_ch_name, ch_name)
        finally:
            if os.path.exists(tmp_ch_name):
                os.unlink(tmp_ch_name)

    print("done.", file=sys.stderr)


def main():
    ch_name = "ChangeLog"
    if os.path.isdir(".git"):
        generate_changelog(ch_name)
    elif not os.path.isfile(ch_name):
        msg = """\
There is no '{cl}' file here and it seems you are not operating from a
clone of the Git repository (no .git directory); therefore, it is impossible to
generate the '{cl}' file from the Git log. Aborting.""".format(cl=ch_name)
        sys.exit(msg)

    with open("README.rst", "r", encoding="utf-8") as f:
        long_description = f.read()

    setup(name="python2-{0}".format(PACKAGE),
          version=VERSION,
          description="A Python interface to the UNIX dialog utility and "
          "mostly-compatible programs (Python 2 backport)",
#         Doesn't work great with several authors...
          author="Robb Shecter, Sultanbek Tezadov, Florent Rougon, "
                 "Peter Åstrand",
          author_email="robb@acm.org, http://sultan.da.ru/, f.rougon@free.fr, "
                       "peter@cendio.se",
          maintainer="Florent Rougon",
          maintainer_email="f.rougon@free.fr",
          url="http://pythondialog.sourceforge.net/",
          download_url="http://sourceforge.net/projects/pythondialog/files/\
pythondialog/{version}/python2-{pkg}-{version}.tar.bz2".format(
            pkg=PACKAGE, version=VERSION),
          # Well, there isn't much UNIX-specific code in dialog.py, if at all.
          # I am putting Unix here only because of the dialog dependency...
          # Note: using the "Unix" case instead of "UNIX", because it is
          # spelled this way in Trove classifiers.
          platforms=["Unix"],
          long_description=long_description,
          keywords=["dialog", "ncurses", "Xdialog", "text-mode interface",
                    "terminal"],
          classifiers=[
            "Programming Language :: Python :: 2",
            "Programming Language :: Python :: 2.6",
            "Programming Language :: Python :: 2.7",
            "Development Status :: 5 - Production/Stable",
            "Environment :: Console :: Curses",
            "Intended Audience :: Developers",
            "License :: OSI Approved :: GNU Library or Lesser General Public "
            "License (LGPL)",
            "Operating System :: Unix",
            "Topic :: Software Development :: Libraries :: Python Modules",
            "Topic :: Software Development :: User Interfaces",
            "Topic :: Software Development :: Widget Sets"],
          py_modules=["dialog"])

if __name__ == "__main__": main()