Bug 1009004 - Re-implement INSTALL.sh script as a python script. r=hskupin DONTBUILD

This commit is contained in:
Cosmin Malutan 2014-06-03 18:10:01 +02:00
Родитель aa5043728d
Коммит b1328768a6
3 изменённых файлов: 122 добавлений и 103 удалений

Просмотреть файл

@ -1,99 +0,0 @@
#!/bin/bash
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# This scripts sets up a virutalenv and installs TPS into it.
# It's probably best to specify a path NOT inside the repo, otherwise
# all the virtualenv files will show up in e.g. hg status.
# get target directory
if [ ! -z "$1" ]
then
TARGET=$1
else
echo "Usage: INSTALL.sh /path/to/create/virtualenv [/path/to/python2.6]"
exit 1
fi
# decide which python to use
if [ ! -z "$2" ]
then
PYTHON=$2
else
PYTHON=`which python`
fi
if [ -z "${PYTHON}" ]
then
echo "No python found"
exit 1
fi
CWD="`pwd`"
# create the destination directory
mkdir ${TARGET}
if [ "$?" -gt 0 ]
then
exit 1
fi
if [ "${OS}" = "Windows_NT" ]
then
BIN_NAME=Scripts/activate
else
BIN_NAME=bin/activate
fi
# Create a virtualenv:
curl -L https://raw.github.com/pypa/virtualenv/1.9.1/virtualenv.py | ${PYTHON} - ${TARGET}
cd ${TARGET}
. $BIN_NAME
if [ -z "${VIRTUAL_ENV}" ]
then
echo "virtualenv wasn't installed correctly, aborting"
exit 1
fi
# install TPS
cd ${CWD}
python setup.py install
# clean up files created by setup.py
rm -rf build/
rm -rf dist/
rm -rf tps.egg-info/
if [ "$?" -gt 0 ]
then
exit 1
fi
CONFIG="`find ${VIRTUAL_ENV} -name config.json.in`"
NEWCONFIG=${CONFIG:0:${#CONFIG}-3}
cd "../../services/sync/tests/tps"
TESTDIR="`pwd`"
cd "../../tps/extensions"
EXTDIR="`pwd`"
sed 's|__TESTDIR__|'"${TESTDIR}"'|' "${CONFIG}" | sed 's|__EXTENSIONDIR__|'"${EXTDIR}"'|' > "${NEWCONFIG}"
rm ${CONFIG}
echo
echo "***********************************************************************"
echo
echo "To run TPS, activate the virtualenv using:"
echo " source ${TARGET}/${BIN_NAME}"
echo "then execute tps using:"
echo " runtps --binary=/path/to/firefox"
echo
echo "See runtps --help for all options"
echo
echo "To change your TPS config, please edit the file: "
echo "${NEWCONFIG}"
echo
echo "***********************************************************************"

116
testing/tps/create_venv.py Executable file
Просмотреть файл

@ -0,0 +1,116 @@
#!/usr/bin/env python
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
"""
This scripts sets up a virtualenv and installs TPS into it.
It's probably best to specify a path NOT inside the repo, otherwise
all the virtualenv files will show up in e.g. hg status.
"""
import optparse
import os
import shutil
import subprocess
import sys
import urllib
here = os.path.dirname(os.path.abspath(__file__))
usage_message = """
***********************************************************************
To run TPS, activate the virtualenv using:
source {TARGET}/{BIN_NAME}
To change your TPS config, please edit the file:
{TARGET}/config.json
To execute tps use:
runtps --binary=/path/to/firefox
See runtps --help for all options
***********************************************************************
"""
virtualenv_url = 'https://raw.github.com/pypa/virtualenv/1.9.1/virtualenv.py'
if sys.platform == 'win32':
bin_name = os.path.join('Scripts', 'activate.bat')
activate_env = os.path.join('Scripts', 'activate_this.py')
else:
bin_name = os.path.join('bin', 'activate')
activate_env = os.path.join('bin', 'activate_this.py')
def main():
parser = optparse.OptionParser('Usage: %prog [options] path_to_venv')
parser.add_option('-p', '--python',
type='string',
dest='python',
metavar='PYTHON_BIN',
default=None,
help='The Python interpreter to use.')
(options, args) = parser.parse_args(args=None, values=None)
if len(args) != 1:
parser.error('Path to the environment has to be specified')
target = args[0]
assert(target)
# Create a virtual environment
urllib.urlretrieve(virtualenv_url, 'virtualenv.py')
cmd_args = [sys.executable, 'virtualenv.py', target]
if options.python:
cmd_args.extend(['-p', options.python])
subprocess.check_call(cmd_args)
# Activate tps environment
tps_env = os.path.join(target, activate_env)
execfile(tps_env, dict(__file__=tps_env))
# Install TPS in environment
subprocess.check_call(['python', os.path.join(here, 'setup.py'),
'install'])
# Get the path to tests and extensions directory by checking check where
# the tests and extensions directories are located
sync_dir = os.path.abspath(os.path.join(here, '..', '..', 'services',
'sync'))
if os.path.exists(sync_dir):
testdir = os.path.join(sync_dir, 'tests', 'tps')
extdir = os.path.join(sync_dir, 'tps', 'extensions')
else:
testdir = os.path.join(here, 'tests')
extdir = os.path.join(here, 'extensions')
assert(os.path.exists(testdir))
assert(os.path.exists(extdir))
# Update config file
config_in_path = os.path.join(here, 'config', 'config.json.in')
replacements = {'__TESTDIR__': testdir, '__EXTENSIONDIR__': extdir}
lines = []
with open(config_in_path) as config:
for line in config:
for source_string, target_string in replacements.iteritems():
line = line.replace(source_string, target_string)
lines.append(line)
with open(os.path.join(target, 'config.json'), 'w') as config:
for line in lines:
config.write(line)
# Clean up files created by setup.py
shutil.rmtree(os.path.join(here, 'build'))
shutil.rmtree(os.path.join(here, 'dist'))
shutil.rmtree(os.path.join(here, 'tps.egg-info'))
os.remove(os.path.join(here, 'virtualenv.py'))
os.remove(os.path.join(here, 'virtualenv.pyc'))
# Print the user instructions
print usage_message.format(TARGET=target,
BIN_NAME=bin_name)
if __name__ == "__main__":
main()

Просмотреть файл

@ -67,14 +67,15 @@ def main():
action='store',
type='string',
dest='testfile',
default='../../services/sync/tests/tps/all_tests.json',
default='all_tests.json',
help='path to the test file to run [default: %default]')
(options, args) = parser.parse_args()
configfile = options.configfile
if configfile is None:
if os.environ.get('VIRTUAL_ENV'):
configfile = os.path.join(os.path.dirname(__file__), 'config.json')
virtual_env = os.environ.get('VIRTUAL_ENV')
if virtual_env:
configfile = os.path.join(virtual_env, 'config.json')
if configfile is None or not os.access(configfile, os.F_OK):
raise Exception('Unable to find config.json in a VIRTUAL_ENV; you must '
'specify a config file using the --configfile option')
@ -84,6 +85,7 @@ def main():
configcontent = f.read()
f.close()
config = json.loads(configcontent)
testfile = os.path.join(config.get('testdir', ''), options.testfile)
rlock = RLock()
@ -110,7 +112,7 @@ def main():
mobile=options.mobile,
resultfile=options.resultfile,
rlock=rlock,
testfile=options.testfile,
testfile=testfile,
)
TPS.run_tests()