3
# Copyright (c) 2010- The University of Notre Dame.
4
# This software is distributed under the GNU General Public License.
5
# See the file COPYING for details.
7
""" Weaver setup script """
9
from distutils import log
10
from distutils.core import setup
11
from distutils.cmd import Command
12
from distutils.command import install_scripts
14
from subprocess import check_call
16
from stat import ST_MODE
22
# Test Command -----------------------------------------------------------------
24
class TestCommand(Command):
26
description = 'Run test suites'
28
def initialize_options(self):
29
self.cwd = os.getcwd()
30
if not os.path.exists(os.path.join(self.cwd, 'build')):
31
os.makedirs(os.path.join(self.cwd, 'build'))
33
def finalize_options(self):
37
sfxs = [('date.sfx', '-x date'),
38
('example.sfx', '-C example.cfg')]
40
for sfx_name, sfx_args in sfxs:
41
logfile = open(os.path.join(self.cwd, 'build', sfx_name + '.log'), 'a')
42
sfx_path = os.path.join(self.cwd, 'build', sfx_name)
43
command = './starch.py %s %s' % (sfx_args, sfx_path)
45
sys.stdout.write('Starching %s ... ' % sfx_name)
47
check_call(command.split(), stderr = logfile, stdout = logfile)
48
check_call([sfx_path], stderr = logfile, stdout = logfile)
49
check_call(['env', 'SFX_KEEP=1', sfx_path], stderr = logfile, stdout = logfile)
50
check_call(['env', 'SFX_KEEP=0', sfx_path], stderr = logfile, stdout = logfile)
51
check_call(['env', 'SFX_UNIQUE=1', sfx_path], stderr = logfile, stdout = logfile)
52
except Exception as e:
53
sys.stdout.write('failure\n%s\n\n' % str(e))
57
sys.stdout.write('success\n')
60
# Script installer -------------------------------------------------------------
62
class InstallScripts(install_scripts.install_scripts):
64
if not self.skip_build:
65
self.run_command('build_scripts')
66
self.outfiles = self.copy_tree(self.build_dir, self.install_dir)
67
if os.name == 'posix':
68
for file in self.get_outputs():
70
log.info("changing mode of %s", file)
72
mode = ((os.stat(file)[ST_MODE]) | 0555) & 07777
73
log.info("changing mode of %s to %o", file, mode)
75
# Basically the same but remove .py extension
76
file_new = '.'.join(file.split('.')[:-1])
77
os.rename(file, file_new)
78
log.info("renaming %s to %s", file, file_new)
81
# Setup Configuration ----------------------------------------------------------
86
description = 'STandalone application ARCHiver',
88
author_email = 'pbui@cse.nd.edu',
89
url = 'http://bitbucket.org/pbui/starch',
90
scripts = ['starch.py'],
91
cmdclass = {'install_scripts': InstallScripts, 'test': TestCommand}
94
# vim: sts=4 sw=4 ts=8 expandtab ft=python