setup.py 9.5 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
# any later version.
#
# Please read the COPYING file.
#

frknkrc44's avatar
frknkrc44 committed
16
import inary
17 18 19 20 21
import os
import shutil
import glob
import sys
import inspect
22
import tempfile
23
import subprocess
Suleyman Poyraz's avatar
Suleyman Poyraz committed
24
from distutils.core import setup
25
from distutils.cmd import Command
26
from distutils.command.build import build
27
from distutils.command.install import install
28
from distutils.sysconfig import get_python_lib
29 30 31

sys.path.insert(0, '.')

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

frknkrc44's avatar
frknkrc44 committed
38
# config file
Your Name's avatar
Your Name committed
39
if os.path.isfile(".config"):
frknkrc44's avatar
frknkrc44 committed
40 41
    cfg = open(".config", "r").readlines()

sulincix's avatar
sulincix committed
42 43

def getConfig(name=""):
Your Name's avatar
Your Name committed
44 45
    if not os.path.isfile(".config"):
        return True
sulincix's avatar
sulincix committed
46 47 48 49 50
    for line in cfg:
        if name in line:
            return "y" in line.split("=")[1]
    return False

51 52 53

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

58 59 60
        build.run(self)

        self.mkpath(self.build_base)
61
        if getConfig("NLS_SUPPORT") and 0 == os.system("which intltool-merge"):
62 63
            for in_file in IN_FILES:
                name, ext = os.path.splitext(in_file)
frknkrc44's avatar
frknkrc44 committed
64 65
                self.spawn(["intltool-merge", "-x", "po", in_file,
                            os.path.join(self.build_base, name)])
66

67

68 69
class BuildPo(build):
    def run(self):
70
        if getConfig("NLS_SUPPORT") and 0 == os.system("which intltool-merge"):
71 72
            build.run(self)
            self.build_po()
73

Suleyman Poyraz's avatar
Suleyman Poyraz committed
74 75
    @staticmethod
    def build_po():
76 77 78 79 80 81 82 83 84
        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:
85
            os.system("intltool-extract --type=gettext/xml {}".format(filename))
86

87
        for root, dirs, filenames in os.walk("inary"):
88 89 90 91
            for filename in filenames:
                if filename.endswith(".py"):
                    filelist.append(os.path.join(root, filename))

Suleyman Poyraz's avatar
Suleyman Poyraz committed
92
        filelist.extend(["inary-cli", "inary.xml.in.h", optparse_path])
93 94 95 96 97 98
        filelist.sort()
        with open(files, "w") as _files:
            _files.write("\n".join(filelist))

        # Generate POT file
        os.system("xgettext -L Python \
99
                            --default-domain={0} \
100 101
                            --keyword=_ \
                            --keyword=N_ \
102 103
                            --files-from={1} \
                            -o po/{2}.pot".format(PROJECT, files, PROJECT))
104 105

        # Update PO files
106
        # FIXME: enable this block
107 108
        for item in glob.glob1("po", "*.po"):
            print("Updating .. ", item)
109 110
            os.system(
                "msgmerge --update --no-wrap --sort-by-file po/{0} po/{1}.pot".format(item, PROJECT))
111 112 113 114 115 116 117 118 119 120 121

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

122

123 124 125
class Install(install):
    def run(self):
        install.run(self)
Your Name's avatar
Your Name committed
126
        self.installi18n()
127
        self.generateConfigFile()
128

129 130 131 132 133 134
    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)
135 136

    def installi18n(self):
137
        if not getConfig("NLS_SUPPORT") and 0 == os.system("which intltool-merge"):
Your Name's avatar
Your Name committed
138
            return
139 140 141 142 143
        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
144
            os.system("msgfmt po/{0}.po -o po/{0}.mo".format(lang))
145
            if not self.root:
146
                self.root = "/"
frknkrc44's avatar
frknkrc44 committed
147 148
            destpath = os.path.join(
                self.root, "usr/share/locale/{}/LC_MESSAGES".format(lang))
149 150
            if not os.path.exists(destpath):
                os.makedirs(destpath)
frknkrc44's avatar
frknkrc44 committed
151 152
            shutil.copy("po/{}.mo".format(lang),
                        os.path.join(destpath, "inary.mo"))
153 154

    def generateConfigFile(self):
Suleyman Poyraz's avatar
Suleyman Poyraz committed
155
        import inary.configfile
156
        destpath = os.path.join(self.root, CONFIG_DIR)
157 158 159
        if not os.path.exists(destpath):
            os.makedirs(destpath)

Suleyman Poyraz's avatar
Suleyman Poyraz committed
160
        confFile = os.path.join(destpath, "inary.conf")
161
        if os.path.isfile(confFile):  # Don't overwrite existing inary.conf
162 163
            return

Suleyman Poyraz's avatar
Suleyman Poyraz committed
164
        inaryconf = open(confFile, "w")
165

Suleyman Poyraz's avatar
Suleyman Poyraz committed
166
        klasses = inspect.getmembers(inary.configfile, inspect.isclass)
frknkrc44's avatar
frknkrc44 committed
167 168
        defaults = [
            klass for klass in klasses if klass[0].endswith('Defaults')]
169 170 171

        for d in defaults:
            section_name = d[0][:-len('Defaults')].lower()
172
            inaryconf.write("[{}]\n".format(section_name))
173

frknkrc44's avatar
frknkrc44 committed
174 175
            section_members = [m for m in inspect.getmembers(d[1])
                               if not m[0].startswith('__')
176 177 178
                               and not m[0].endswith('__')]

            for member in section_members:
Suleyman Poyraz's avatar
Suleyman Poyraz committed
179
                if member[1] is None or member[1] == "":
180
                    inaryconf.write("# {0[0]} = {0[1]}\n".format(member))
181
                else:
182
                    inaryconf.write("{0[0]} = {0[1]}\n".format(member))
Suleyman Poyraz's avatar
Suleyman Poyraz committed
183 184
            inaryconf.write('\n')

185

186 187
class Test(Command):
    user_options = []
188

189 190
    def initialize_options(self):
        pass
191

192 193 194 195 196 197 198 199 200 201 202
    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')
        ])

frknkrc44's avatar
frknkrc44 committed
203

Suleyman Poyraz's avatar
Suleyman Poyraz committed
204
setup(name="inary",
205 206 207
      version=inary.__version__,
      description="Inary (Special Package Manager)",
      long_description="Inary is the package management system of Sulin Linux.",
208
      license="GNU GPLv3",
209 210 211 212 213 214
      author="Zaryob",
      author_email="zaryob.dev@gmail.com",
      url="https://github.com/Zaryob/inary",
      # package_dir = {'': ''},

      packages=['inary',
215 216 217 218 219
                'inary.actionsapi',
                'inary.analyzer',
                'inary.cli',
                'inary.data',
                'inary.db',
220
                'inary.libraries',
Your Name's avatar
Your Name committed
221
                'inary.util',
222
                'inary.operations',
Suleyman Poyraz's avatar
Suleyman Poyraz committed
223
                'inary.sxml'],
224 225 226 227
      cmdclass={'build': Build,
                'build_po': BuildPo,
                'install': Install,
                'test': Test},
228
      data_files=[(CONFIG_DIR, ["config/inary.conf", "config/mirrors.conf"]),
229
                  (MIMEFILE_DIR, ["build/inary.xml"] if getConfig("NLS_SUPPORT") and 0 == os.system("which intltool-merge") else [])],
sulincix's avatar
sulincix committed
230
      scripts=(['inary-cli',
frknkrc44's avatar
frknkrc44 committed
231 232 233 234 235 236 237
                'scripts/pspec2po',
                'scripts/revdep-rebuild',
                'scripts/sulinstrapt',
                'scripts/makepkg',
                'scripts/mkdeb',
                'scripts/revdep-rebuild-devel',
                'scripts/inary-sandbox',
Adınız's avatar
Adınız committed
238
                'scripts/inary-template',
frknkrc44's avatar
frknkrc44 committed
239 240 241 242
                'scripts/inarysh',
                'scripts/lsinary',
                'scripts/mkinary',
                'scripts/detect-dep',
Adınız's avatar
Adınız committed
243
                'scripts/detect-revdep',
frknkrc44's avatar
frknkrc44 committed
244 245
                'scripts/detect-file-dep',
                'scripts/uninary',
Adınız's avatar
Adınız committed
246
                'scripts/undeb',
frknkrc44's avatar
frknkrc44 committed
247
                'scripts/genpspec',
Ali Rıza KESKİN's avatar
Ali Rıza KESKİN committed
248
                'scripts/revpspec',
frknkrc44's avatar
frknkrc44 committed
249 250
                'scripts/update-inary-cache',
                'scripts/version-bump'] if getConfig("ADDITIONAL_SCRIPTS") else ['inary-cli']),
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
      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',
frknkrc44's avatar
frknkrc44 committed
280
      ],
281
      )
282 283 284 285 286

# 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
287
INARY_VERSION = inary.__version__