3 import glob, os, os.path, re, sys
5 from distutils.command.build import build as _build
6 from distutils.command.clean import clean as _clean
7 from distutils.command.install import install as _install
8 from setuptools.command.test import test as _test
9 from distutils.core import setup
10 from distutils.dir_util import remove_tree
11 from setuptools import find_packages
12 from subprocess import check_call, check_output
16 return glob.glob("locale/*/*/*.po")
19 def message_catalog (translation):
20 return os.path.splitext (os.path.basename (translation))[0] + ".mo"
23 def message_catalogs ():
24 return [os.path.join (os.path.dirname (translation), message_catalog (translation)) for translation in translations ()]
28 user_options = [("pytest-args=", "a", "Arguments to pass to py.test")]
30 def initialize_options (self):
31 _test.initialize_options (self)
35 def finalize_options (self):
36 _test.finalize_options (self)
39 self.test_suite = True
42 _test.run_tests (self)
44 # import here, cause outside the eggs aren't loaded
46 sys.exit (pytest.main (self.pytest_args))
53 def update_version ():
54 with open (os.path.join (self.build_scripts, "crypto-install"), "r+") as file:
56 data = re.sub ("GIT-TAG", check_output (["git", "describe", "--abbrev=0", "--tags"]).strip (), data)
57 data = re.sub ("GIT-COMMIT", check_output (["git", "rev-parse", "--short=7", "HEAD"]).strip (), data)
58 data = re.sub ("GIT-BRANCH", check_output (["git", "rev-parse", "--abbrev-ref", "HEAD"]).strip (), data)
62 self.execute (update_version, [], "Updating version")
64 def compile_message_catalog (translation, output):
65 check_call (["msgfmt", "-o", os.path.join (output, message_catalog (translation)), translation])
67 for translation in translations ():
68 output = os.path.join (self.build_base, os.path.dirname (translation))
72 self.execute (compile_message_catalog, [translation, output], "Compiling message catalog {}".format (translation))
75 class install (_install):
79 self.copy_tree (os.path.join (self.build_base, "locale"),
80 os.path.join (self.install_data, "share/locale"))
87 if os.path.exists (self.build_base):
88 remove_tree (self.build_base, dry_run = self.dry_run)
92 name = "crypto_install",
94 author = "Olof-Joachim Frahm",
95 author_email = "olof@macrolet.net",
96 url = "https://github.com/Ferada/crypto-install",
97 scripts = ["crypto-install"],
98 install_requires = [],
99 tests_require = ["pytest"],
107 "Development Status :: 3 - Alpha",
108 "Environment :: Console",
109 "Environment :: X11 Applications",
110 "Intended Audience :: End Users/Desktop",
111 "License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)",
112 "Natural Language :: English",
113 "Natural Language :: German",
114 "Operating System :: POSIX",
115 "Programming Language :: Python :: 2.7",
116 "Programming Language :: Python :: 3.2",
117 "Topic :: Security :: Cryptography",