/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
    """
0.152.7 by Vincent Ladeuil
Slight refactoring.
40
    takes_args = ['location?']
0.152.2 by v.ladeuil+lp at free
Add failing tests for basic usage.
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.7 by Vincent Ladeuil
Slight refactoring.
46
    def run(self, location, 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
0.152.7 by Vincent Ladeuil
Slight refactoring.
50
        if location is None:
51
            # XXX: use the remembered location
0.152.4 by v.ladeuil+lp at free
Implement a trivial implementation to make one test pass.
52
            raise NotImplementedError
53
        else:
0.152.7 by Vincent Ladeuil
Slight refactoring.
54
            self.to_transport = transport.get_transport(location)
0.152.4 by v.ladeuil+lp at free
Implement a trivial implementation to make one test pass.
55
        if revision is None:
0.152.5 by v.ladeuil+lp at free
Partial incremental upload implementationm tests pass.
56
            rev_id = wt.last_revision()
0.152.4 by v.ladeuil+lp at free
Implement a trivial implementation to make one test pass.
57
        else:
58
            if len(revision) != 1:
59
                raise errors.BzrCommandError(
60
                    'bzr upload --revision takes exactly 1 argument')
61
            rev_id = revision[0].in_history(b).rev_id
62
0.152.5 by v.ladeuil+lp at free
Partial incremental upload implementationm tests pass.
63
        self.rev_id = rev_id
64
        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.
65
        if full:
0.152.5 by v.ladeuil+lp at free
Partial incremental upload implementationm tests pass.
66
            self.upload_full_tree()
0.152.4 by v.ladeuil+lp at free
Implement a trivial implementation to make one test pass.
67
        else:
0.152.5 by v.ladeuil+lp at free
Partial incremental upload implementationm tests pass.
68
            rev1 = revisionspec.RevisionSpec.from_string('1')
69
            rev1_id = rev1.in_history(b).rev_id
70
            from_tree = b.repository.revision_tree(rev1_id)
71
            self.upload_tree(from_tree)
72
73
    def set_uploaded_revid(self, rev_id):
74
        # XXX: Rename to .bzr/uploaded ? Add tests for concurrent updates, etc.
0.152.7 by Vincent Ladeuil
Slight refactoring.
75
        self.to_transport.put_bytes('.bzr.uploaded', rev_id)
76
77
    def upload_file(self, relpath, id):
78
        self.to_transport.put_bytes(relpath, self.tree.get_file_text(id))
0.152.5 by v.ladeuil+lp at free
Partial incremental upload implementationm tests pass.
79
80
    def upload_full_tree(self):
0.152.7 by Vincent Ladeuil
Slight refactoring.
81
        self.to_transport.ensure_base() # XXX: Handle errors
0.152.5 by v.ladeuil+lp at free
Partial incremental upload implementationm tests pass.
82
        self.tree.lock_read()
83
        try:
84
            inv = self.tree.inventory
85
            entries = inv.iter_entries()
86
            entries.next() # skip root
87
            for dp, ie in entries:
88
                # .bzrignore has no meaning outside of a working tree
89
                # so do not export it
90
                if dp == ".bzrignore":
91
                    continue
92
0.152.7 by Vincent Ladeuil
Slight refactoring.
93
                self.upload_file(dp, ie.file_id)
0.152.5 by v.ladeuil+lp at free
Partial incremental upload implementationm tests pass.
94
            self.set_uploaded_revid(self.rev_id)
95
        finally:
96
            self.tree.unlock()
97
98
    def upload_tree(self, from_tree):
0.152.7 by Vincent Ladeuil
Slight refactoring.
99
        self.to_transport.ensure_base() # XXX: Handle errors
0.152.5 by v.ladeuil+lp at free
Partial incremental upload implementationm tests pass.
100
        # XXX: add tests for directories
101
        changes = self.tree.changes_from(from_tree)
102
        self.tree.lock_read()
103
        try:
104
            for (path, id, kind) in changes.added:
105
                if kind is 'file':
0.152.7 by Vincent Ladeuil
Slight refactoring.
106
                    self.upload_file(path, id)
0.152.5 by v.ladeuil+lp at free
Partial incremental upload implementationm tests pass.
107
                else:
108
                    raise NotImplementedError
109
            # XXX: Add a test for exec_change
110
            for (path, id, kind,
111
                 content_change, exec_change) in changes.modified:
112
                if kind is 'file':
0.152.7 by Vincent Ladeuil
Slight refactoring.
113
                    self.upload_file(path, id)
0.152.5 by v.ladeuil+lp at free
Partial incremental upload implementationm tests pass.
114
                else:
115
                    raise NotImplementedError
116
            self.set_uploaded_revid(self.rev_id)
117
        finally:
118
            self.tree.unlock()
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
121
commands.register_command(cmd_upload)
122
0.152.4 by v.ladeuil+lp at free
Implement a trivial implementation to make one test pass.
123
0.152.1 by Vincent Ladeuil
Empty shell
124
def test_suite():
125
    from bzrlib.tests import TestUtil
126
127
    suite = TestUtil.TestSuite()
128
    loader = TestUtil.TestLoader()
129
    testmod_names = [
130
        'test_upload',
131
        ]
132
133
    suite.addTest(loader.loadTestsFromModuleNames(
134
            ["%s.%s" % (__name__, tmn) for tmn in testmod_names]))
135
    return suite