~ubuntu-branches/ubuntu/vivid/cctools/vivid

« back to all changes in this revision

Viewing changes to python/starch/setup.py

  • Committer: Bazaar Package Importer
  • Author(s): Michael Hanke
  • Date: 2011-05-07 09:05:00 UTC
  • Revision ID: james.westby@ubuntu.com-20110507090500-lqpmdtwndor6e7os
Tags: upstream-3.3.2
ImportĀ upstreamĀ versionĀ 3.3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python2
 
2
 
 
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.
 
6
 
 
7
""" Weaver setup script """
 
8
 
 
9
from distutils         import log
 
10
from distutils.core    import setup
 
11
from distutils.cmd     import Command
 
12
from distutils.command import install_scripts
 
13
 
 
14
from subprocess import check_call
 
15
 
 
16
from stat import ST_MODE
 
17
 
 
18
import os
 
19
import sys
 
20
 
 
21
 
 
22
# Test Command -----------------------------------------------------------------
 
23
 
 
24
class TestCommand(Command):
 
25
    user_options = []
 
26
    description  = 'Run test suites'
 
27
 
 
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'))
 
32
 
 
33
    def finalize_options(self):
 
34
        pass
 
35
 
 
36
    def run(self):
 
37
        sfxs = [('date.sfx', '-x date'),
 
38
                ('example.sfx', '-C example.cfg')]
 
39
 
 
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)
 
44
            try:
 
45
                sys.stdout.write('Starching %s ... ' % sfx_name)
 
46
                sys.stdout.flush()
 
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))
 
54
                continue
 
55
            finally:
 
56
                logfile.close()
 
57
            sys.stdout.write('success\n')
 
58
 
 
59
 
 
60
# Script installer -------------------------------------------------------------
 
61
 
 
62
class InstallScripts(install_scripts.install_scripts):
 
63
    def run(self):
 
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():
 
69
                if self.dry_run:
 
70
                    log.info("changing mode of %s", file)
 
71
                else:
 
72
                    mode = ((os.stat(file)[ST_MODE]) | 0555) & 07777
 
73
                    log.info("changing mode of %s to %o", file, mode)
 
74
                    os.chmod(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)
 
79
 
 
80
 
 
81
# Setup Configuration ----------------------------------------------------------
 
82
 
 
83
setup(
 
84
    name         = 'Starch',
 
85
    version      = '0.0.2',
 
86
    description  = 'STandalone application ARCHiver',
 
87
    author       = 'Peter Bui',
 
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}
 
92
)
 
93
 
 
94
# vim: sts=4 sw=4 ts=8 expandtab ft=python