setup.py 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  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 inary
  16. import os
  17. import shutil
  18. import glob
  19. import sys
  20. import inspect
  21. import tempfile
  22. import subprocess
  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. sys.path.insert(0, '.')
  29. IN_FILES = ("inary.xml.in",)
  30. PROJECT = "inary"
  31. CONFIG_DIR = "/etc/inary"
  32. MIMEFILE_DIR = "/usr/share/mime/packages"
  33. ICONS_DIR = "/usr/share/icons/hicolor/scalable/mimetypes"
  34. PIXMAP_DIR = "/usr/share/pixmaps"
  35. THUMBNAILER_DIR="/usr/share/thumbnailers"
  36. TMPFILES_DIR = "/usr/lib/tmpfiles.d"
  37. # config file
  38. if os.path.isfile(".config"):
  39. cfg = open(".config", "r").readlines()
  40. def getConfig(name=""):
  41. if not os.path.isfile(".config"):
  42. return True
  43. for line in cfg:
  44. if name in line:
  45. return "y" in line.split("=")[1]
  46. return False
  47. class Build(build):
  48. def run(self):
  49. # Preparing configure file
  50. shutil.copy("config/inary.conf-{}".format(os.uname().machine),
  51. "config/inary.conf")
  52. build.run(self)
  53. self.mkpath(self.build_base)
  54. if getConfig("NLS_SUPPORT") and 0 == os.system("which intltool-merge"):
  55. for in_file in IN_FILES:
  56. name, ext = os.path.splitext(in_file)
  57. self.spawn(["intltool-merge", "-x", "po", in_file,
  58. os.path.join(self.build_base, name)])
  59. class BuildPo(build):
  60. def run(self):
  61. if getConfig("NLS_SUPPORT") and 0 == os.system("which intltool-merge"):
  62. build.run(self)
  63. self.build_po()
  64. @staticmethod
  65. def build_po():
  66. import optparse
  67. files = tempfile.mkstemp()[1]
  68. filelist = []
  69. # Include optparse module path to translate
  70. optparse_path = os.path.abspath(optparse.__file__).rstrip("co")
  71. # Collect headers for mimetype files
  72. for filename in IN_FILES:
  73. os.system("intltool-extract --type=gettext/xml {}".format(filename))
  74. for root, dirs, filenames in os.walk("inary"):
  75. for filename in filenames:
  76. if filename.endswith(".py"):
  77. filelist.append(os.path.join(root, filename))
  78. filelist.extend(["inary-cli", "inary.xml.in.h", optparse_path])
  79. filelist.sort()
  80. with open(files, "w") as _files:
  81. _files.write("\n".join(filelist))
  82. # Generate POT file
  83. os.system("xgettext -L Python \
  84. --default-domain={0} \
  85. --keyword=_ \
  86. --keyword=N_ \
  87. --files-from={1} \
  88. -o po/{2}.pot".format(PROJECT, files, PROJECT))
  89. # Update PO files
  90. # FIXME: enable this block
  91. for item in glob.glob1("po", "*.po"):
  92. print("Updating .. ", item)
  93. os.system(
  94. "msgmerge --update --no-wrap --sort-by-file po/{0} po/{1}.pot".format(item, PROJECT))
  95. # Cleanup
  96. os.unlink(files)
  97. for f in filelist:
  98. if not f.endswith(".h"):
  99. continue
  100. try:
  101. os.unlink(f)
  102. except OSError:
  103. pass
  104. class Install(install):
  105. def run(self):
  106. install.run(self)
  107. self.installi18n()
  108. self.generateConfigFile()
  109. def finalize_options(self):
  110. # NOTE: for Sulin distribution
  111. if os.path.exists("/etc/sulin-release"):
  112. self.install_platlib = '$base/lib/sulin'
  113. self.install_purelib = '$base/lib/sulin'
  114. install.finalize_options(self)
  115. def installi18n(self):
  116. if not getConfig("NLS_SUPPORT") and 0 == os.system("which intltool-merge"):
  117. return
  118. for name in os.listdir('po'):
  119. if not name.endswith('.po'):
  120. continue
  121. lang = name[:-3]
  122. print("Installing '{}' translations...".format(lang))
  123. os.system("msgfmt po/{0}.po -o po/{0}.mo".format(lang))
  124. if not self.root:
  125. self.root = "/"
  126. destpath = os.path.join(
  127. self.root, "usr/share/locale/{}/LC_MESSAGES".format(lang))
  128. if not os.path.exists(destpath):
  129. os.makedirs(destpath)
  130. shutil.copy("po/{}.mo".format(lang),
  131. os.path.join(destpath, "inary.mo"))
  132. def generateConfigFile(self):
  133. import inary.configfile
  134. destpath = os.path.join(self.root, CONFIG_DIR)
  135. if not os.path.exists(destpath):
  136. os.makedirs(destpath)
  137. confFile = os.path.join(destpath, "inary.conf")
  138. if os.path.isfile(confFile): # Don't overwrite existing inary.conf
  139. return
  140. inaryconf = open(confFile, "w")
  141. klasses = inspect.getmembers(inary.configfile, inspect.isclass)
  142. defaults = [
  143. klass for klass in klasses if klass[0].endswith('Defaults')]
  144. for d in defaults:
  145. section_name = d[0][:-len('Defaults')].lower()
  146. inaryconf.write("[{}]\n".format(section_name))
  147. section_members = [m for m in inspect.getmembers(d[1])
  148. if not m[0].startswith('__')
  149. and not m[0].endswith('__')]
  150. for member in section_members:
  151. if member[1] is None or member[1] == "":
  152. inaryconf.write("# {0[0]} = {0[1]}\n".format(member))
  153. else:
  154. inaryconf.write("{0[0]} = {0[1]}\n".format(member))
  155. inaryconf.write('\n')
  156. class Test(Command):
  157. user_options = []
  158. def initialize_options(self):
  159. pass
  160. def finalize_options(self):
  161. pass
  162. def run(self):
  163. self.run_command('build')
  164. os.chdir('tests')
  165. subprocess.check_call([
  166. sys.executable, '-bWd',
  167. os.path.join('runTests.py')
  168. ])
  169. setup(name="inary",
  170. version=inary.__version__,
  171. description="Inary (Special Package Manager)",
  172. long_description="Inary is the package management system of Sulin Linux.",
  173. license="GNU GPLv3",
  174. author="Zaryob",
  175. author_email="zaryob.dev@gmail.com",
  176. url="https://github.com/Zaryob/inary",
  177. # package_dir = {'': ''},
  178. packages=['inary',
  179. 'inary.actionsapi',
  180. 'inary.analyzer',
  181. 'inary.cli',
  182. 'inary.data',
  183. 'inary.db',
  184. 'inary.libraries',
  185. 'inary.util',
  186. 'inary.operations',
  187. 'inary.sxml'],
  188. cmdclass={'build': Build,
  189. 'build_po': BuildPo,
  190. 'install': Install,
  191. 'test': Test},
  192. data_files=[(CONFIG_DIR, ["config/inary.conf", "config/mirrors.conf"]),
  193. (MIMEFILE_DIR, ["build/inary.xml"] if getConfig("NLS_SUPPORT") and 0 == os.system("which intltool-merge") else []),
  194. (ICONS_DIR, ["application-x-inary.svg"]),
  195. (THUMBNAILER_DIR, ["inary.thumbnailer"]),
  196. (PIXMAP_DIR, ["inary.png"])],
  197. scripts=(['inary-cli',
  198. 'scripts/pspec2po',
  199. 'scripts/revdep-rebuild',
  200. 'scripts/sulinstrapt',
  201. 'scripts/makepkg',
  202. 'scripts/mkdeb',
  203. 'scripts/revdep-rebuild-devel',
  204. 'scripts/inary-icon',
  205. 'scripts/inary-sandbox',
  206. 'scripts/inary-template',
  207. 'scripts/inarysh',
  208. 'scripts/lsinary',
  209. 'scripts/mkinary',
  210. 'scripts/detect-dep',
  211. 'scripts/detect-revdep',
  212. 'scripts/detect-file-dep',
  213. 'scripts/uninary',
  214. 'scripts/undeb',
  215. 'scripts/genpspec',
  216. 'scripts/revpspec',
  217. 'scripts/update-inary-cache',
  218. 'scripts/version-bump'] if getConfig("ADDITIONAL_SCRIPTS") else ['inary-cli']),
  219. classifiers=[
  220. 'Development Status :: 5 - Production/Stable',
  221. 'Environment :: Console',
  222. 'Environment :: Plugins',
  223. 'Framework :: Sphinx',
  224. 'Intended Audience :: End Users/Desktop',
  225. 'Intended Audience :: Developers',
  226. 'Intended Audience :: System Administrators',
  227. 'License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)',
  228. 'License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+)',
  229. 'Natural Language :: English',
  230. 'Natural Language :: Dutch',
  231. 'Natural Language :: French',
  232. 'Natural Language :: German',
  233. 'Natural Language :: Hungarian',
  234. 'Natural Language :: Italian',
  235. 'Natural Language :: Portuguese (Brazilian)',
  236. 'Natural Language :: Russian',
  237. 'Natural Language :: Slovak',
  238. 'Natural Language :: Turkish',
  239. 'Natural Language :: Ukrainian',
  240. 'Operating System :: MacOS :: MacOS X',
  241. 'Operating System :: POSIX',
  242. 'Operating System :: POSIX :: BSD',
  243. 'Programming Language :: Python :: 3 :: Only',
  244. 'Topic :: Desktop Environment',
  245. 'Topic :: System',
  246. 'Topic :: System :: Installation/Setup',
  247. 'Topic :: Software Development :: Bug Tracking',
  248. ],
  249. )
  250. # the below stuff is really nice but we already have a version
  251. # we can use this stuff for svn snapshots in a separate
  252. # script, or with a parameter I don't know -- exa
  253. INARY_VERSION = inary.__version__