2
# Copyright 2008 Canonical Ltd. All rights reserved.
4
"""Make a Subversion repostiory and then make a CodeImportJob for it."""
6
# XXX: JonathanLange 2008-01-03: This is deliberately horrible.
7
# You can make it nicer if you want.
13
from subprocess import PIPE, Popen
17
from zope.component import getUtility
19
from canonical.launchpad.interfaces import (
20
BranchType, CodeImportReviewStatus, ICodeImportSet,
21
ICodeImportJobWorkflow, ILaunchpadCelebrities, RevisionControlSystems)
22
from canonical.launchpad.scripts import execute_zcml_for_scripts
23
from canonical.launchpad.testing import LaunchpadObjectFactory
28
return Popen(args, stdout=PIPE).communicate()[0]
31
def make_temp_svn_repo():
32
directory = tempfile.mkdtemp()
33
repo = os.path.join(directory, 'repo')
35
shell('svnadmin', 'create', repo)
36
return os.path.abspath(repo)
39
def in_temp_dir(function):
40
def new_function(*args, **kwargs):
41
curr_dir = os.getcwd()
42
temp_dir = tempfile.mkdtemp()
45
return function(*args, **kwargs)
48
shutil.rmtree(temp_dir)
53
def populate_repo(url):
54
url = '/'.join([url, 'trunk'])
55
shell('svn', 'mkdir', '-m', '"Make trunk"', url)
56
shell('svn', 'co', url)
58
file = open('README', 'w')
59
file.write('No real content\n')
61
shell('svn', 'add', 'README')
62
shell('svn', 'commit', '-m', '"Add a file."')
63
return os.path.abspath(os.getcwd())
66
def make_import_job(svn_url):
67
factory = LaunchpadObjectFactory()
68
vcs_imports = getUtility(ILaunchpadCelebrities).vcs_imports
69
branch = factory.makeBranch(
70
BranchType.IMPORTED, owner=vcs_imports)
71
registrar = factory.makePerson()
72
code_import = getUtility(ICodeImportSet).new(
73
registrar, branch, RevisionControlSystems.SVN,
74
svn_branch_url=svn_url)
75
workflow = getUtility(ICodeImportJobWorkflow)
76
code_import.updateFromData(
77
{'review_status': CodeImportReviewStatus.REVIEWED}, registrar)
78
job = workflow.newJob(code_import)
83
execute_zcml_for_scripts(use_web_security=False)
84
repo_path = make_temp_svn_repo()
85
working_path = populate_repo('file://' + repo_path)
86
job = make_import_job(
87
'svn://localhost:8083/' + os.path.basename(repo_path) + '/'
88
+ os.path.basename(working_path))
91
print "REPOSITORY:", repo_path
93
print "URL:", job.code_import.svn_branch_url
95
print "RUNNING Subversion server. Press Ctrl-C to terminate."
96
shell('svnserve', '-d', '--foreground', '--listen-port', '8083', '--root',
97
os.path.dirname(repo_path))
101
if __name__ == '__main__':