setup.py 8.41 KB
Newer Older
1 2 3
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
4 5 6
# Main fork Pisi: Copyright (C) 2005 - 2011, Tubitak/UEKAE
#
# Copyright (C) 2016 - 2017, Suleyman POYRAZ (Zaryob)
7 8 9
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
10
# Software Foundation; either version 2 of the License, or (at your option)
11 12 13 14 15 16 17 18 19 20
# any later version.
#
# Please read the COPYING file.
#

import os
import shutil
import glob
import sys
import inspect
21
import tempfile
22
import subprocess
Suleyman Poyraz's avatar
Suleyman Poyraz committed
23
from distutils.core import setup
24
from distutils.cmd import Command
25
from distutils.command.build import build
26
from distutils.command.install import install
27
from distutils.sysconfig import get_python_lib
28 29

sys.path.insert(0, '.')
Suleyman Poyraz's avatar
Suleyman Poyraz committed
30
import inary
31

Suleyman Poyraz's avatar
Suleyman Poyraz committed
32 33
IN_FILES = ("inary.xml.in",)
PROJECT = "inary"
34 35 36
CONFIG_DIR = "/etc/inary"
MIMEFILE_DIR = "/usr/share/mime/packages"
TMPFILES_DIR = "/usr/lib/tmpfiles.d"
37 38 39 40


class Build(build):
    def run(self):
41
        # Preparing configure file
42
        shutil.copy("config/inary.conf-{}".format(os.uname().machine), "config/inary.conf")
Suleyman Poyraz's avatar
Suleyman Poyraz committed
43

44 45 46
        build.run(self)

        self.mkpath(self.build_base)
47

48 49 50 51
        for in_file in IN_FILES:
            name, ext = os.path.splitext(in_file)
            self.spawn(["intltool-merge", "-x", "po", in_file, os.path.join(self.build_base, name)])

52

53 54 55 56 57
class BuildPo(build):
    def run(self):
        build.run(self)
        self.build_po()

Suleyman Poyraz's avatar
Suleyman Poyraz committed
58 59
    @staticmethod
    def build_po():
60 61 62 63 64 65 66 67 68
        import optparse
        files = tempfile.mkstemp()[1]
        filelist = []

        # Include optparse module path to translate
        optparse_path = os.path.abspath(optparse.__file__).rstrip("co")

        # Collect headers for mimetype files
        for filename in IN_FILES:
69
            os.system("intltool-extract --type=gettext/xml {}".format(filename))
70

71
        for root, dirs, filenames in os.walk("inary"):
72 73 74 75
            for filename in filenames:
                if filename.endswith(".py"):
                    filelist.append(os.path.join(root, filename))

Suleyman Poyraz's avatar
Suleyman Poyraz committed
76
        filelist.extend(["inary-cli", "inary.xml.in.h", optparse_path])
77 78 79 80 81 82
        filelist.sort()
        with open(files, "w") as _files:
            _files.write("\n".join(filelist))

        # Generate POT file
        os.system("xgettext -L Python \
83
                            --default-domain={0} \
84 85
                            --keyword=_ \
                            --keyword=N_ \
86 87
                            --files-from={1} \
                            -o po/{2}.pot".format(PROJECT, files, PROJECT))
88 89 90

        # Update PO files
        for item in glob.glob1("po", "*.po"):
Suleyman Poyraz's avatar
Suleyman Poyraz committed
91
            print("Updating .. ", item)
92
            os.system("msgmerge --update --no-wrap --sort-by-file po/{0} po/{1}.pot".format(item, PROJECT))
93 94 95 96 97 98 99 100 101 102 103

        # Cleanup
        os.unlink(files)
        for f in filelist:
            if not f.endswith(".h"):
                continue
            try:
                os.unlink(f)
            except OSError:
                pass

104

105 106 107
class Install(install):
    def run(self):
        install.run(self)
108
        self.installi18n()
109
        self.generateConfigFile()
110

111 112 113 114 115 116
    def finalize_options(self):
        # NOTE: for Sulin distribution
        if os.path.exists("/etc/sulin-release"):
            self.install_platlib = '$base/lib/sulin'
            self.install_purelib = '$base/lib/sulin'
        install.finalize_options(self)
117 118

    def installi18n(self):
119 120 121 122 123
        for name in os.listdir('po'):
            if not name.endswith('.po'):
                continue
            lang = name[:-3]
            print("Installing '{}' translations...".format(lang))
Suleyman Poyraz's avatar
Suleyman Poyraz committed
124
            os.system("msgfmt po/{0}.po -o po/{0}.mo".format(lang))
125
            if not self.root:
126
                self.root = "/"
127 128 129 130
            destpath = os.path.join(self.root, "usr/share/locale/{}/LC_MESSAGES".format(lang))
            if not os.path.exists(destpath):
                os.makedirs(destpath)
            shutil.copy("po/{}.mo".format(lang), os.path.join(destpath, "inary.mo"))
131 132

    def generateConfigFile(self):
Suleyman Poyraz's avatar
Suleyman Poyraz committed
133
        import inary.configfile
134
        destpath = os.path.join(self.root, CONFIG_DIR)
135 136 137
        if not os.path.exists(destpath):
            os.makedirs(destpath)

Suleyman Poyraz's avatar
Suleyman Poyraz committed
138
        confFile = os.path.join(destpath, "inary.conf")
139
        if os.path.isfile(confFile):  # Don't overwrite existing inary.conf
140 141
            return

Suleyman Poyraz's avatar
Suleyman Poyraz committed
142
        inaryconf = open(confFile, "w")
143

Suleyman Poyraz's avatar
Suleyman Poyraz committed
144
        klasses = inspect.getmembers(inary.configfile, inspect.isclass)
145 146 147 148
        defaults = [klass for klass in klasses if klass[0].endswith('Defaults')]

        for d in defaults:
            section_name = d[0][:-len('Defaults')].lower()
149
            inaryconf.write("[{}]\n".format(section_name))
150 151 152 153 154 155

            section_members = [m for m in inspect.getmembers(d[1]) \
                               if not m[0].startswith('__') \
                               and not m[0].endswith('__')]

            for member in section_members:
Suleyman Poyraz's avatar
Suleyman Poyraz committed
156
                if member[1] is None or member[1] == "":
157
                    inaryconf.write("# {0[0]} = {0[1]}\n".format(member))
158
                else:
159
                    inaryconf.write("{0[0]} = {0[1]}\n".format(member))
Suleyman Poyraz's avatar
Suleyman Poyraz committed
160 161
            inaryconf.write('\n')

162

163 164
class Test(Command):
    user_options = []
165

166 167
    def initialize_options(self):
        pass
168

169 170 171 172 173 174 175 176 177 178 179
    def finalize_options(self):
        pass

    def run(self):
        self.run_command('build')
        os.chdir('tests')
        subprocess.check_call([
            sys.executable, '-bWd',
            os.path.join('runTests.py')
        ])

Suleyman Poyraz's avatar
Suleyman Poyraz committed
180
setup(name="inary",
181 182 183
      version=inary.__version__,
      description="Inary (Special Package Manager)",
      long_description="Inary is the package management system of Sulin Linux.",
184
      license="GNU GPLv3",
185 186 187 188 189 190
      author="Zaryob",
      author_email="zaryob.dev@gmail.com",
      url="https://github.com/Zaryob/inary",
      # package_dir = {'': ''},

      packages=['inary',
191 192 193 194 195
                'inary.actionsapi',
                'inary.analyzer',
                'inary.cli',
                'inary.data',
                'inary.db',
196
                'inary.libraries',
197
                'inary.operations',
Suleyman Poyraz's avatar
Suleyman Poyraz committed
198
                'inary.sxml'],
199 200 201 202
      cmdclass={'build': Build,
                'build_po': BuildPo,
                'install': Install,
                'test': Test},
203
      data_files=[(CONFIG_DIR, ["config/inary.conf", "config/mirrors.conf"]),
204 205 206 207
                  (MIMEFILE_DIR, ["build/inary.xml"])],
      scripts=['inary-cli',
               'scripts/pspec2po',
               'scripts/revdep-rebuild',
Ali Rıza Keskin's avatar
Ali Rıza Keskin committed
208
               'scripts/sulinstrapt',
Ali Rıza KESKİN's avatar
Ali Rıza KESKİN committed
209
               'scripts/makepkg',
sulincix's avatar
sulincix committed
210 211 212 213 214
               'scripts/mkdeb',
               'scripts/revdep-rebuild-devel',
               'scripts/inary-sandbox',
               'scripts/inarysh',
               'scripts/lsinary',
sulincix's avatar
sulincix committed
215 216
               'scripts/detect-dep',
               'scripts/detect-file-dep',
sulincix's avatar
sulincix committed
217
               'scripts/uninary',
Ali Rıza Keskin's avatar
Ali Rıza Keskin committed
218
               'scripts/update-inary-cache',
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249
               'scripts/version-bump'],
      classifiers=[
          'Development Status :: 5 - Production/Stable',
          'Environment :: Console',
          'Environment :: Plugins',
          'Framework :: Sphinx',
          'Intended Audience :: End Users/Desktop',
          'Intended Audience :: Developers',
          'Intended Audience :: System Administrators',
          'License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)',
          'License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+)',
          'Natural Language :: English',
          'Natural Language :: Dutch',
          'Natural Language :: French',
          'Natural Language :: German',
          'Natural Language :: Hungarian',
          'Natural Language :: Italian',
          'Natural Language :: Portuguese (Brazilian)',
          'Natural Language :: Russian',
          'Natural Language :: Slovak',
          'Natural Language :: Turkish',
          'Natural Language :: Ukrainian',
          'Operating System :: MacOS :: MacOS X',
          'Operating System :: POSIX',
          'Operating System :: POSIX :: BSD',
          'Programming Language :: Python :: 3 :: Only',
          'Topic :: Desktop Environment',
          'Topic :: System',
          'Topic :: System :: Installation/Setup',
          'Topic :: Software Development :: Bug Tracking',
          ],
250
      )
251 252 253 254 255

# the below stuff is really nice but we already have a version
# we can use this stuff for svn snapshots in a separate
# script, or with a parameter I don't know -- exa

Suleyman Poyraz's avatar
Suleyman Poyraz committed
256
INARY_VERSION = inary.__version__