/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz

« back to all changes in this revision

Viewing changes to olive/backend/init.py

  • Committer: Jelmer Vernooij
  • Date: 2008-06-28 20:24:16 UTC
  • mto: This revision was merged to the branch mainline in revision 517.
  • Revision ID: jelmer@samba.org-20080628202416-pvt4hkck3gqndine
Show the credits of those who contributed in the About dialog.

The credits are loaded from a pickle file that is generated by 
a new script, which uses the stats plugin to do the heavy lifting.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006 by Szilveszter Farkas (Phanatic) <szilveszter.farkas@gmail.com>
2
 
# Some parts of the code are:
3
 
# Copyright (C) 2005, 2006 by Canonical Ltd
4
 
 
5
 
# This program is free software; you can redistribute it and/or modify
6
 
# it under the terms of the GNU General Public License as published by
7
 
# the Free Software Foundation; either version 2 of the License, or
8
 
# (at your option) any later version.
9
 
 
10
 
# This program is distributed in the hope that it will be useful,
11
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
# GNU General Public License for more details.
14
 
 
15
 
# You should have received a copy of the GNU General Public License
16
 
# along with this program; if not, write to the Free Software
17
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
 
 
19
 
import errno
20
 
import os
21
 
 
22
 
import bzrlib
23
 
import bzrlib.bzrdir as bzrdir
24
 
import bzrlib.errors as errors
25
 
 
26
 
from bzrlib.branch import Branch
27
 
 
28
 
from errors import (AlreadyBranchError, BranchExistsWithoutWorkingTree,
29
 
                    NonExistingParent, NonExistingRevision,
30
 
                    NonExistingSource, NotBranchError, TargetAlreadyExists)
31
 
 
32
 
def init(location):
33
 
    """ Initialize a directory.
34
 
    
35
 
    :param location: full path to the directory you want to be versioned
36
 
    """
37
 
    from bzrlib.builtins import get_format_type
38
 
 
39
 
    format = get_format_type('default')
40
 
 
41
 
    if not os.path.exists(location):
42
 
        os.mkdir(location)
43
 
 
44
 
    try:
45
 
        existing_bzrdir = bzrdir.BzrDir.open(location)
46
 
    except errors.NotBranchError:
47
 
        bzrdir.BzrDir.create_branch_convenience(location, format=format)
48
 
    else:
49
 
        if existing_bzrdir.has_branch():
50
 
            if existing_bzrdir.has_workingtree():
51
 
                raise AlreadyBranchError(location)
52
 
            else:
53
 
                raise BranchExistsWithoutWorkingTree(location)
54
 
        else:
55
 
            existing_bzrdir.create_branch()
56
 
            existing_bzrdir.create_workingtree()
57
 
 
58
 
def branch(from_location, to_location, revision=None):
59
 
    """ Create a branch from a local/remote location.
60
 
    
61
 
    :param from_location: the original location of the branch
62
 
    
63
 
    :param to_location: the directory where the branch should be created
64
 
    
65
 
    :param revision: if specified, the given revision will be branched
66
 
    
67
 
    :return: number of revisions branched
68
 
    """
69
 
    from bzrlib.transport import get_transport
70
 
 
71
 
    try:
72
 
        br_from = Branch.open(from_location)
73
 
    except OSError, e:
74
 
        if e.errno == errno.ENOENT:
75
 
            raise NonExistingSource(from_location)
76
 
        else:
77
 
            raise
78
 
    except errors.NotBranchError:
79
 
        raise NotBranchError(from_location)
80
 
 
81
 
    br_from.lock_read()
82
 
 
83
 
    try:
84
 
        basis_dir = None
85
 
        if revision is not None:
86
 
            revision_id = br_from.get_rev_id(revision)
87
 
        else:
88
 
            revision_id = None
89
 
 
90
 
        to_location = to_location + '/' + os.path.basename(from_location.rstrip("/\\"))
91
 
        name = None
92
 
        to_transport = get_transport(to_location)
93
 
 
94
 
        try:
95
 
            to_transport.mkdir('.')
96
 
        except errors.FileExists:
97
 
            raise TargetAlreadyExists(to_location)
98
 
        except errors.NoSuchFile:
99
 
            raise NonExistingParent(to_location)
100
 
 
101
 
        try:
102
 
            dir = br_from.bzrdir.sprout(to_transport.base, revision_id, basis_dir)
103
 
            branch = dir.open_branch()
104
 
        except errors.NoSuchRevision:
105
 
            to_transport.delete_tree('.')
106
 
            raise NonExistingRevision(from_location, revision[0])
107
 
 
108
 
        if name:
109
 
            branch.control_files.put_utf8('branch-name', name)
110
 
    finally:
111
 
        br_from.unlock()
112
 
        
113
 
    return branch.revno()
114
 
 
115
 
def checkout(branch_location, to_location, revision=None, lightweight=False):
116
 
    """ Create a new checkout of an existing branch.
117
 
    
118
 
    :param branch_location: the location of the branch you'd like to checkout
119
 
    
120
 
    :param to_location: the directory where the checkout should be created
121
 
    
122
 
    :param revision: the given revision will be checkout'ed (be aware!)
123
 
    
124
 
    :param lightweight: perform a lightweight checkout (be aware!)
125
 
    """
126
 
    source = Branch.open(branch_location)
127
 
    
128
 
    if revision is not None:
129
 
        revision_id = source.get_rev_id(revision)
130
 
    else:
131
 
        revision_id = None
132
 
 
133
 
    # if the source and to_location are the same, 
134
 
    # and there is no working tree,
135
 
    # then reconstitute a branch
136
 
    if (bzrlib.osutils.abspath(to_location) ==
137
 
        bzrlib.osutils.abspath(branch_location)):
138
 
        try:
139
 
            source.bzrdir.open_workingtree()
140
 
        except errors.NoWorkingTree:
141
 
            source.bzrdir.create_workingtree()
142
 
            return
143
 
 
144
 
    try:
145
 
        os.mkdir(to_location)
146
 
    except OSError, e:
147
 
        if e.errno == errno.EEXIST:
148
 
            raise TargetAlreadyExists(to_location)
149
 
        if e.errno == errno.ENOENT:
150
 
            raise NonExistingParent(to_location)
151
 
        else:
152
 
            raise
153
 
 
154
 
    old_format = bzrlib.bzrdir.BzrDirFormat.get_default_format()
155
 
    bzrlib.bzrdir.BzrDirFormat.set_default_format(bzrdir.BzrDirMetaFormat1())
156
 
 
157
 
    try:
158
 
        if lightweight:
159
 
            checkout = bzrdir.BzrDirMetaFormat1().initialize(to_location)
160
 
            bzrlib.branch.BranchReferenceFormat().initialize(checkout, source)
161
 
        else:
162
 
            checkout_branch = bzrlib.bzrdir.BzrDir.create_branch_convenience(
163
 
                to_location, force_new_tree=False)
164
 
            checkout = checkout_branch.bzrdir
165
 
            checkout_branch.bind(source)
166
 
            if revision_id is not None:
167
 
                rh = checkout_branch.revision_history()
168
 
                checkout_branch.set_revision_history(rh[:rh.index(revision_id) + 1])
169
 
 
170
 
        checkout.create_workingtree(revision_id)
171
 
    finally:
172
 
        bzrlib.bzrdir.BzrDirFormat.set_default_format(old_format)