/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.152.72 by Vincent Ladeuil
Avoid the recursive loading to be able to BZR_PLUGINS_AT.
1
# Copyright (C) 2008, 2009, 2010 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
0.152.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
0.159.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
0.152.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
0.152.17 by Vincent Ladeuil
Handle deletes (trivial implementation).
82
The only bzr-related info uploaded with the working tree is the corresponding
0.152.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
0.152.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
0.160.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
0.152.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
0.160.5 by Martin Albisetti
Add docs
133
And change anything you'd like, and file a merge proposal on Launchpad.
0.152.63 by Vincent Ladeuil
Make the doc more easily discoverable.
134
135
136
Known Issues
137
------------
138
0.162.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).
0.152.63 by Vincent Ladeuil
Make the doc more easily discoverable.
140
141
0.152.6 by Vincent Ladeuil
Really use the transports and test against all targeted protocols.
142
"""
0.152.1 by Vincent Ladeuil
Empty shell
143
0.152.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
0.152.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...
0.152.19 by Vincent Ladeuil
Handle kind_change. Trivial implementation, blocked by bug #205636.
154
0.152.78 by Vincent Ladeuil
Prepare 1.0.0 release by being a better packager and bzr citizen.
155
import bzrlib
156
import bzrlib.api
157
0.165.1 by Jelmer Vernooij
Support lazily loading.
158
from bzrlib import (
159
    branch,
160
    )
161
0.152.78 by Vincent Ladeuil
Prepare 1.0.0 release by being a better packager and bzr citizen.
162
from info import (
163
    bzr_plugin_version as version_info,
164
    bzr_compatible_versions,
165
    )
166
167
if version_info[3] == 'final':
168
    version_string = '%d.%d.%d' % version_info[:3]
169
else:
170
    version_string = '%d.%d.%d%s%d' % version_info
171
__version__ = version_string
172
173
bzrlib.api.require_any_api(bzrlib, bzr_compatible_versions)
174
0.165.1 by Jelmer Vernooij
Support lazily loading.
175
from bzrlib.commands import plugin_cmds
176
177
plugin_cmds.register_lazy('cmd_upload', [], 'bzrlib.plugins.upload.cmds')
0.152.68 by Vincent Ladeuil
Cleanup some pending changes.
178
0.152.72 by Vincent Ladeuil
Avoid the recursive loading to be able to BZR_PLUGINS_AT.
179
def auto_upload_hook(params):
0.165.1 by Jelmer Vernooij
Support lazily loading.
180
    from bzrlib import (
181
        osutils,
182
        trace,
183
        transport,
184
        urlutils,
185
        )
186
    from bzrlib.plugins.upload.cmds import (
187
        BzrUploader,
188
        get_upload_location,
189
        get_upload_auto,
190
        get_upload_auto_quiet,
191
        )
192
    import sys
0.152.72 by Vincent Ladeuil
Avoid the recursive loading to be able to BZR_PLUGINS_AT.
193
    source_branch = params.branch
194
    destination = get_upload_location(source_branch)
195
    if destination is None:
196
        return
197
    auto_upload = get_upload_auto(source_branch)
198
    if not auto_upload:
199
        return
200
    quiet = get_upload_auto_quiet(source_branch)
201
    if not quiet:
202
        display_url = urlutils.unescape_for_display(
203
            destination, osutils.get_terminal_encoding())
204
        trace.note('Automatically uploading to %s', display_url)
205
    to_transport = transport.get_transport(destination)
206
    last_revision = source_branch.last_revision()
207
    last_tree = source_branch.repository.revision_tree(last_revision)
208
    uploader = BzrUploader(source_branch, to_transport, sys.stdout,
209
                           last_tree, last_revision, quiet=quiet)
210
    uploader.upload_tree()
211
212
0.152.61 by Vincent Ladeuil
Fix bug #312686 and add an 'upload_auto_quiet' config variable.
213
def install_auto_upload_hook():
0.157.1 by James Westby
Don't try and register the hook if install_named_hook is not available
214
    branch.Branch.hooks.install_named_hook('post_change_branch_tip',
0.152.72 by Vincent Ladeuil
Avoid the recursive loading to be able to BZR_PLUGINS_AT.
215
            auto_upload_hook,
0.157.1 by James Westby
Don't try and register the hook if install_named_hook is not available
216
            'Auto upload code from a branch when it is changed.')
0.152.61 by Vincent Ladeuil
Fix bug #312686 and add an 'upload_auto_quiet' config variable.
217
218
0.152.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.
219
install_auto_upload_hook()
0.155.2 by James Westby
Add a post_change_branch_tip hook to upload.
220
221
0.152.29 by Vincent Ladeuil
Work around test fixture limitation regarding self.outf (cough). All tests passing again.
222
def load_tests(basic_tests, module, loader):
0.153.1 by Vincent Ladeuil
Clean up references to verbose.
223
    # This module shouldn't define any tests but I don't know how to report
0.154.1 by Vincent Ladeuil
Create a simple setup.py and rework tests modules accordingly.
224
    # that. I prefer to update basic_tests with the other tests to detect
225
    # unwanted tests and I think that's sufficient.
0.152.1 by Vincent Ladeuil
Empty shell
226
227
    testmod_names = [
0.154.1 by Vincent Ladeuil
Create a simple setup.py and rework tests modules accordingly.
228
        'tests',
0.152.1 by Vincent Ladeuil
Empty shell
229
        ]
0.154.1 by Vincent Ladeuil
Create a simple setup.py and rework tests modules accordingly.
230
    basic_tests.addTest(loader.loadTestsFromModuleNames(
0.152.1 by Vincent Ladeuil
Empty shell
231
            ["%s.%s" % (__name__, tmn) for tmn in testmod_names]))
0.154.1 by Vincent Ladeuil
Create a simple setup.py and rework tests modules accordingly.
232
    return basic_tests