| 1 |
#!/usr/bin/env python |
| 2 |
# -*- coding: utf-8 -*- |
| 3 |
# Copyright (c) 2013-2014 Spotify AB |
| 4 |
|
| 5 |
# This file is part of dh-virtualenv. |
| 6 |
|
| 7 |
# dh-virtualenv is free software: you can redistribute it and/or |
| 8 |
# modify it under the terms of the GNU General Public License as |
| 9 |
# published by the Free Software Foundation, either version 2 of the |
| 10 |
# License, or (at your option) any later version. |
| 11 |
|
| 12 |
# dh-virtualenv is distributed in the hope that it will be useful, but |
| 13 |
# WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 |
# General Public License for more details. |
| 16 |
|
| 17 |
# You should have received a copy of the GNU General Public License |
| 18 |
# along with dh-virtualenv. If not, see |
| 19 |
# <http://www.gnu.org/licenses/>. |
| 20 |
|
| 21 |
import inspect |
| 22 |
import logging |
| 23 |
import os |
| 24 |
import sys |
| 25 |
|
| 26 |
from dh_virtualenv import Deployment |
| 27 |
from dh_virtualenv.cmdline import get_default_parser |
| 28 |
from dh_virtualenv.debhelper import DebHelper |
| 29 |
|
| 30 |
logging.basicConfig(format='%(levelname).1s: %(module)s:%(lineno)d: ' |
| 31 |
'%(message)s') |
| 32 |
log = logging.getLogger(__name__) |
| 33 |
|
| 34 |
|
| 35 |
def _shell_vars(**kwargs): |
| 36 |
"""Convert the given values into the equivalent shell snippet defining them.""" |
| 37 |
return '\n'.join("dh_venv_{0}='{1}'".format(k, v.replace("'", r"'\''")) |
| 38 |
for k, v in sorted(kwargs.items())) |
| 39 |
|
| 40 |
|
| 41 |
def main(): |
| 42 |
parser = get_default_parser() |
| 43 |
options, args = parser.parse_args() |
| 44 |
options.compile_all = False # for DebHelper.save() |
| 45 |
|
| 46 |
# TODO: Reduce redundancy with this and the Deployment.from_options |
| 47 |
verbose = options.verbose or os.environ.get('DH_VERBOSE') == '1' |
| 48 |
if verbose: |
| 49 |
log.setLevel(logging.DEBUG) |
| 50 |
|
| 51 |
if 'nocheck' in os.environ.get('DEB_BUILD_OPTIONS', ''): |
| 52 |
do_test = False |
| 53 |
else: |
| 54 |
do_test = options.setuptools_test |
| 55 |
|
| 56 |
# Older DebHelpers, like the one on Debian Squeeze, expect to be |
| 57 |
# passed the packages keyword argument. Newer (like Ubuntu |
| 58 |
# Precise) expect the whole options to be passed. |
| 59 |
|
| 60 |
arguments = inspect.getargspec(DebHelper.__init__).args |
| 61 |
if 'packages' in arguments: |
| 62 |
dh = DebHelper(packages=options.package or None) |
| 63 |
else: |
| 64 |
dh = DebHelper(options) |
| 65 |
if hasattr(sys, 'real_prefix'): |
| 66 |
log.error('Already in a virtualenv. This is likely to generate an ' |
| 67 |
'invalid package (run "deactivate" first?)') |
| 68 |
return 1 |
| 69 |
for package, details in dh.packages.items(): |
| 70 |
def _info(msg): |
| 71 |
log.info('{0}: {1}'.format(package, msg)) |
| 72 |
|
| 73 |
_info('Processing package...') |
| 74 |
deploy = Deployment.from_options(package, options) |
| 75 |
|
| 76 |
if options.autoscripts: |
| 77 |
_info('Adding autoscripts...') |
| 78 |
dh.autoscript(package, 'postinst', 'postinst-dh-virtualenv', _shell_vars( |
| 79 |
package=package, |
| 80 |
install_dir=deploy.virtualenv_install_dir, |
| 81 |
)) |
| 82 |
dh.autoscript(package, 'prerm', 'prerm-dh-virtualenv', _shell_vars( |
| 83 |
package=package, |
| 84 |
install_dir=deploy.virtualenv_install_dir, |
| 85 |
)) |
| 86 |
|
| 87 |
_info('Creating virtualenv') |
| 88 |
deploy.create_virtualenv() |
| 89 |
|
| 90 |
_info('Installing dependencies') |
| 91 |
deploy.install_dependencies() |
| 92 |
|
| 93 |
_info('Installing package') |
| 94 |
deploy.install_package() |
| 95 |
if do_test: |
| 96 |
_info('Running tests') |
| 97 |
deploy.run_tests() |
| 98 |
else: |
| 99 |
_info('Skipped tests') |
| 100 |
|
| 101 |
_info('Fixing paths') |
| 102 |
deploy.fix_activate_path() |
| 103 |
deploy.fix_shebangs() |
| 104 |
deploy.fix_local_symlinks() |
| 105 |
|
| 106 |
_info('dh-virtualenv: All done!') |
| 107 |
|
| 108 |
dh.save() |
| 109 |
|
| 110 |
if __name__ == '__main__': |
| 111 |
sys.exit(main() or 0) |