/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.152.6 by Vincent Ladeuil
Really use the transports and test against all targeted protocols.
1
# Copyright (C) 2008 Canonical Ltd
0.152.1 by Vincent Ladeuil
Empty shell
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
0.152.6 by Vincent Ladeuil
Really use the transports and test against all targeted protocols.
17
"""Upload a working tree, incrementally.
18
19
The only bzr-related info uploaded with the working tree is the corrseponding
20
revision id. The uploaded working tree is not linked to any other bzr data.
21
22
The intended use is for web sites.
23
"""
0.152.1 by Vincent Ladeuil
Empty shell
24
0.152.3 by v.ladeuil+lp at free
Make the tests fail not error out.
25
from bzrlib import (
26
    commands,
0.152.5 by v.ladeuil+lp at free
Partial incremental upload implementationm tests pass.
27
    errors,
0.152.3 by v.ladeuil+lp at free
Make the tests fail not error out.
28
    option,
0.152.5 by v.ladeuil+lp at free
Partial incremental upload implementationm tests pass.
29
    revisionspec,
0.152.4 by v.ladeuil+lp at free
Implement a trivial implementation to make one test pass.
30
    transport,
31
    workingtree,
0.152.3 by v.ladeuil+lp at free
Make the tests fail not error out.
32
    )
0.152.1 by Vincent Ladeuil
Empty shell
33
34
class cmd_upload(commands.Command):
0.152.2 by v.ladeuil+lp at free
Add failing tests for basic usage.
35
    """Upload a working tree, as a whole or incrementally.
36
37
    If no destination is specified use the last one used.
38
    If no revision is specified upload the changes since the last upload.
39
    """
40
    takes_args = ['dest?']
41
    takes_options = [
42
        'revision',
0.152.3 by v.ladeuil+lp at free
Make the tests fail not error out.
43
        option.Option('full', 'Upload the full working tree.'),
0.152.4 by v.ladeuil+lp at free
Implement a trivial implementation to make one test pass.
44
       ]
0.152.5 by v.ladeuil+lp at free
Partial incremental upload implementationm tests pass.
45
0.152.3 by v.ladeuil+lp at free
Make the tests fail not error out.
46
    def run(self, dest, full=False, revision=None):
0.152.5 by v.ladeuil+lp at free
Partial incremental upload implementationm tests pass.
47
        wt = workingtree.WorkingTree.open_containing(u'.')[0]
48
        b = wt.branch
0.152.4 by v.ladeuil+lp at free
Implement a trivial implementation to make one test pass.
49
50
        if dest is None:
51
            raise NotImplementedError
52
        else:
0.152.5 by v.ladeuil+lp at free
Partial incremental upload implementationm tests pass.
53
            self.dest = transport.get_transport(dest)
0.152.4 by v.ladeuil+lp at free
Implement a trivial implementation to make one test pass.
54
        if revision is None:
0.152.5 by v.ladeuil+lp at free
Partial incremental upload implementationm tests pass.
55
            rev_id = wt.last_revision()
0.152.4 by v.ladeuil+lp at free
Implement a trivial implementation to make one test pass.
56
        else:
57
            if len(revision) != 1:
58
                raise errors.BzrCommandError(
59
                    'bzr upload --revision takes exactly 1 argument')
60
            rev_id = revision[0].in_history(b).rev_id
61
0.152.5 by v.ladeuil+lp at free
Partial incremental upload implementationm tests pass.
62
        self.rev_id = rev_id
63
        self.tree = b.repository.revision_tree(rev_id)
0.152.4 by v.ladeuil+lp at free
Implement a trivial implementation to make one test pass.
64
        if full:
0.152.5 by v.ladeuil+lp at free
Partial incremental upload implementationm tests pass.
65
            self.upload_full_tree()
0.152.4 by v.ladeuil+lp at free
Implement a trivial implementation to make one test pass.
66
        else:
0.152.5 by v.ladeuil+lp at free
Partial incremental upload implementationm tests pass.
67
            rev1 = revisionspec.RevisionSpec.from_string('1')
68
            rev1_id = rev1.in_history(b).rev_id
69
            from_tree = b.repository.revision_tree(rev1_id)
70
            self.upload_tree(from_tree)
71
72
    def set_uploaded_revid(self, rev_id):
73
        # XXX: Rename to .bzr/uploaded ? Add tests for concurrent updates, etc.
74
        self.dest.put_bytes('.bzr.uploaded', rev_id)
75
76
    def upload_full_tree(self):
77
        self.dest.ensure_base() # XXX: Handle errors
78
        self.tree.lock_read()
79
        try:
80
            inv = self.tree.inventory
81
            entries = inv.iter_entries()
82
            entries.next() # skip root
83
            for dp, ie in entries:
84
                # .bzrignore has no meaning outside of a working tree
85
                # so do not export it
86
                if dp == ".bzrignore":
87
                    continue
88
0.152.6 by Vincent Ladeuil
Really use the transports and test against all targeted protocols.
89
                self.dest.put_bytes(dp, self.tree.get_file_text(ie.file_id))
0.152.5 by v.ladeuil+lp at free
Partial incremental upload implementationm tests pass.
90
            self.set_uploaded_revid(self.rev_id)
91
        finally:
92
            self.tree.unlock()
93
94
    def upload_tree(self, from_tree):
95
        self.dest.ensure_base() # XXX: Handle errors
96
        # XXX: add tests for directories
97
        changes = self.tree.changes_from(from_tree)
98
        self.tree.lock_read()
99
        try:
100
            for (path, id, kind) in changes.added:
101
                if kind is 'file':
102
                    self.dest.put_bytes(path, self.tree.get_file_text(id))
103
                else:
104
                    raise NotImplementedError
105
            # XXX: Add a test for exec_change
106
            for (path, id, kind,
107
                 content_change, exec_change) in changes.modified:
108
                if kind is 'file':
109
                    self.dest.put_bytes(path, self.tree.get_file_text(id))
110
                else:
111
                    raise NotImplementedError
112
            self.set_uploaded_revid(self.rev_id)
113
        finally:
114
            self.tree.unlock()
0.152.4 by v.ladeuil+lp at free
Implement a trivial implementation to make one test pass.
115
0.152.1 by Vincent Ladeuil
Empty shell
116
117
commands.register_command(cmd_upload)
118
0.152.4 by v.ladeuil+lp at free
Implement a trivial implementation to make one test pass.
119
0.152.1 by Vincent Ladeuil
Empty shell
120
def test_suite():
121
    from bzrlib.tests import TestUtil
122
123
    suite = TestUtil.TestSuite()
124
    loader = TestUtil.TestLoader()
125
    testmod_names = [
126
        'test_upload',
127
        ]
128
129
    suite.addTest(loader.loadTestsFromModuleNames(
130
            ["%s.%s" % (__name__, tmn) for tmn in testmod_names]))
131
    return suite