Failed Conditions
Pull Request — master (#1307)
by Lasse
01:44
created

download()   A

Complexity

Conditions 4

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 4
dl 0
loc 19
rs 9.2
1
#!/usr/bin/env python3
2
3
import locale
4
from urllib.request import urlopen
5
from shutil import copyfileobj
6
from os.path import exists
7
from sys import stdout
8
from setuptools import setup, find_packages
9
import setuptools.command.build_py
10
11
from coalib import assert_supported_version
12
assert_supported_version()
13
from coalib.misc.BuildManPage import BuildManPage
14
from coalib.output.dbus.BuildDbusService import BuildDbusService
15
from coalib.misc import Constants
16
17
try:
18
    locale.getlocale()
19
except (ValueError, UnicodeError):
20
    locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')
21
22
23
def download(url: str, filename: str, overwrite: bool=False):
24
    """
25
    Downloads the given URL to the given filename. If the file exists, it won't
26
    be downloaded.
27
28
    :param url:       A URL to download.
29
    :param filename:  The file to store the downloaded file to.
30
    :param overwrite: Set to True if the file should be downloaded even if it
31
                      already exists.
32
    :return:          The filename.
33
    """
34
    if not exists(filename) or overwrite:
35
        print("Downloading", filename + "...", end='')
36
        stdout.flush()
37
        with urlopen(url) as response, open(filename, 'wb') as out_file:
38
            copyfileobj(response, out_file)
39
        print(" DONE.")
40
41
    return filename
42
43
44
class BuildPyCommand(setuptools.command.build_py.build_py):
45
46
    def run(self):
47
        self.run_command('build_manpage')
48
        self.run_command('build_dbus')
49
        setuptools.command.build_py.build_py.run(self)
50
51
52
with open('requirements.txt') as requirements:
53
    required = requirements.read().splitlines()
54
55
56
if __name__ == "__main__":
57
    download('http://sourceforge.net/projects/checkstyle/files/checkstyle/'
58
             '6.15/checkstyle-6.15-all.jar',
59
             'bears/java/checkstyle.jar')
60
    data_files = [('.', ['coala.1']), ('.', [Constants.BUS_NAME + '.service'])]
61
62
    setup(name='coala',
63
          version=Constants.VERSION,
64
          description='Code Analysis Application (coala)',
65
          author="The coala developers",
66
          maintainer="Lasse Schuirmann, Fabian Neuschmidt, Mischa Kr\xfcger",
67
          maintainer_email=('[email protected], '
68
                            '[email protected], '
69
                            '[email protected]'),
70
          url='http://coala.rtfd.org/',
71
          platforms='any',
72
          packages=find_packages(exclude=["build.*", "*.tests.*", "*.tests"]),
73
          install_requires=required,
74
          package_data={'coalib': ['default_coafile', "VERSION"],
75
                        'bears.java': ['checkstyle.jar', 'google_checks.xml']},
76
          license="AGPL v3",
77
          data_files=data_files,
78
          long_description="coala is a simple COde AnaLysis Application. Its "
79
                           "goal is to make static code analysis easy while "
80
                           "remaining completely modular and therefore "
81
                           "extendable and language independent. Code analysis"
82
                           " happens in python scripts while coala manages "
83
                           "these, tries to provide helpful libraries and "
84
                           "provides a user interface. Please visit "
85
                           "http://coala.rtfd.org/ for more information or our"
86
                           "development repository on "
87
                           "https://github.com/coala-analyzer/coala/.",
88
          entry_points={
89
              "console_scripts": [
90
                  "coala = coalib.coala:main",
91
                  "coala-ci = coalib.coala_ci:main",
92
                  "coala-dbus = coalib.coala_dbus:main",
93
                  "coala-json = coalib.coala_json:main",
94
                  "coala-format = coalib.coala_format:main"]},
95
          # from http://pypi.python.org/pypi?%3Aaction=list_classifiers
96
          classifiers=[
97
              'Development Status :: 3 - Alpha',
98
99
              'Environment :: Console',
100
              'Environment :: MacOS X',
101
              'Environment :: Win32 (MS Windows)',
102
              'Environment :: X11 Applications :: Gnome',
103
104
              'Intended Audience :: Science/Research',
105
              'Intended Audience :: Developers',
106
107
              'License :: OSI Approved :: GNU Affero General Public License '
108
              'v3 or later (AGPLv3+)',
109
110
              'Operating System :: OS Independent',
111
112
              'Programming Language :: Python :: Implementation :: CPython',
113
              'Programming Language :: Python :: 3.3',
114
              'Programming Language :: Python :: 3.4',
115
              'Programming Language :: Python :: 3.5',
116
              'Programming Language :: Python :: 3 :: Only',
117
118
              'Topic :: Scientific/Engineering :: Information Analysis',
119
              'Topic :: Software Development :: Quality Assurance',
120
              'Topic :: Text Processing :: Linguistic'],
121
          cmdclass={'build_manpage': BuildManPage,
122
                    'build_dbus': BuildDbusService,
123
                    'build_py': BuildPyCommand})
124