|
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 from optparse import OptionParser |
|
19 |
|
20 ROOT_PATH = os.path.abspath(os.path.dirname(__file__)) |
|
21 SOURCE_ROOT = os.path.normpath(os.path.join(ROOT_PATH, '../../..')) |
|
22 PLUGIN_SOURCE_ROOT = os.path.normpath(os.path.join(SOURCE_ROOT, 'plugins')) |
|
23 assert os.path.split(SOURCE_ROOT)[1] == 'source' |
|
24 assert os.path.split(PLUGIN_SOURCE_ROOT)[1] == 'plugins' |
|
25 |
|
26 sys.path.append(os.path.normpath(os.path.join(SOURCE_ROOT, 'testautomation'))) |
|
27 import testautomation |
|
28 from testautomation.copy_dir import copy_dir |
|
29 |
|
30 def build_egg(dir, target_dir): |
|
31 orig_workdir = os.getcwd() |
|
32 os.chdir(dir) |
|
33 try: |
|
34 os.system('python setup.py bdist_egg --dist-dir "%s"' % target_dir) |
|
35 finally: |
|
36 os.chdir(orig_workdir) |
|
37 |
|
38 def read_export_function_from_file(file_path): |
|
39 if not os.path.exists(file_path): |
|
40 return None |
|
41 |
|
42 m = imp.load_source( |
|
43 file_path.replace('\\', '__') |
|
44 .replace('/', '__') |
|
45 .replace(':', '_') |
|
46 .replace('.', '_') |
|
47 .replace(' ', '_'), |
|
48 file_path) |
|
49 |
|
50 try: |
|
51 return m.export_standalone |
|
52 except AttributeError: |
|
53 return None |
|
54 |
|
55 def main(argv): |
|
56 # Parse args |
|
57 parser = OptionParser() |
|
58 parser.add_option("--target-dir", |
|
59 help="The directory where the test are to be exported.", |
|
60 metavar="COMMAND") |
|
61 parser.add_option("--plugin-subpackage",\ |
|
62 help="The plug-in package for exporting plug-in integration tests.",\ |
|
63 default=None,\ |
|
64 metavar="SUBPACKAGE") |
|
65 (options, args) = parser.parse_args() |
|
66 if options.target_dir is None: |
|
67 parser.error("Target directory must be given") |
|
68 if options.plugin_subpackage is None: |
|
69 parser.error("Plug-in sub-package name must be given") |
|
70 |
|
71 TARGET_PATH = options.target_dir |
|
72 PLUGIN_PACKAGES = ['common'] |
|
73 if options.plugin_subpackage.lower() not in ('', 'common'): |
|
74 PLUGIN_PACKAGES.append(options.plugin_subpackage) |
|
75 |
|
76 print "(Re)creating dir '%s'..." % TARGET_PATH |
|
77 if os.path.exists(TARGET_PATH): |
|
78 shutil.rmtree(TARGET_PATH) |
|
79 os.makedirs(TARGET_PATH) |
|
80 |
|
81 |
|
82 print "Copying script test files..." |
|
83 copy_dir(source_dir = os.path.join(ROOT_PATH, '..'), |
|
84 target_dir = os.path.join(TARGET_PATH, 'tests'), |
|
85 dir_ignore_functions = [lambda d: d in ('.svn', 'temp', 'export_standalone')], |
|
86 file_ignore_functions = [lambda f: f == 'cone.log' or f.endswith('.pyc')]) |
|
87 |
|
88 print "Copying plug-in integration test files..." |
|
89 for name in PLUGIN_PACKAGES: |
|
90 print " Processing plug-in package '%s'..." % name |
|
91 |
|
92 package_path = os.path.join(PLUGIN_SOURCE_ROOT, name) |
|
93 if not os.path.isdir(package_path): |
|
94 print " '%s' does not exist or is not a directory!" % package_path |
|
95 return 1 |
|
96 |
|
97 tests_path = os.path.join(package_path, 'integration-test') |
|
98 if not os.path.isdir(tests_path): |
|
99 print " No 'integration-test' directory, skipping" |
|
100 continue |
|
101 |
|
102 print " Copying test files..." |
|
103 target_path = os.path.join(TARGET_PATH, 'plugin-tests', name + '_tests') |
|
104 copy_dir(source_dir = tests_path, |
|
105 target_dir = target_path, |
|
106 dir_ignore_functions = [lambda d: d in ('.svn', 'temp')], |
|
107 file_ignore_functions = [lambda f: f in ('cone.log', 'export_standalone.py') or f.endswith('.pyc')]) |
|
108 |
|
109 print " Overwriting __init__.py..." |
|
110 f = open(os.path.join(target_path, '__init__.py'), 'wb') |
|
111 f.close() |
|
112 |
|
113 print " Exporting extra data..." |
|
114 func = read_export_function_from_file(os.path.join(tests_path, 'export_standalone.py')) |
|
115 if func: |
|
116 print " Executing export function..." |
|
117 func(target_path) |
|
118 |
|
119 print "Copying overlay files..." |
|
120 copy_dir(source_dir = os.path.join(ROOT_PATH, "overlay"), |
|
121 target_dir = TARGET_PATH, |
|
122 dir_ignore_functions = [lambda d: d == '.svn']) |
|
123 |
|
124 |
|
125 print "Building eggs..." |
|
126 eggs_dir = os.path.join(TARGET_PATH, 'eggs') |
|
127 build_egg(os.path.join(SOURCE_ROOT), eggs_dir) |
|
128 build_egg(os.path.join(SOURCE_ROOT, 'testautomation'), eggs_dir) |
|
129 return 0 |
|
130 |
|
131 if __name__ == "__main__": |
|
132 sys.exit(main(sys.argv)) |