10637.3.1
by Guilherme Salgado
Use the default python version instead of a hard-coded version |
1 |
#!/usr/bin/python -S
|
8687.15.4
by Karl Fogel
Add the copyright header block to more files; tweak format in a few files. |
2 |
#
|
3 |
# Copyright 2009 Canonical Ltd. This software is licensed under the
|
|
4 |
# GNU Affero General Public License version 3 (see the file LICENSE).
|
|
5670.2.13
by jml at canonical
Helpful utility for running a branch to be imported. |
5 |
|
5670.2.17
by jml at canonical
Make the mock server utility re-use test code. Make it better |
6 |
"""Make a Subversion repostiory and then make a CodeImportJob for it.
|
7 |
||
8 |
USAGE: ./utilities/mock-code-import
|
|
9 |
||
10 |
Run 'make schema' first! This utility mutates the DB and doesn't restore
|
|
11 |
afterwards.
|
|
12 |
||
13 |
This means that the valid_vcs_details constraint on CodeImport is lost and
|
|
14 |
that there are new, crappy test objects in the DB. The utility will bork on
|
|
15 |
these when run again.
|
|
16 |
||
17 |
Details of the Subversion server are printed to stdout.
|
|
18 |
"""
|
|
5670.2.13
by jml at canonical
Helpful utility for running a branch to be imported. |
19 |
|
20 |
# XXX: JonathanLange 2008-01-03: This is deliberately horrible.
|
|
21 |
# You can make it nicer if you want.
|
|
22 |
||
23 |
import _pythonpath |
|
24 |
||
25 |
import os |
|
14612.2.6
by William Grant
utilities |
26 |
from subprocess import ( |
27 |
PIPE, |
|
28 |
Popen, |
|
29 |
)
|
|
5670.2.13
by jml at canonical
Helpful utility for running a branch to be imported. |
30 |
import tempfile |
14612.2.6
by William Grant
utilities |
31 |
|
5670.2.13
by jml at canonical
Helpful utility for running a branch to be imported. |
32 |
import transaction |
33 |
||
14612.2.6
by William Grant
utilities |
34 |
from lp.codehosting.codeimport.tests.test_foreigntree import SubversionServer |
14565.2.15
by Curtis Hovey
Moved canonical.launchpad.scripts __init__ to lp.services.scripts. |
35 |
from lp.services.scripts import execute_zcml_for_scripts |
14612.2.6
by William Grant
utilities |
36 |
from lp.services.webapp import canonical_url |
8440.1.1
by Curtis Hovey
Updated all imports or LaunchpadObjectFactory to come from lp.test.factory. |
37 |
from lp.testing.factory import LaunchpadObjectFactory |
5670.2.17
by jml at canonical
Make the mock server utility re-use test code. Make it better |
38 |
|
39 |
||
5670.2.13
by jml at canonical
Helpful utility for running a branch to be imported. |
40 |
def shell(*args): |
41 |
print ' '.join(args) |
|
42 |
return Popen(args, stdout=PIPE).communicate()[0] |
|
43 |
||
44 |
||
45 |
def make_import_job(svn_url): |
|
46 |
factory = LaunchpadObjectFactory() |
|
5670.2.17
by jml at canonical
Make the mock server utility re-use test code. Make it better |
47 |
code_import = factory.makeCodeImport(svn_branch_url=svn_url) |
48 |
return factory.makeCodeImportJob(code_import) |
|
5670.2.13
by jml at canonical
Helpful utility for running a branch to be imported. |
49 |
|
50 |
||
51 |
def main(): |
|
52 |
execute_zcml_for_scripts(use_web_security=False) |
|
5670.2.17
by jml at canonical
Make the mock server utility re-use test code. Make it better |
53 |
temp_directory = tempfile.mkdtemp() |
54 |
svn_repo_path = os.path.join(temp_directory, 'svn-repository') |
|
5670.2.21
by jml at canonical
Why run a server at all?! |
55 |
svn_server = SubversionServer(svn_repo_path) |
5670.2.17
by jml at canonical
Make the mock server utility re-use test code. Make it better |
56 |
svn_server.setUp() |
57 |
try: |
|
5670.2.21
by jml at canonical
Why run a server at all?! |
58 |
svn_url = svn_server.makeBranch( |
59 |
'trunk', [('README', 'No real content\n.')]) |
|
5670.2.17
by jml at canonical
Make the mock server utility re-use test code. Make it better |
60 |
job = make_import_job(svn_url) |
5670.2.22
by jml at canonical
Clean up a bunch of lint and put a commit in the right place. |
61 |
transaction.commit() |
5670.2.17
by jml at canonical
Make the mock server utility re-use test code. Make it better |
62 |
print "CodeImportJob.id:", job.id |
5670.2.24
by jml at canonical
More URLs |
63 |
print "Code Import URL:", canonical_url(job.code_import) |
5670.2.17
by jml at canonical
Make the mock server utility re-use test code. Make it better |
64 |
print "Subversion Repository:", svn_repo_path |
65 |
print "Subversion branch URL:", job.code_import.svn_branch_url |
|
5670.2.24
by jml at canonical
More URLs |
66 |
print "Launchpad branch URL:", canonical_url(job.code_import.branch) |
5670.2.17
by jml at canonical
Make the mock server utility re-use test code. Make it better |
67 |
print
|
68 |
finally: |
|
69 |
svn_server.tearDown() |
|
5670.2.13
by jml at canonical
Helpful utility for running a branch to be imported. |
70 |
|
71 |
||
72 |
if __name__ == '__main__': |
|
73 |
main() |