setup.py 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. # Main fork Pisi: Copyright (C) 2005 - 2011, Tubitak/UEKAE
  5. #
  6. # Copyright (C) 2016 - 2017, Suleyman POYRAZ (Zaryob)
  7. #
  8. # This program is free software; you can redistribute it and/or modify it under
  9. # 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. # any later version.
  12. #
  13. # Please read the COPYING file.
  14. #
  15. import os
  16. import shutil
  17. import glob
  18. import sys
  19. import inspect
  20. import tempfile
  21. import subprocess
  22. from distutils.core import setup
  23. from distutils.cmd import Command
  24. from distutils.command.build import build
  25. from distutils.command.install import install
  26. from distutils.sysconfig import get_python_lib
  27. sys.path.insert(0, '.')
  28. import inary
  29. IN_FILES = ("inary.xml.in",)
  30. PROJECT = "inary"
  31. CONFIG_DIR = "/etc/inary"
  32. MIMEFILE_DIR = "/usr/share/mime/packages"
  33. TMPFILES_DIR = "/usr/lib/tmpfiles.d"
  34. class Build(build):
  35. def run(self):
  36. # Preparing configure file
  37. shutil.copy("config/inary.conf-{}".format(os.uname().machine), "config/inary.conf")
  38. build.run(self)
  39. self.mkpath(self.build_base)
  40. for in_file in IN_FILES:
  41. name, ext = os.path.splitext(in_file)
  42. self.spawn(["intltool-merge", "-x", "po", in_file, os.path.join(self.build_base, name)])
  43. class BuildPo(build):
  44. def run(self):
  45. build.run(self)
  46. self.build_po()
  47. @staticmethod
  48. def build_po():
  49. import optparse
  50. files = tempfile.mkstemp()[1]
  51. filelist = []
  52. # Include optparse module path to translate
  53. optparse_path = os.path.abspath(optparse.__file__).rstrip("co")
  54. # Collect headers for mimetype files
  55. for filename in IN_FILES:
  56. os.system("intltool-extract --type=gettext/xml {}".format(filename))
  57. for root, dirs, filenames in os.walk("inary"):
  58. for filename in filenames:
  59. if filename.endswith(".py"):
  60. filelist.append(os.path.join(root, filename))
  61. filelist.extend(["inary-cli", "inary.xml.in.h", optparse_path])
  62. filelist.sort()
  63. with open(files, "w") as _files:
  64. _files.write("\n".join(filelist))
  65. # Generate POT file
  66. os.system("xgettext -L Python \
  67. --default-domain={0} \
  68. --keyword=_ \
  69. --keyword=N_ \
  70. --files-from={1} \
  71. -o po/{2}.pot".format(PROJECT, files, PROJECT))
  72. # Update PO files
  73. for item in glob.glob1("po", "*.po"):
  74. print("Updating .. ", item)
  75. os.system("msgmerge --update --no-wrap --sort-by-file po/{0} po/{1}.pot".format(item, PROJECT))
  76. # Cleanup
  77. os.unlink(files)
  78. for f in filelist:
  79. if not f.endswith(".h"):
  80. continue
  81. try:
  82. os.unlink(f)
  83. except OSError:
  84. pass
  85. class Install(install):
  86. def run(self):
  87. install.run(self)
  88. self.installi18n()
  89. self.generateConfigFile()
  90. def finalize_options(self):
  91. # NOTE: for Sulin distribution
  92. if os.path.exists("/etc/sulin-release"):
  93. self.install_platlib = '$base/lib/sulin'
  94. self.install_purelib = '$base/lib/sulin'
  95. install.finalize_options(self)
  96. def installi18n(self):
  97. for name in os.listdir('po'):
  98. if not name.endswith('.po'):
  99. continue
  100. lang = name[:-3]
  101. print("Installing '{}' translations...".format(lang))
  102. os.system("msgfmt po/{0}.po -o po/{0}.mo".format(lang))
  103. if not self.root:
  104. self.root = "/"
  105. destpath = os.path.join(self.root, "usr/share/locale/{}/LC_MESSAGES".format(lang))
  106. if not os.path.exists(destpath):
  107. os.makedirs(destpath)
  108. shutil.copy("po/{}.mo".format(lang), os.path.join(destpath, "inary.mo"))
  109. def generateConfigFile(self):
  110. import inary.configfile
  111. destpath = os.path.join(self.root, CONFIG_DIR)
  112. if not os.path.exists(destpath):
  113. os.makedirs(destpath)
  114. confFile = os.path.join(destpath, "inary.conf")
  115. if os.path.isfile(confFile): # Don't overwrite existing inary.conf
  116. return
  117. inaryconf = open(confFile, "w")
  118. klasses = inspect.getmembers(inary.configfile, inspect.isclass)
  119. defaults = [klass for klass in klasses if klass[0].endswith('Defaults')]
  120. for d in defaults:
  121. section_name = d[0][:-len('Defaults')].lower()
  122. inaryconf.write("[{}]\n".format(section_name))
  123. section_members = [m for m in inspect.getmembers(d[1]) \
  124. if not m[0].startswith('__') \
  125. and not m[0].endswith('__')]
  126. for member in section_members:
  127. if member[1] is None or member[1] == "":
  128. inaryconf.write("# {0[0]} = {0[1]}\n".format(member))
  129. else:
  130. inaryconf.write("{0[0]} = {0[1]}\n".format(member))
  131. inaryconf.write('\n')
  132. class Test(Command):
  133. user_options = []
  134. def initialize_options(self):
  135. pass
  136. def finalize_options(self):
  137. pass
  138. def run(self):
  139. self.run_command('build')
  140. os.chdir('tests')
  141. subprocess.check_call([
  142. sys.executable, '-bWd',
  143. os.path.join('runTests.py')
  144. ])
  145. setup(name="inary",
  146. version=inary.__version__,
  147. description="Inary (Special Package Manager)",
  148. long_description="Inary is the package management system of Sulin Linux.",
  149. license="GNU GPLv3",
  150. author="Zaryob",
  151. author_email="zaryob.dev@gmail.com",
  152. url="https://github.com/Zaryob/inary",
  153. # package_dir = {'': ''},
  154. packages=['inary',
  155. 'inary.actionsapi',
  156. 'inary.analyzer',
  157. 'inary.cli',
  158. 'inary.data',
  159. 'inary.db',
  160. 'inary.libraries',
  161. 'inary.operations',
  162. 'inary.sxml'],
  163. cmdclass={'build': Build,
  164. 'build_po': BuildPo,
  165. 'install': Install,
  166. 'test': Test},
  167. data_files=[(CONFIG_DIR, ["config/inary.conf", "config/mirrors.conf", "config/sandbox.conf"]),
  168. (MIMEFILE_DIR, ["build/inary.xml"])],
  169. scripts=['inary-cli',
  170. 'scripts/pspec2po',
  171. 'scripts/revdep-rebuild',
  172. 'scripts/sulinstrapt',
  173. 'scripts/update-inary-cache',
  174. 'scripts/version-bump'],
  175. classifiers=[
  176. 'Development Status :: 5 - Production/Stable',
  177. 'Environment :: Console',
  178. 'Environment :: Plugins',
  179. 'Framework :: Sphinx',
  180. 'Intended Audience :: End Users/Desktop',
  181. 'Intended Audience :: Developers',
  182. 'Intended Audience :: System Administrators',
  183. 'License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)',
  184. 'License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+)',
  185. 'Natural Language :: English',
  186. 'Natural Language :: Dutch',
  187. 'Natural Language :: French',
  188. 'Natural Language :: German',
  189. 'Natural Language :: Hungarian',
  190. 'Natural Language :: Italian',
  191. 'Natural Language :: Portuguese (Brazilian)',
  192. 'Natural Language :: Russian',
  193. 'Natural Language :: Slovak',
  194. 'Natural Language :: Turkish',
  195. 'Natural Language :: Ukrainian',
  196. 'Operating System :: MacOS :: MacOS X',
  197. 'Operating System :: POSIX',
  198. 'Operating System :: POSIX :: BSD',
  199. 'Programming Language :: Python :: 3 :: Only',
  200. 'Topic :: Desktop Environment',
  201. 'Topic :: System',
  202. 'Topic :: System :: Installation/Setup',
  203. 'Topic :: Software Development :: Bug Tracking',
  204. ],
  205. )
  206. # the below stuff is really nice but we already have a version
  207. # we can use this stuff for svn snapshots in a separate
  208. # script, or with a parameter I don't know -- exa
  209. INARY_VERSION = inary.__version__