Advertisement
mixster

Untitled

Sep 19th, 2011
541
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.85 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. from __future__ import print_function
  4.  
  5.  
  6. import re
  7. import sys
  8. import distutils
  9. from distutils import core, log
  10. from glob import glob
  11.  
  12. import os
  13. import io
  14.  
  15. sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'pym'))
  16.  
  17. __version__ = os.getenv('VERSION', default='9999')
  18.  
  19. cwd = os.getcwd()
  20.  
  21. # Load EPREFIX from Portage, fall back to the empty string if it fails
  22. try:
  23. from portage.const import EPREFIX
  24. except ImportError:
  25. EPREFIX='/'
  26.  
  27.  
  28. # Bash files that need `VERSION=""` subbed, relative to this dir:
  29. bash_scripts = [os.path.join(cwd, path) for path in (
  30. 'bin/euse',
  31. 'bin/revdep-rebuild'
  32. )]
  33.  
  34. # Python files that need `__version__ = ""` subbed, relative to this dir:
  35. python_scripts = [os.path.join(cwd, path) for path in (
  36. 'bin/eclean',
  37. 'bin/epkginfo',
  38. 'bin/glsa-check',
  39. 'pym/gentoolkit/eclean/cli.py',
  40. 'pym/gentoolkit/enalyze/__init__.py',
  41. 'pym/gentoolkit/equery/__init__.py',
  42. 'pym/gentoolkit/eshowkw/__init__.py'
  43. )]
  44. class set_version(core.Command):
  45. """Set python __version__ and bash VERSION to our __version__."""
  46. description = "hardcode scripts' version using VERSION from environment"
  47. user_options = [] # [(long_name, short_name, desc),]
  48.  
  49. def initialize_options (self):
  50. pass
  51.  
  52. def finalize_options (self):
  53. pass
  54.  
  55. def run(self):
  56. ver = 'svn' if __version__ == '9999' else __version__
  57. print("Settings version to %s" % ver)
  58. def sub(files, pattern):
  59. for f in files:
  60. updated_file = []
  61. with io.open(f, 'r', 1, 'utf_8') as s:
  62. for line in s:
  63. newline = re.sub(pattern, '"%s"' % ver, line, 1)
  64. if newline != line:
  65. log.info("%s: %s" % (f, newline))
  66. updated_file.append(newline)
  67. with io.open(f, 'w', 1, 'utf_8') as s:
  68. s.writelines(updated_file)
  69. quote = r'[\'"]{1}'
  70. bash_re = r'(?<=VERSION=)' + quote + '[^\'"]*' + quote
  71. sub(bash_scripts, bash_re)
  72. python_re = r'(?<=^__version__ = )' + quote + '[^\'"]*' + quote
  73. sub(python_scripts, python_re)
  74.  
  75.  
  76. def load_test():
  77. """Only return the real test class if it's actually being run so that we
  78. don't depend on snakeoil just to install."""
  79.  
  80. desc = "run the test suite"
  81. if 'test' in sys.argv[1:]:
  82. try:
  83. from snakeoil import distutils_extensions
  84. except ImportError:
  85. sys.stderr.write("Error: We depend on dev-python/snakeoil ")
  86. sys.stderr.write("to run tests.\n")
  87. sys.exit(1)
  88. class test(distutils_extensions.test):
  89. description = desc
  90. default_test_namespace = 'gentoolkit.test'
  91. else:
  92. class test(core.Command):
  93. description = desc
  94.  
  95. return test
  96.  
  97. packages = [
  98. str('.'.join(root.split(os.sep)[1:]))
  99. for root, dirs, files in os.walk('pym/gentoolkit')
  100. if '__init__.py' in files
  101. ]
  102.  
  103. test_data = {
  104. 'gentoolkit': [
  105. 'test/eclean/Packages',
  106. 'test/eclean/testdistfiles.tar.gz',
  107. 'test/eclean/distfiles.exclude'
  108. ]
  109. }
  110.  
  111. core.setup(
  112. name='gentoolkit',
  113. version=__version__,
  114. description='Set of tools that work with and enhance portage.',
  115. author='',
  116. author_email='',
  117. maintainer='Gentoo Portage Tools Team',
  118. maintainer_email='tools-portage@gentoo.org',
  119. url='http://www.gentoo.org/proj/en/portage/tools/index.xml',
  120. download_url='http://distfiles.gentoo.org/distfiles/gentoolkit-%s.tar.gz'\
  121. % __version__,
  122. package_dir={'': 'pym'},
  123. packages=packages,
  124. package_data = test_data,
  125. scripts=(glob('bin/*')),
  126. data_files=(
  127. (os.path.join(EPREFIX, 'etc/env.d'), ['data/99gentoolkit-env']),
  128. (os.path.join(EPREFIX, 'etc/revdep-rebuild'), ['data/revdep-rebuild/99revdep-rebuild']),
  129. (os.path.join(EPREFIX, 'etc/eclean'), glob('data/eclean/*')),
  130. (os.path.join(EPREFIX, 'usr/share/man/man1'), glob('man/*')),
  131. ),
  132. cmdclass={
  133. 'test': load_test(),
  134. 'set_version': set_version,
  135. },
  136. )
  137.  
  138. # vim: set ts=4 sw=4 tw=79:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement