0
|
1 |
#
|
|
2 |
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
# All rights reserved.
|
|
4 |
# This component and the accompanying materials are made available
|
|
5 |
# under the terms of "Eclipse Public License v1.0"
|
|
6 |
# which accompanies this distribution, and is available
|
|
7 |
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
#
|
|
9 |
# Initial Contributors:
|
|
10 |
# Nokia Corporation - initial contribution.
|
|
11 |
#
|
|
12 |
# Contributors:
|
|
13 |
#
|
|
14 |
# Description:
|
|
15 |
#
|
|
16 |
|
|
17 |
import sys, os, shutil, imp
|
|
18 |
import logging
|
|
19 |
from optparse import OptionParser
|
|
20 |
|
|
21 |
log = logging.getLogger()
|
|
22 |
|
|
23 |
ROOT_PATH = os.path.abspath(os.path.dirname(__file__))
|
|
24 |
SOURCE_ROOT = os.path.normpath(os.path.join(ROOT_PATH, '../source'))
|
|
25 |
SCRIPTS_SOURCE_ROOT = os.path.normpath(os.path.join(SOURCE_ROOT, 'scripts'))
|
|
26 |
PLUGIN_SOURCE_ROOT = os.path.normpath(os.path.join(SOURCE_ROOT, 'plugins'))
|
|
27 |
TESTAUTOMATION_ROOT = os.path.normpath(os.path.join(SOURCE_ROOT, 'testautomation'))
|
|
28 |
assert os.path.exists(SOURCE_ROOT)
|
|
29 |
assert os.path.exists(SCRIPTS_SOURCE_ROOT)
|
|
30 |
assert os.path.exists(PLUGIN_SOURCE_ROOT)
|
|
31 |
assert os.path.exists(TESTAUTOMATION_ROOT)
|
|
32 |
|
3
|
33 |
|
0
|
34 |
|
|
35 |
sys.path.append(TESTAUTOMATION_ROOT)
|
|
36 |
import testautomation
|
|
37 |
from testautomation.copy_dir import copy_dir
|
3
|
38 |
from testautomation import plugin_utils
|
0
|
39 |
import utils
|
|
40 |
utils.setup_logging('export_bat.log')
|
|
41 |
|
|
42 |
|
|
43 |
def read_export_function_from_file(file_path):
|
|
44 |
if not os.path.exists(file_path):
|
|
45 |
return None
|
|
46 |
|
|
47 |
m = imp.load_source(
|
|
48 |
file_path.replace('\\', '__')
|
|
49 |
.replace('/', '__')
|
|
50 |
.replace(':', '_')
|
|
51 |
.replace('.', '_')
|
|
52 |
.replace(' ', '_'),
|
|
53 |
file_path)
|
|
54 |
|
|
55 |
try:
|
|
56 |
return m.export_standalone
|
|
57 |
except AttributeError:
|
|
58 |
return None
|
|
59 |
|
|
60 |
def find_egg_file(dir, name, python_version):
|
|
61 |
"""
|
|
62 |
Returns the name of an egg file in the given directory that starts with the
|
|
63 |
given name and is for the given Python version.
|
|
64 |
|
|
65 |
>>> find_egg_file('dep-eggs', 'simplejson', '2.5')
|
|
66 |
'simplejson-2.0.9-py2.5-win32.egg'
|
|
67 |
>>> find_egg_file('dep-eggs', 'simplejson', '2.6')
|
|
68 |
'simplejson-2.0.9-py2.6-win32.egg'
|
|
69 |
"""
|
|
70 |
for filename in os.listdir(dir):
|
|
71 |
if filename.startswith(name) and 'py' + python_version in filename:
|
|
72 |
return filename
|
|
73 |
return None
|
|
74 |
|
|
75 |
def main(argv):
|
|
76 |
# -----------
|
|
77 |
# Parse args
|
|
78 |
# -----------
|
|
79 |
|
|
80 |
parser = OptionParser()
|
|
81 |
parser.add_option("-t", "--target-dir",
|
|
82 |
help="The directory where the test are to be exported.")
|
|
83 |
parser.add_option("-p", "--plugin-package",
|
|
84 |
help="The plug-in package for exporting plug-in integration tests.",
|
|
85 |
default=None)
|
|
86 |
(options, args) = parser.parse_args()
|
|
87 |
if options.target_dir is None:
|
|
88 |
parser.error("Target directory must be given")
|
|
89 |
|
|
90 |
PYTHON_VERSION = utils.get_python_version()
|
|
91 |
|
|
92 |
TARGET_PATH = options.target_dir
|
|
93 |
PLUGIN_PACKAGE = options.plugin_package
|
|
94 |
log.info("Target directory: %s" % TARGET_PATH)
|
|
95 |
log.info("Plug-in package: %r" % PLUGIN_PACKAGE)
|
|
96 |
log.info("Python version: %s" % PYTHON_VERSION)
|
|
97 |
|
|
98 |
log.info("Cleaning target directory...")
|
|
99 |
utils.recreate_dir(TARGET_PATH)
|
|
100 |
|
|
101 |
|
|
102 |
# -------------------------
|
|
103 |
# Export script test files
|
|
104 |
# -------------------------
|
|
105 |
|
|
106 |
log.info("Copying script test files...")
|
|
107 |
SCRIPT_TESTS_DIR = os.path.join(SCRIPTS_SOURCE_ROOT, 'tests')
|
|
108 |
assert os.path.exists(SCRIPT_TESTS_DIR)
|
|
109 |
copy_dir(source_dir = SCRIPT_TESTS_DIR,
|
|
110 |
target_dir = os.path.join(TARGET_PATH, 'tests'),
|
|
111 |
dir_ignore_functions = [lambda d: d in ('.svn', 'temp', 'export_standalone')],
|
|
112 |
file_ignore_functions = [lambda f: f == 'cone.log' or f.endswith('.pyc')])
|
|
113 |
|
|
114 |
log.info("Copying script test overlay files...")
|
|
115 |
copy_dir(source_dir = os.path.join(ROOT_PATH, "export-bat/scripts-tests-overlay"),
|
|
116 |
target_dir = TARGET_PATH,
|
|
117 |
dir_ignore_functions = [lambda d: d == '.svn'])
|
|
118 |
|
|
119 |
|
|
120 |
|
|
121 |
# --------------------------------------
|
|
122 |
# Export plug-in integration test files
|
|
123 |
# --------------------------------------
|
|
124 |
|
|
125 |
log.info("Exporting plug-in integration test files...")
|
3
|
126 |
subpaths_by_package = plugin_utils.find_plugin_package_subpaths(PLUGIN_SOURCE_ROOT, 'integration-test', PLUGIN_PACKAGE)
|
0
|
127 |
for package_name, tests_path in subpaths_by_package:
|
|
128 |
log.debug(" Package: %s" % package_name)
|
|
129 |
log.debug(" Path: %s" % tests_path)
|
|
130 |
|
|
131 |
log.debug(" Copying test files...")
|
|
132 |
target_path = os.path.join(TARGET_PATH, 'plugin-tests', package_name + '_tests')
|
|
133 |
copy_dir(source_dir = tests_path,
|
|
134 |
target_dir = target_path,
|
|
135 |
dir_ignore_functions = [lambda d: d in ('.svn', 'temp')],
|
|
136 |
file_ignore_functions = [lambda f: f in ('cone.log', 'export_standalone.py') or f.endswith('.pyc')])
|
|
137 |
|
|
138 |
log.debug(" Copying overlay files...")
|
|
139 |
overlay_path = os.path.join('export-bat/plugin-integration-test-overlay')
|
|
140 |
copy_dir(source_dir = overlay_path,
|
|
141 |
target_dir = target_path,
|
|
142 |
dir_ignore_functions = [lambda d: d == '.svn'])
|
|
143 |
|
|
144 |
log.debug(" Exporting extra data...")
|
|
145 |
func = read_export_function_from_file(os.path.join(tests_path, 'export_standalone.py'))
|
|
146 |
if func:
|
|
147 |
log.debug(" Executing export function...")
|
|
148 |
func(target_path)
|
|
149 |
|
|
150 |
|
|
151 |
TARGET_EGGS_DIR = os.path.join(TARGET_PATH, 'eggs')
|
|
152 |
|
|
153 |
# ---------------------------
|
|
154 |
# Copy needed dependency eggs
|
|
155 |
# ---------------------------
|
|
156 |
|
|
157 |
log.info("Copying library eggs...")
|
|
158 |
DEP_EGGS_DIR = os.path.normpath(os.path.join(ROOT_PATH, '../dep-eggs'))
|
|
159 |
assert os.path.isdir(DEP_EGGS_DIR)
|
5
|
160 |
DEPENDENCIES = ['simplejson']
|
0
|
161 |
for dep in DEPENDENCIES:
|
|
162 |
egg_file_name = find_egg_file(DEP_EGGS_DIR, dep, PYTHON_VERSION)
|
|
163 |
if egg_file_name is None:
|
|
164 |
log.critical("Could not find egg file for dependency '%s' from '%s'" % (dep, DEP_EGGS_DIR))
|
|
165 |
return 1
|
|
166 |
source_path = os.path.join(DEP_EGGS_DIR, egg_file_name)
|
|
167 |
target_path = os.path.join(TARGET_EGGS_DIR, egg_file_name)
|
|
168 |
utils.copy_file(source_path, target_path)
|
|
169 |
|
|
170 |
|
|
171 |
# ------------------
|
|
172 |
# Build needed eggs
|
|
173 |
# ------------------
|
|
174 |
|
|
175 |
log.info("Building eggs...")
|
|
176 |
utils.build_egg(os.path.join(SOURCE_ROOT), TARGET_EGGS_DIR)
|
|
177 |
utils.build_egg(os.path.join(SOURCE_ROOT, 'testautomation'), TARGET_EGGS_DIR)
|
|
178 |
|
|
179 |
return 0
|
|
180 |
|
|
181 |
if __name__ == "__main__":
|
|
182 |
sys.exit(main(sys.argv))
|