Back to index

obnam  1.1
setup.py
Go to the documentation of this file.
00001 #!/usr/bin/python
00002 # Copyright (C) 2008-2012  Lars Wirzenius <liw@liw.fi>
00003 #
00004 # This program is free software; you can redistribute it and/or modify
00005 # it under the terms of the GNU General Public License as published by
00006 # the Free Software Foundation; either version 3 of the License, or
00007 # (at your option) any later version.
00008 #
00009 # This program is distributed in the hope that it will be useful,
00010 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 # GNU General Public License for more details.
00013 #
00014 # You should have received a copy of the GNU General Public License along
00015 # with this program; if not, write to the Free Software Foundation, Inc.,
00016 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00017 
00018 from distutils.core import setup, Extension
00019 from distutils.cmd import Command
00020 from distutils.command.build import build
00021 from distutils.command.clean import clean
00022 import glob
00023 import os
00024 import shutil
00025 import subprocess
00026 import sys
00027 import tempfile
00028 
00029 
00030 def runcmd(*args, **kwargs):
00031     try:
00032         subprocess.check_call(*args, **kwargs)
00033     except subprocess.CalledProcessError, e:
00034         sys.stderr.write('ERROR: %s\n' % str(e))
00035         sys.exit(1)
00036 
00037 
00038 class GenerateManpage(build):
00039 
00040     def run(self):
00041         build.run(self)
00042         print 'building manpages'
00043         for x in ['obnam', 'obnam-benchmark']:
00044             with open('%s.1' % x, 'w') as f:
00045                 runcmd(['python', x, '--generate-manpage=%s.1.in' % x, 
00046                         '--output=%s.1' % x], stdout=f)
00047 
00048 
00049 class CleanMore(clean):
00050 
00051     def run(self):
00052         clean.run(self)
00053         for x in ['obnam.1', 'obnam-benchmark.1', '.coverage',
00054                   'obnamlib/_obnam.so']:
00055             if os.path.exists(x):
00056                 os.remove(x)
00057         self.remove_pyc('obnamlib')
00058         self.remove_pyc('test-plugins')
00059         if os.path.isdir('build'):
00060             shutil.rmtree('build')
00061         
00062     def remove_pyc(self, rootdir):
00063         for dirname, subdirs, basenames in os.walk(rootdir):
00064             for x in [os.path.join(dirname, base)
00065                        for base in basenames
00066                        if base.endswith('.pyc')]:
00067                 os.remove(x)
00068 
00069 class Check(Command):
00070 
00071     user_options = [
00072         ('fast', 'f', 'run fast tests only?'),
00073         ('network', 'n', 'run network tests to localhost?'),
00074         ('network-only', 'N', 'only run network tests to localhost?'),
00075     ]
00076 
00077     def initialize_options(self):
00078         self.fast = False
00079         self.network = False
00080         self.network_only = False
00081 
00082     def finalize_options(self):
00083         pass
00084 
00085     def run(self):
00086         local = not self.network_only
00087         network = self.network or self.network_only
00088         fast = self.fast
00089         slow = not self.fast
00090 
00091         if local and fast:
00092             print "run unit tests"
00093             runcmd(['python', '-m', 'CoverageTestRunner',
00094                     '--ignore-missing-from=without-tests'])
00095             os.remove('.coverage')
00096 
00097         if local and fast:
00098             print "run black box tests"
00099             runcmd(['cmdtest', 'tests'])
00100 
00101         num_clients = '2'
00102         num_generations = '16'
00103 
00104         if local and slow:
00105             print "run locking tests"
00106             test_repo = tempfile.mkdtemp()
00107             runcmd(['./test-locking', num_clients, 
00108                     num_generations, test_repo, test_repo])
00109             shutil.rmtree(test_repo)
00110 
00111         if local and slow:
00112             print "run crash test"
00113             runcmd(['./crash-test', '200'])
00114 
00115         if network and fast:
00116             print "run sftp tests"
00117             runcmd(['./test-sftpfs'])
00118 
00119         if network and fast:
00120             print "re-run black box tests using localhost networking"
00121             env = dict(os.environ)
00122             env['OBNAM_TEST_SFTP_ROOT'] = 'yes'
00123             env['OBNAM_TEST_SFTP_REPOSITORY'] = 'yes'
00124             runcmd(['cmdtest', 'tests'], env=env)
00125 
00126         if network and slow:
00127             print "re-run locking tests using localhost networking"
00128             test_repo = tempfile.mkdtemp()
00129             repo_url = 'sftp://localhost/%s' % test_repo
00130             runcmd(['./test-locking', num_clients, 
00131                     num_generations, repo_url, test_repo])
00132             shutil.rmtree(test_repo)
00133             
00134         print "setup.py check done"
00135 
00136 
00137 setup(name='obnam',
00138       version='1.1',
00139       description='Backup software',
00140       author='Lars Wirzenius',
00141       author_email='liw@liw.fi',
00142       url='http://liw.fi/obnam/',
00143       scripts=['obnam', 'obnam-benchmark', 'obnam-viewprof'],
00144       packages=['obnamlib', 'obnamlib.plugins'],
00145       ext_modules=[Extension('obnamlib._obnam', sources=['_obnammodule.c'])],
00146       data_files=[('share/man/man1', glob.glob('*.1'))],
00147       cmdclass={
00148         'build': GenerateManpage,
00149         'check': Check,
00150         'clean': CleanMore,
00151       },
00152      )