Completed
Pull Request — master (#1284)
by Lasse
02:34 queued 47s
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
    data_files = [
58
        ('.', ['coala.1']),
59
        ('.', [Constants.BUS_NAME + '.service']),
60
        ('bears/java', [download('http://sourceforge.net/projects/checkstyle/f'
61
                                 'iles/checkstyle/6.15/checkstyle-6.15-all.jar',
62
                                 'bears/java/checkstyle.jar')])]
63
64
    setup(name='coala',
65
          version=Constants.VERSION,
66
          description='Code Analysis Application (coala)',
67
          author="The coala developers",
68
          maintainer="Lasse Schuirmann, Fabian Neuschmidt, Mischa Kr\xfcger",
69
          maintainer_email=('[email protected], '
70
                            '[email protected], '
71
                            '[email protected]'),
72
          url='http://coala.rtfd.org/',
73
          platforms='any',
74
          packages=find_packages(exclude=["build.*", "*.tests.*", "*.tests"]),
75
          install_requires=required,
76
          package_data={'coalib': ['default_coafile', "VERSION"]},
77
          license="AGPL v3",
78
          data_files=data_files,
79
          long_description="coala is a simple COde AnaLysis Application. Its "
80
                           "goal is to make static code analysis easy while "
81
                           "remaining completely modular and therefore "
82
                           "extendable and language independent. Code analysis"
83
                           " happens in python scripts while coala manages "
84
                           "these, tries to provide helpful libraries and "
85
                           "provides a user interface. Please visit "
86
                           "http://coala.rtfd.org/ for more information or our"
87
                           "development repository on "
88
                           "https://github.com/coala-analyzer/coala/.",
89
          entry_points={
90
              "console_scripts": [
91
                  "coala = coalib.coala:main",
92
                  "coala-ci = coalib.coala_ci:main",
93
                  "coala-dbus = coalib.coala_dbus:main",
94
                  "coala-json = coalib.coala_json:main",
95
                  "coala-format = coalib.coala_format:main"]},
96
          # from http://pypi.python.org/pypi?%3Aaction=list_classifiers
97
          classifiers=[
98
              'Development Status :: 3 - Alpha',
99
100
              'Environment :: Console',
101
              'Environment :: MacOS X',
102
              'Environment :: Win32 (MS Windows)',
103
              'Environment :: X11 Applications :: Gnome',
104
105
              'Intended Audience :: Science/Research',
106
              'Intended Audience :: Developers',
107
108
              'License :: OSI Approved :: GNU Affero General Public License '
109
              'v3 or later (AGPLv3+)',
110
111
              'Operating System :: OS Independent',
112
113
              'Programming Language :: Python :: Implementation :: CPython',
114
              'Programming Language :: Python :: 3.3',
115
              'Programming Language :: Python :: 3.4',
116
              'Programming Language :: Python :: 3.5',
117
              'Programming Language :: Python :: 3 :: Only',
118
119
              'Topic :: Scientific/Engineering :: Information Analysis',
120
              'Topic :: Software Development :: Quality Assurance',
121
              'Topic :: Text Processing :: Linguistic'],
122
          cmdclass={'build_manpage': BuildManPage,
123
                    'build_dbus': BuildDbusService,
124
                    'build_py': BuildPyCommand})
125