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 ( |
|
0.152.12
by Vincent Ladeuil
Implement 'upload_location' in config files. |
26 |
branch, |
|
0.152.3
by v.ladeuil+lp at free
Make the tests fail not error out. |
27 |
commands, |
|
0.152.5
by v.ladeuil+lp at free
Partial incremental upload implementationm tests pass. |
28 |
errors, |
|
0.152.3
by v.ladeuil+lp at free
Make the tests fail not error out. |
29 |
option, |
|
0.152.5
by v.ladeuil+lp at free
Partial incremental upload implementationm tests pass. |
30 |
revisionspec, |
|
0.152.4
by v.ladeuil+lp at free
Implement a trivial implementation to make one test pass. |
31 |
transport, |
|
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.12
by Vincent Ladeuil
Implement 'upload_location' in config files. |
43 |
'remember', |
|
0.152.3
by v.ladeuil+lp at free
Make the tests fail not error out. |
44 |
option.Option('full', 'Upload the full working tree.'), |
|
0.152.11
by Vincent Ladeuil
Be coherent with bzr push. |
45 |
option.Option('directory', |
46 |
help='Branch to upload from, ' |
|
47 |
'rather than the one containing the working directory.', |
|
48 |
short_name='d', |
|
49 |
type=unicode, |
|
50 |
),
|
|
|
0.152.4
by v.ladeuil+lp at free
Implement a trivial implementation to make one test pass. |
51 |
]
|
|
0.152.5
by v.ladeuil+lp at free
Partial incremental upload implementationm tests pass. |
52 |
|
|
0.152.12
by Vincent Ladeuil
Implement 'upload_location' in config files. |
53 |
def run(self, location, full=False, revision=None, remember=None, |
|
0.152.11
by Vincent Ladeuil
Be coherent with bzr push. |
54 |
directory=None, |
|
0.152.8
by Vincent Ladeuil
Handle uploading directories. |
55 |
):
|
|
0.152.11
by Vincent Ladeuil
Be coherent with bzr push. |
56 |
if directory is None: |
57 |
directory = u'.' |
|
|
0.152.12
by Vincent Ladeuil
Implement 'upload_location' in config files. |
58 |
self.branch = branch.Branch.open_containing(directory)[0] |
|
0.152.4
by v.ladeuil+lp at free
Implement a trivial implementation to make one test pass. |
59 |
|
|
0.152.7
by Vincent Ladeuil
Slight refactoring. |
60 |
if location is None: |
|
0.152.12
by Vincent Ladeuil
Implement 'upload_location' in config files. |
61 |
stored_loc = self.get_upload_location() |
62 |
if stored_loc is None: |
|
63 |
raise errors.BzrCommandError('No upload location' |
|
64 |
' known or specified.') |
|
65 |
else: |
|
66 |
display_url = urlutils.unescape_for_display(stored_loc, |
|
67 |
self.outf.encoding) |
|
68 |
self.outf.write("Using saved location: %s\n" % display_url) |
|
69 |
location = stored_loc |
|
70 |
||
71 |
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. |
72 |
if revision is None: |
|
0.152.12
by Vincent Ladeuil
Implement 'upload_location' in config files. |
73 |
rev_id = self.branch.last_revision() |
|
0.152.4
by v.ladeuil+lp at free
Implement a trivial implementation to make one test pass. |
74 |
else: |
75 |
if len(revision) != 1: |
|
76 |
raise errors.BzrCommandError( |
|
77 |
'bzr upload --revision takes exactly 1 argument') |
|
|
0.152.10
by Vincent Ladeuil
Fix incremental upload cheat. |
78 |
rev_id = revision[0].in_history(self.branch).rev_id |
|
0.152.4
by v.ladeuil+lp at free
Implement a trivial implementation to make one test pass. |
79 |
|
|
0.152.12
by Vincent Ladeuil
Implement 'upload_location' in config files. |
80 |
self.tree = self.branch.repository.revision_tree(rev_id) |
|
0.152.5
by v.ladeuil+lp at free
Partial incremental upload implementationm tests pass. |
81 |
self.rev_id = rev_id |
|
0.152.4
by v.ladeuil+lp at free
Implement a trivial implementation to make one test pass. |
82 |
if full: |
|
0.152.5
by v.ladeuil+lp at free
Partial incremental upload implementationm tests pass. |
83 |
self.upload_full_tree() |
|
0.152.4
by v.ladeuil+lp at free
Implement a trivial implementation to make one test pass. |
84 |
else: |
|
0.152.10
by Vincent Ladeuil
Fix incremental upload cheat. |
85 |
self.upload_tree() |
86 |
||
|
0.152.12
by Vincent Ladeuil
Implement 'upload_location' in config files. |
87 |
# We uploaded successfully, remember it
|
88 |
if self.get_upload_location() is None or remember: |
|
89 |
self.set_upload_location(self.to_transport.base) |
|
90 |
||
91 |
def set_upload_location(self, location): |
|
92 |
self.branch.get_config().set_user_option('upload_location', location) |
|
93 |
||
94 |
def get_upload_location(self): |
|
95 |
return self.branch.get_config().get_user_option('upload_location') |
|
96 |
||
|
0.152.10
by Vincent Ladeuil
Fix incremental upload cheat. |
97 |
bzr_upload_revid_file_name = '.bzr-upload.revid' |
|
0.152.5
by v.ladeuil+lp at free
Partial incremental upload implementationm tests pass. |
98 |
|
99 |
def set_uploaded_revid(self, rev_id): |
|
|
0.152.10
by Vincent Ladeuil
Fix incremental upload cheat. |
100 |
# XXX: Add tests for concurrent updates, etc.
|
101 |
self.to_transport.put_bytes(self.bzr_upload_revid_file_name, rev_id) |
|
102 |
||
103 |
def get_uploaded_revid(self): |
|
104 |
return self.to_transport.get_bytes(self.bzr_upload_revid_file_name) |
|
|
0.152.7
by Vincent Ladeuil
Slight refactoring. |
105 |
|
106 |
def upload_file(self, relpath, id): |
|
107 |
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. |
108 |
|
|
0.152.8
by Vincent Ladeuil
Handle uploading directories. |
109 |
def make_remote_dir(self, relpath): |
110 |
# XXX: handle mode
|
|
111 |
self.to_transport.mkdir(relpath) |
|
112 |
||
|
0.152.5
by v.ladeuil+lp at free
Partial incremental upload implementationm tests pass. |
113 |
def upload_full_tree(self): |
|
0.152.7
by Vincent Ladeuil
Slight refactoring. |
114 |
self.to_transport.ensure_base() # XXX: Handle errors |
|
0.152.5
by v.ladeuil+lp at free
Partial incremental upload implementationm tests pass. |
115 |
self.tree.lock_read() |
116 |
try: |
|
|
0.152.10
by Vincent Ladeuil
Fix incremental upload cheat. |
117 |
for dp, ie in self.tree.inventory.iter_entries(): |
118 |
if dp in ('', '.bzrignore'): |
|
119 |
# skip root ('')
|
|
120 |
# .bzrignore has no meaning outside of a working tree
|
|
121 |
# so do not upload it
|
|
|
0.152.5
by v.ladeuil+lp at free
Partial incremental upload implementationm tests pass. |
122 |
continue
|
123 |
||
|
0.152.8
by Vincent Ladeuil
Handle uploading directories. |
124 |
if ie.kind == 'file': |
125 |
self.upload_file(dp, ie.file_id) |
|
126 |
elif ie.kind == 'directory': |
|
127 |
try: |
|
128 |
self.make_remote_dir(dp) |
|
129 |
except errors.FileExists: |
|
130 |
# The directory existed before the upload
|
|
131 |
pass
|
|
132 |
else: |
|
133 |
raise NotImplementedError |
|
|
0.152.5
by v.ladeuil+lp at free
Partial incremental upload implementationm tests pass. |
134 |
self.set_uploaded_revid(self.rev_id) |
135 |
finally: |
|
136 |
self.tree.unlock() |
|
137 |
||
|
0.152.10
by Vincent Ladeuil
Fix incremental upload cheat. |
138 |
def upload_tree(self): |
|
0.152.12
by Vincent Ladeuil
Implement 'upload_location' in config files. |
139 |
# XXX: errors out if NoSuchFile and recommand --full on first upload ?
|
140 |
# Add tests.
|
|
|
0.152.10
by Vincent Ladeuil
Fix incremental upload cheat. |
141 |
rev_id = self.get_uploaded_revid() |
142 |
# XXX: errors out if rev_id not in branch history (probably someone
|
|
143 |
# uploaded from a different branch).
|
|
144 |
from_tree = self.branch.repository.revision_tree(rev_id) |
|
|
0.152.7
by Vincent Ladeuil
Slight refactoring. |
145 |
self.to_transport.ensure_base() # XXX: Handle errors |
|
0.152.5
by v.ladeuil+lp at free
Partial incremental upload implementationm tests pass. |
146 |
changes = self.tree.changes_from(from_tree) |
147 |
self.tree.lock_read() |
|
148 |
try: |
|
|
0.152.8
by Vincent Ladeuil
Handle uploading directories. |
149 |
# XXX: handle removed, renamed, kind_changed
|
|
0.152.5
by v.ladeuil+lp at free
Partial incremental upload implementationm tests pass. |
150 |
for (path, id, kind) in changes.added: |
151 |
if kind is 'file': |
|
|
0.152.7
by Vincent Ladeuil
Slight refactoring. |
152 |
self.upload_file(path, id) |
|
0.152.8
by Vincent Ladeuil
Handle uploading directories. |
153 |
elif kind is 'directory': |
154 |
self.make_remote_dir(path) |
|
|
0.152.5
by v.ladeuil+lp at free
Partial incremental upload implementationm tests pass. |
155 |
else: |
156 |
raise NotImplementedError |
|
157 |
# XXX: Add a test for exec_change
|
|
158 |
for (path, id, kind, |
|
159 |
content_change, exec_change) in changes.modified: |
|
160 |
if kind is 'file': |
|
|
0.152.7
by Vincent Ladeuil
Slight refactoring. |
161 |
self.upload_file(path, id) |
|
0.152.5
by v.ladeuil+lp at free
Partial incremental upload implementationm tests pass. |
162 |
else: |
163 |
raise NotImplementedError |
|
164 |
self.set_uploaded_revid(self.rev_id) |
|
165 |
finally: |
|
166 |
self.tree.unlock() |
|
|
0.152.4
by v.ladeuil+lp at free
Implement a trivial implementation to make one test pass. |
167 |
|
|
0.152.1
by Vincent Ladeuil
Empty shell |
168 |
|
169 |
commands.register_command(cmd_upload) |
|
170 |
||
|
0.152.4
by v.ladeuil+lp at free
Implement a trivial implementation to make one test pass. |
171 |
|
|
0.152.1
by Vincent Ladeuil
Empty shell |
172 |
def test_suite(): |
173 |
from bzrlib.tests import TestUtil |
|
174 |
||
175 |
suite = TestUtil.TestSuite() |
|
176 |
loader = TestUtil.TestLoader() |
|
177 |
testmod_names = [ |
|
178 |
'test_upload', |
|
179 |
]
|
|
180 |
||
181 |
suite.addTest(loader.loadTestsFromModuleNames( |
|
182 |
["%s.%s" % (__name__, tmn) for tmn in testmod_names])) |
|
183 |
return suite |