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