~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).
4984.1.1 by jml at canonical
Add a script to make dummy hosted branches for all of the hosted branches in
5
4984.1.4 by jml at canonical
Add docstrings and remove unnecessary sys.exit() call.
6
"""Create dummy Bazaar branches for all HOSTED branches in the database.
7
8
The Launchpad sample data includes a number of HOSTED branches that users can
9
branch from, push to and view on the website. However, some of these things
10
will break if we are missing the actual Bazaar branches, so we have a script
11
to create them.
12
13
NOTE: This script will delete any existing sample data branches, so that the
14
sample data on the filesystem is consistent with the sample data in the
15
database.
16
"""
17
4984.1.1 by jml at canonical
Add a script to make dummy hosted branches for all of the hosted branches in
18
import _pythonpath
19
4984.1.2 by jml at canonical
Add make-dummy-hosted-branches as a target to branches, remove branch dir
20
import os
21
import shutil
4984.1.1 by jml at canonical
Add a script to make dummy hosted branches for all of the hosted branches in
22
import sys
5027.1.1 by jml at canonical
Mask BZR_HOME, rather than editing people's configuration files!
23
import tempfile
4984.1.1 by jml at canonical
Add a script to make dummy hosted branches for all of the hosted branches in
24
5821.2.34 by James Henstridge
Don't bother with initZopeless().
25
import transaction
4984.1.1 by jml at canonical
Add a script to make dummy hosted branches for all of the hosted branches in
26
from zope.component import getUtility
27
8590.1.5 by Tim Penhey
Here are the actual three lines needed to fix the make-dummy-hosted-branches script.
28
# Until we completely kill canonical.launchpad.database.__init__.py and remove
29
# all of the import *'s we need to import it first here.
30
import canonical.launchpad.database
31
8555.2.12 by Tim Penhey
Fix cronscripts and utilities too.
32
from lp.code.enums import BranchType
33
from lp.code.model.branch import Branch
8426.6.1 by Michael Hudson
bzr ls --versioned --recursive --kind=file | xargs sed -i -e 's,from canonical.codehosting,from lp.codehosting,'
34
from lp.codehosting.tests.helpers import make_bazaar_branch_and_tree
4984.1.2 by jml at canonical
Add make-dummy-hosted-branches as a target to branches, remove branch dir
35
from canonical.config import config
4984.1.1 by jml at canonical
Add a script to make dummy hosted branches for all of the hosted branches in
36
from canonical.database.sqlbase import sqlvalues
37
from canonical.launchpad.scripts import execute_zcml_for_scripts
38
39
40
def main(argv):
5027.1.1 by jml at canonical
Mask BZR_HOME, rather than editing people's configuration files!
41
    os.environ['BZR_HOME'] = tempfile.mkdtemp()
7732.1.3 by Jonathan Lange
Get rid of the branchesdest config variable.
42
    if os.path.exists(config.codehosting.hosted_branches_root):
43
        shutil.rmtree(config.codehosting.hosted_branches_root)
4984.1.1 by jml at canonical
Add a script to make dummy hosted branches for all of the hosted branches in
44
    execute_zcml_for_scripts()
45
    try:
46
        branches = Branch.select(
47
            "Branch.branch_type = %s" % sqlvalues(BranchType.HOSTED))
48
        for branch in branches:
49
            make_bazaar_branch_and_tree(branch)
50
    finally:
5821.2.34 by James Henstridge
Don't bother with initZopeless().
51
        transaction.abort()
4984.1.5 by jml at canonical
Add output on success.
52
    print "Created %d branches based on sample data." % len(list(branches))
4984.1.1 by jml at canonical
Add a script to make dummy hosted branches for all of the hosted branches in
53
54
55
if __name__ == '__main__':
4984.1.4 by jml at canonical
Add docstrings and remove unnecessary sys.exit() call.
56
    main(sys.argv)