93
by Vincent Ladeuil
Migrate to config stacks |
1 |
# Copyright (C) 2008-2012 Canonical Ltd
|
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 |
||
6
by Vincent Ladeuil
Really use the transports and test against all targeted protocols. |
17 |
"""Upload a working tree, incrementally.
|
18 |
||
63
by Vincent Ladeuil
Make the doc more easily discoverable. |
19 |
Quickstart
|
20 |
----------
|
|
21 |
||
22 |
To get started, it's as simple as running::
|
|
23 |
||
24 |
bzr upload sftp://user@host/location/on/webserver
|
|
25 |
||
26 |
This will initially upload the whole working tree, and leave a file on the
|
|
27 |
remote location indicating the last revision that was uploaded
|
|
28 |
(.bzr-upload.revid), in order to avoid uploading unnecessary information the
|
|
29 |
next time.
|
|
30 |
||
31 |
If you would like to upload a specific revision, you just do:
|
|
32 |
||
33 |
bzr upload -r X sftp://user@host/location/on/webserver
|
|
34 |
||
35 |
bzr-upload, just as bzr does, will remember the location where you upload the
|
|
36 |
first time, so you don't need to specify it every time.
|
|
37 |
||
38 |
If you need to re-upload the whole working tree for some reason, you can:
|
|
39 |
||
40 |
bzr upload --full sftp://user@host/location/on/webserver
|
|
41 |
||
64.1.4
by Gary van der Merwe
Check that the revision we are uploading is a descendent from the revision that was uploaded. |
42 |
This command only works on the revision beening uploaded is a decendent of the
|
43 |
revision that was previously uploaded, and that they are hence from branches
|
|
44 |
that have not diverged. Branches are considered diverged if the destination
|
|
45 |
branch's most recent commit is one that has not been merged (directly or
|
|
46 |
indirectly) by the source branch.
|
|
47 |
||
48 |
If branches have diverged, you can use 'bzr upload --overwrite' to replace
|
|
49 |
the other branch completely, discarding its unmerged changes.
|
|
50 |
||
63
by Vincent Ladeuil
Make the doc more easily discoverable. |
51 |
|
52 |
Automatically Uploading
|
|
53 |
-----------------------
|
|
54 |
||
55 |
bzr-upload comes with a hook that can be used to trigger an upload whenever
|
|
56 |
the tip of the branch changes, including on commit, push, uncommit etc. This
|
|
57 |
would allow you to keep the code on the target up to date automatically.
|
|
58 |
||
59 |
The easiest way to enable this is to run upload with the --auto option.
|
|
60 |
||
61 |
bzr upload --auto
|
|
62 |
||
63 |
will enable the hook for this branch. If you were to do a commit in this branch
|
|
64 |
now you would see it trigger the upload automatically.
|
|
65 |
||
66 |
If you wish to disable this for a branch again then you can use the --no-auto
|
|
67 |
option.
|
|
68 |
||
69 |
bzr upload --no-auto
|
|
70 |
||
71 |
will disable the feature for that branch.
|
|
72 |
||
73 |
Since the auto hook is triggered automatically, you can't use the --quiet
|
|
74 |
option available for the upload command. Instead, you can set the
|
|
75 |
'upload_auto_quiet' configuration variable to True or False in either
|
|
76 |
bazaar.conf, locations.conf or branch.conf.
|
|
77 |
||
78 |
||
79 |
Storing the '.bzr-upload.revid' file
|
|
80 |
------------------------------------
|
|
81 |
||
17
by Vincent Ladeuil
Handle deletes (trivial implementation). |
82 |
The only bzr-related info uploaded with the working tree is the corresponding
|
6
by Vincent Ladeuil
Really use the transports and test against all targeted protocols. |
83 |
revision id. The uploaded working tree is not linked to any other bzr data.
|
84 |
||
63
by Vincent Ladeuil
Make the doc more easily discoverable. |
85 |
If the layout of your remote server is such that you can't write in the
|
86 |
root directory but only in the directories inside that root, you will need
|
|
87 |
to use the 'upload_revid_location' configuration variable to specify the
|
|
88 |
relative path to be used. That configuration variable can be specified in
|
|
89 |
locations.conf or branch.conf.
|
|
90 |
||
91 |
For example, given the following layout:
|
|
92 |
||
93 |
Project/
|
|
94 |
private/
|
|
95 |
public/
|
|
96 |
||
97 |
you may have write access in 'private' and 'public' but in 'Project'
|
|
98 |
itself. In that case, you can add the following in your locations.conf or
|
|
99 |
branch.conf file:
|
|
100 |
||
101 |
upload_revid_location = private/.bzr-upload.revid
|
|
102 |
||
103 |
||
104 |
Upload from Remote Location
|
|
105 |
---------------------------
|
|
106 |
||
107 |
It is possible to upload to a remote location from another remote location by
|
|
108 |
specifying it with the --directory option:
|
|
109 |
||
110 |
bzr upload ftp://public.example.com --directory sftp://private.example.com
|
|
111 |
||
112 |
This, together with --auto, can be used to upload when you push to your
|
|
113 |
central branch, rather than when you commit to your local branch.
|
|
114 |
||
115 |
Note that you will consume more bandwith this way than uploading from a local
|
|
116 |
branch.
|
|
117 |
||
66.1.5
by Martin Albisetti
Add docs |
118 |
Ignoring certain files
|
119 |
-----------------------
|
|
120 |
||
121 |
If you want to version a file, but not upload it, you can create a file called
|
|
122 |
.bzrignore-upload, which works in the same way as the regular .bzrignore file,
|
|
123 |
but only applies to bzr-upload.
|
|
124 |
||
125 |
||
63
by Vincent Ladeuil
Make the doc more easily discoverable. |
126 |
Collaborating
|
127 |
-------------
|
|
128 |
||
129 |
While we don't have any platform setup, you can branch from trunk:
|
|
130 |
||
131 |
bzr branch lp:bzr-upload
|
|
132 |
||
66.1.5
by Martin Albisetti
Add docs |
133 |
And change anything you'd like, and file a merge proposal on Launchpad.
|
63
by Vincent Ladeuil
Make the doc more easily discoverable. |
134 |
|
135 |
||
136 |
Known Issues
|
|
137 |
------------
|
|
138 |
||
74.1.1
by Vincent Ladeuil
Emit warnings instead of crashing when symlinks are encountered |
139 |
* Symlinks are not supported (warnings are emitted when they are encountered).
|
63
by Vincent Ladeuil
Make the doc more easily discoverable. |
140 |
|
141 |
||
6
by Vincent Ladeuil
Really use the transports and test against all targeted protocols. |
142 |
"""
|
1
by Vincent Ladeuil
Empty shell |
143 |
|
17
by Vincent Ladeuil
Handle deletes (trivial implementation). |
144 |
# TODO: the chmod bits *can* be supported via the upload protocols
|
145 |
# (i.e. poorly), but since the web developers use these protocols to upload
|
|
146 |
# manually, it is expected that the associated web server is coherent with
|
|
147 |
# their presence/absence. In other words, if a web hosting provider requires
|
|
148 |
# chmod bits but don't provide an ftp server that support them, well, better
|
|
149 |
# find another provider ;-)
|
|
150 |
||
44
by Vincent Ladeuil
More robust full upload (at least regarding files changed to dirs and vice-versa). |
151 |
# TODO: The message emitted in verbose mode displays local paths. That may be
|
152 |
# scary for the user when we say 'Deleting <path>' and are referring to
|
|
153 |
# remote files...
|
|
19
by Vincent Ladeuil
Handle kind_change. Trivial implementation, blocked by bug #205636. |
154 |
|
93
by Vincent Ladeuil
Migrate to config stacks |
155 |
|
78
by Vincent Ladeuil
Prepare 1.0.0 release by being a better packager and bzr citizen. |
156 |
import bzrlib |
78.1.1
by Jelmer Vernooij
Support lazily loading. |
157 |
from bzrlib import ( |
93
by Vincent Ladeuil
Migrate to config stacks |
158 |
api, |
78.1.1
by Jelmer Vernooij
Support lazily loading. |
159 |
branch, |
93
by Vincent Ladeuil
Migrate to config stacks |
160 |
commands, |
161 |
config, |
|
78.1.1
by Jelmer Vernooij
Support lazily loading. |
162 |
)
|
163 |
||
78
by Vincent Ladeuil
Prepare 1.0.0 release by being a better packager and bzr citizen. |
164 |
from info import ( |
165 |
bzr_plugin_version as version_info, |
|
166 |
bzr_compatible_versions, |
|
167 |
)
|
|
168 |
||
169 |
if version_info[3] == 'final': |
|
170 |
version_string = '%d.%d.%d' % version_info[:3] |
|
171 |
else: |
|
172 |
version_string = '%d.%d.%d%s%d' % version_info |
|
173 |
__version__ = version_string |
|
174 |
||
93
by Vincent Ladeuil
Migrate to config stacks |
175 |
api.require_any_api(bzrlib, bzr_compatible_versions) |
176 |
||
177 |
||
178 |
def register_lazy_option(key, member): |
|
179 |
config.option_registry.register_lazy( |
|
180 |
key, 'bzrlib.plugins.upload.cmds', member) |
|
181 |
||
182 |
||
183 |
register_lazy_option('upload_auto', 'auto_option') |
|
184 |
register_lazy_option('upload_auto_quiet', 'auto_quiet_option') |
|
185 |
register_lazy_option('upload_location', 'location_option') |
|
186 |
register_lazy_option('upload_revid_location', 'revid_location_option') |
|
187 |
||
188 |
||
189 |
commands.plugin_cmds.register_lazy( |
|
190 |
'cmd_upload', [], 'bzrlib.plugins.upload.cmds') |
|
191 |
||
68
by Vincent Ladeuil
Cleanup some pending changes. |
192 |
|
72
by Vincent Ladeuil
Avoid the recursive loading to be able to BZR_PLUGINS_AT. |
193 |
def auto_upload_hook(params): |
78.1.1
by Jelmer Vernooij
Support lazily loading. |
194 |
from bzrlib import ( |
195 |
osutils, |
|
196 |
trace, |
|
197 |
transport, |
|
198 |
urlutils, |
|
199 |
)
|
|
200 |
from bzrlib.plugins.upload.cmds import ( |
|
201 |
BzrUploader, |
|
202 |
)
|
|
203 |
import sys |
|
72
by Vincent Ladeuil
Avoid the recursive loading to be able to BZR_PLUGINS_AT. |
204 |
source_branch = params.branch |
93
by Vincent Ladeuil
Migrate to config stacks |
205 |
conf = source_branch.get_config_stack() |
206 |
destination = conf.get('upload_location') |
|
72
by Vincent Ladeuil
Avoid the recursive loading to be able to BZR_PLUGINS_AT. |
207 |
if destination is None: |
208 |
return
|
|
93
by Vincent Ladeuil
Migrate to config stacks |
209 |
auto_upload = conf.get('upload_auto') |
72
by Vincent Ladeuil
Avoid the recursive loading to be able to BZR_PLUGINS_AT. |
210 |
if not auto_upload: |
211 |
return
|
|
93
by Vincent Ladeuil
Migrate to config stacks |
212 |
quiet = conf.get('upload_auto_quiet') |
72
by Vincent Ladeuil
Avoid the recursive loading to be able to BZR_PLUGINS_AT. |
213 |
if not quiet: |
214 |
display_url = urlutils.unescape_for_display( |
|
215 |
destination, osutils.get_terminal_encoding()) |
|
216 |
trace.note('Automatically uploading to %s', display_url) |
|
217 |
to_transport = transport.get_transport(destination) |
|
218 |
last_revision = source_branch.last_revision() |
|
219 |
last_tree = source_branch.repository.revision_tree(last_revision) |
|
220 |
uploader = BzrUploader(source_branch, to_transport, sys.stdout, |
|
221 |
last_tree, last_revision, quiet=quiet) |
|
222 |
uploader.upload_tree() |
|
223 |
||
224 |
||
61
by Vincent Ladeuil
Fix bug #312686 and add an 'upload_auto_quiet' config variable. |
225 |
def install_auto_upload_hook(): |
52.1.1
by James Westby
Don't try and register the hook if install_named_hook is not available |
226 |
branch.Branch.hooks.install_named_hook('post_change_branch_tip', |
72
by Vincent Ladeuil
Avoid the recursive loading to be able to BZR_PLUGINS_AT. |
227 |
auto_upload_hook, |
52.1.1
by James Westby
Don't try and register the hook if install_named_hook is not available |
228 |
'Auto upload code from a branch when it is changed.') |
61
by Vincent Ladeuil
Fix bug #312686 and add an 'upload_auto_quiet' config variable. |
229 |
|
230 |
||
82
by Vincent Ladeuil
``install_named_hook`` is available in bzr >= 2.2, no need to check anymore. Also remove some code left when loading lazily more aggressively. |
231 |
install_auto_upload_hook() |
49.1.2
by James Westby
Add a post_change_branch_tip hook to upload. |
232 |
|
233 |
||
29
by Vincent Ladeuil
Work around test fixture limitation regarding self.outf (cough). All tests passing again. |
234 |
def load_tests(basic_tests, module, loader): |
36.1.1
by Vincent Ladeuil
Clean up references to verbose. |
235 |
# This module shouldn't define any tests but I don't know how to report
|
38.1.1
by Vincent Ladeuil
Create a simple setup.py and rework tests modules accordingly. |
236 |
# that. I prefer to update basic_tests with the other tests to detect
|
237 |
# unwanted tests and I think that's sufficient.
|
|
1
by Vincent Ladeuil
Empty shell |
238 |
|
239 |
testmod_names = [ |
|
38.1.1
by Vincent Ladeuil
Create a simple setup.py and rework tests modules accordingly. |
240 |
'tests', |
1
by Vincent Ladeuil
Empty shell |
241 |
]
|
38.1.1
by Vincent Ladeuil
Create a simple setup.py and rework tests modules accordingly. |
242 |
basic_tests.addTest(loader.loadTestsFromModuleNames( |
1
by Vincent Ladeuil
Empty shell |
243 |
["%s.%s" % (__name__, tmn) for tmn in testmod_names])) |
38.1.1
by Vincent Ladeuil
Create a simple setup.py and rework tests modules accordingly. |
244 |
return basic_tests |