Skip to content

Commit

Permalink
Merge pull request #267 from matthew-brett/build-dmgs-script
Browse files Browse the repository at this point in the history
NF: add script to build dmg files from buildbots

The buildbots build mpkgs; this script builds dmgs from the mpkgs and
sets the permissions correctly.
  • Loading branch information
matthew-brett committed May 2, 2013
2 parents cfc99f8 + 86bb1b2 commit 343b8cf
Show file tree
Hide file tree
Showing 2 changed files with 130 additions and 0 deletions.
69 changes: 69 additions & 0 deletions tools/build_dmgs.py
@@ -0,0 +1,69 @@
#!/usr/bin/env python
"""Script to build dmgs for buildbot builds
Example
-------
%(prog)s "nipy-dist/nipy*-0.4.0-py*mpkg"
Note quotes around the globber first argument to protect it from shell
globbing.
"""
import os
from os.path import join as pjoin, isfile, isdir
import shutil
from glob import glob
from functools import partial
from subprocess import check_call
import warnings

from argparse import ArgumentParser, RawDescriptionHelpFormatter

my_call = partial(check_call, shell=True)

BUILDBOT_LOGIN = "buildbot@nipy.bic.berkeley.edu"
BUILDBOT_HTML = "nibotmi/public_html/"

def main():
parser = ArgumentParser(description=__doc__,
formatter_class=RawDescriptionHelpFormatter)
parser.add_argument('globber', type=str,
help='glob to search for build mpkgs')
parser.add_argument('--out-path', type=str, default='mpkg-dist',
help='path for output files (default="mpkg-dist")',
metavar='OUTPATH')
parser.add_argument('--clobber', action='store_true',
help='Delete OUTPATH if exists')
args = parser.parse_args()
globber = args.globber
out_path = args.out_path
address = "{0}:{1}{2}".format(BUILDBOT_LOGIN, BUILDBOT_HTML, globber)
if isdir(out_path):
if not args.clobber:
raise RuntimeError('Path {0} exists and "clobber" not set'.format(
out_path))
shutil.rmtree(out_path)
os.mkdir(out_path)
cwd = os.path.abspath(os.getcwd())
os.chdir(out_path)
try:
my_call('scp -r {0} .'.format(address))
found_mpkgs = sorted(glob('*.mpkg'))
for mpkg in found_mpkgs:
pkg_name, ext = os.path.splitext(mpkg)
assert ext == '.mpkg'
my_call('sudo reown_mpkg {0} root admin'.format(mpkg))
os.mkdir(pkg_name)
pkg_moved = pjoin(pkg_name, mpkg)
os.rename(mpkg, pkg_moved)
readme = pjoin(pkg_moved, 'Contents', 'Resources', 'ReadMe.txt')
if isfile(readme):
shutil.copy(readme, pkg_name)
else:
warnings.warn("Could not find readme with " + readme)
my_call('sudo hdiutil create {0}.dmg -srcfolder ./{0}/ -ov'.format(pkg_name))
finally:
os.chdir(cwd)


if __name__ == '__main__':
main()
61 changes: 61 additions & 0 deletions tools/doctest_extmods.py
@@ -0,0 +1,61 @@
#!/usr/bin/env python
"""Run doctests in extension modules of <pkg_name>
Collect extension modules in <pkg_name>
Run doctests in each extension module
Example:
%prog nipy
"""

import sys
import os
from os.path import dirname, relpath, sep, join as pjoin, splitext, abspath

from distutils.sysconfig import get_config_vars

import doctest
from optparse import OptionParser

EXT_EXT = get_config_vars('SO')[0]


def get_ext_modules(pkg_name):
pkg = __import__(pkg_name, fromlist=[''])
pkg_dir = abspath(dirname(pkg.__file__))
# pkg_root = __import__(pkg_name)
ext_modules = []
for dirpath, dirnames, filenames in os.walk(pkg_dir):
reldir = relpath(dirpath, pkg_dir)
if reldir == '.':
reldir = ''
for filename in filenames:
froot, ext = splitext(filename)
if ext == EXT_EXT:
mod_path = pjoin(reldir, froot)
mod_uri = pkg_name + '.' + mod_path.replace(sep, '.')
# fromlist=[''] results in submodule being returned, rather than the
# top level module. See help(__import__)
mod = __import__(mod_uri, fromlist=[''])
ext_modules.append(mod)
return ext_modules


def main():
usage = "usage: %prog [options] <pkg_name>\n\n" + __doc__
parser = OptionParser(usage=usage)
opts, args = parser.parse_args()
if len(args) == 0:
parser.print_help()
sys.exit(1)
mod_name = args[0]
mods = get_ext_modules(mod_name)
for mod in mods:
print("Testing module: " + mod.__name__)
doctest.testmod(mod)


if __name__ == '__main__':
main()

0 comments on commit 343b8cf

Please sign in to comment.