Back to index

apport  2.4
setup.py
Go to the documentation of this file.
00001 #!/usr/bin/python
00002 
00003 from glob import glob
00004 import os.path, shutil, sys, subprocess
00005 from distutils.version import StrictVersion
00006 import distutils.core
00007 import distutils.command.build
00008 import distutils.command.clean
00009 
00010 try:
00011     import DistUtilsExtra.auto
00012 except ImportError:
00013     sys.stderr.write('To build Apport you need https://launchpad.net/python-distutils-extra\n')
00014     sys.exit(1)
00015 
00016 assert StrictVersion(DistUtilsExtra.auto.__version__) >= '2.24', 'needs DistUtilsExtra.auto >= 2.24'
00017 
00018 
00019 class build_java_subdir(distutils.core.Command):
00020     '''Java crash handler build command'''
00021 
00022     description = 'Compile java components of Apport'
00023     user_options = []
00024 
00025     def initialize_options(self):
00026         pass
00027 
00028     def finalize_options(self):
00029         pass
00030 
00031     def run(self):
00032         oldwd = os.getcwd()
00033         os.chdir('java')
00034 
00035         subprocess.check_call(['javac'] + glob('com/ubuntu/apport/*.java'))
00036         subprocess.check_call(['jar', 'cvf', 'apport.jar'] +
00037                               glob('com/ubuntu/apport/*.class'))
00038         subprocess.check_call(['javac', 'crash.java'])
00039         subprocess.check_call(['jar', 'cvf', 'crash.jar', 'crash.class'])
00040 
00041         os.chdir(oldwd)
00042 
00043 
00044 class clean_java_subdir(DistUtilsExtra.auto.clean_build_tree):
00045     '''Java crash handler clean command'''
00046 
00047     def run(self):
00048         DistUtilsExtra.auto.clean_build_tree.run(self)
00049         for (root, dirs, files) in os.walk('java'):
00050             for f in files:
00051                 if f.endswith('.jar') or f.endswith('.class'):
00052                     os.unlink(os.path.join(root, f))
00053 
00054 
00055 class install_fix_hashbangs(DistUtilsExtra.auto.install_auto):
00056     '''Fix hashbang lines in scripts in data dir.'''
00057 
00058     def run(self):
00059         DistUtilsExtra.auto.install_auto.run(self)
00060         new_hashbang = '#!%s\n' % sys.executable.rsplit('.', 1)[0]
00061         for (path, _, files) in os.walk(os.path.join(self.install_data, 'share', 'apport')):
00062             for fname in files:
00063                 f = os.path.join(path, fname)
00064                 with open(f) as fd:
00065                     try:
00066                         lines = fd.readlines()
00067                     except UnicodeDecodeError:
00068                         # ignore data files like spinner.gif
00069                         continue
00070                 if lines[0].startswith('#!') and 'python' in lines[0]:
00071                     distutils.log.info('Updating hashbang of %s', f)
00072                     lines[0] = new_hashbang
00073                     with open(f, 'w') as fd:
00074                         for l in lines:
00075                             fd.write(l)
00076 
00077 #
00078 # main
00079 #
00080 
00081 # try to auto-setup packaging_impl
00082 if len(sys.argv) >= 2 and sys.argv[1] != 'sdist' and not os.path.exists('apport/packaging_impl.py'):
00083     if os.path.exists('/etc/apt/sources.list'):
00084         print('Installing apt/dpkg packaging backend.')
00085         shutil.copy('backends/packaging-apt-dpkg.py', 'apport/packaging_impl.py')
00086     elif os.path.exists('/usr/bin/rpm'):
00087         print('Installing RPM packaging backend.')
00088         shutil.copy('backends/packaging_rpm.py', 'apport/packaging_impl.py')
00089     else:
00090         print('Could not determine system package manager. Copy appropriate backends/packaging* to apport/packaging_impl.py')
00091         sys.exit(1)
00092 
00093 optional_data_files = []
00094 cmdclass = {}
00095 
00096 # if we have Java available, build the Java crash handler
00097 try:
00098     subprocess.check_call(['javac', '-version'], stderr=subprocess.PIPE)
00099 
00100     distutils.command.build.build.sub_commands.append(('build_java_subdir', None))
00101     optional_data_files.append(('share/java', ['java/apport.jar']))
00102     cmdclass['build_java_subdir'] = build_java_subdir
00103     cmdclass['install'] = install_fix_hashbangs
00104     cmdclass['clean'] = clean_java_subdir
00105     print('Java support: Enabled')
00106 except (OSError, subprocess.CalledProcessError):
00107     print('Java support: Java not available, not building Java crash handler')
00108 
00109 from apport.ui import __version__
00110 
00111 DistUtilsExtra.auto.setup(
00112     name='apport',
00113     author='Martin Pitt',
00114     author_email='martin.pitt@ubuntu.com',
00115     url='https://launchpad.net/apport',
00116     license='gpl',
00117     description='intercept, process, and report crashes and bug reports',
00118     version=__version__,
00119 
00120     data_files=[('share/mime/packages', glob('xdg-mime/*')),
00121                 # these are not supposed to be called directly, use apport-bug instead
00122                 ('share/apport', ['gtk/apport-gtk', 'kde/apport-kde']),
00123                 ('share/apport/testsuite/', glob('test/*')),
00124                 ('share/doc/apport/', glob('doc/*.txt')),
00125                 ('lib/pm-utils/sleep.d/', glob('pm-utils/sleep.d/*')),
00126                 ] + optional_data_files,
00127     cmdclass=cmdclass
00128 )