~launchpad-pqm/launchpad/devel

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
26
from subprocess import PIPE, Popen
27
import tempfile
28
import transaction
29
8426.6.1 by Michael Hudson
bzr ls --versioned --recursive --kind=file | xargs sed -i -e 's,from canonical.codehosting,from lp.codehosting,'
30
from lp.codehosting.codeimport.tests.test_foreigntree import (
5670.2.22 by jml at canonical
Clean up a bunch of lint and put a commit in the right place.
31
    SubversionServer)
5670.2.13 by jml at canonical
Helpful utility for running a branch to be imported.
32
from canonical.launchpad.scripts import execute_zcml_for_scripts
8440.1.1 by Curtis Hovey
Updated all imports or LaunchpadObjectFactory to come from lp.test.factory.
33
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
34
from canonical.launchpad.webapp import canonical_url
35
36
5670.2.13 by jml at canonical
Helpful utility for running a branch to be imported.
37
def shell(*args):
38
    print ' '.join(args)
39
    return Popen(args, stdout=PIPE).communicate()[0]
40
41
42
def make_import_job(svn_url):
43
    factory = LaunchpadObjectFactory()
5670.2.17 by jml at canonical
Make the mock server utility re-use test code. Make it better
44
    code_import = factory.makeCodeImport(svn_branch_url=svn_url)
45
    return factory.makeCodeImportJob(code_import)
5670.2.13 by jml at canonical
Helpful utility for running a branch to be imported.
46
47
48
def main():
49
    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
50
    temp_directory = tempfile.mkdtemp()
51
    svn_repo_path = os.path.join(temp_directory, 'svn-repository')
5670.2.21 by jml at canonical
Why run a server at all?!
52
    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
53
    svn_server.setUp()
54
    try:
5670.2.21 by jml at canonical
Why run a server at all?!
55
        svn_url = svn_server.makeBranch(
56
            '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
57
        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.
58
        transaction.commit()
5670.2.17 by jml at canonical
Make the mock server utility re-use test code. Make it better
59
        print "CodeImportJob.id:", job.id
5670.2.24 by jml at canonical
More URLs
60
        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
61
        print "Subversion Repository:", svn_repo_path
62
        print "Subversion branch URL:", job.code_import.svn_branch_url
5670.2.24 by jml at canonical
More URLs
63
        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
64
        print
65
    finally:
66
        svn_server.tearDown()
5670.2.13 by jml at canonical
Helpful utility for running a branch to be imported.
67
68
69
if __name__ == '__main__':
70
    main()