/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/plugins/upload/__init__.py

  • Committer: Breezy landing bot
  • Author(s): Jelmer Vernooij
  • Date: 2017-06-02 21:00:17 UTC
  • mfrom: (6645.2.3 bundle-upload)
  • Revision ID: breezy.the.bot@gmail.com-20170602210017-bes059arl227guzb
Bundle the 'upload' plugin.

Merged from https://code.launchpad.net/~jelmer/brz/bundle-upload/+merge/324986

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2008-2012 Canonical Ltd
 
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
 
 
17
"""Upload a working tree, incrementally.
 
18
 
 
19
Quickstart
 
20
----------
 
21
 
 
22
To get started, it's as simple as running::
 
23
 
 
24
    brz 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
    brz upload -r X  sftp://user@host/location/on/webserver
 
34
 
 
35
bzr-upload, just as brz 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
    brz upload --full sftp://user@host/location/on/webserver
 
41
 
 
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 'brz upload --overwrite' to replace
 
49
the other branch completely, discarding its unmerged changes.
 
50
 
 
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
     brz 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
     brz 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
 
 
82
The only bzr-related info uploaded with the working tree is the corresponding
 
83
revision id. The uploaded working tree is not linked to any other brz data.
 
84
 
 
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
    brz 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
 
 
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
 
 
126
Collaborating
 
127
-------------
 
128
 
 
129
While we don't have any platform setup, you can branch from trunk:
 
130
 
 
131
    brz branch lp:bzr-upload
 
132
 
 
133
And change anything you'd like, and file a merge proposal on Launchpad.
 
134
 
 
135
 
 
136
Known Issues
 
137
------------
 
138
 
 
139
 * Symlinks are not supported (warnings are emitted when they are encountered).
 
140
 
 
141
 
 
142
"""
 
143
 
 
144
from __future__ import absolute_import
 
145
 
 
146
# TODO: the chmod bits *can* be supported via the upload protocols
 
147
# (i.e. poorly), but since the web developers use these protocols to upload
 
148
# manually, it is expected that the associated web server is coherent with
 
149
# their presence/absence. In other words, if a web hosting provider requires
 
150
# chmod bits but don't provide an ftp server that support them, well, better
 
151
# find another provider ;-)
 
152
 
 
153
# TODO: The message emitted in verbose mode displays local paths. That may be
 
154
# scary for the user when we say 'Deleting <path>' and are referring to
 
155
# remote files...
 
156
 
 
157
 
 
158
import breezy
 
159
from ... import (
 
160
    commands,
 
161
    config,
 
162
    hooks,
 
163
    )
 
164
 
 
165
from ...hooks import install_lazy_named_hook
 
166
 
 
167
from ... import version_info
 
168
 
 
169
 
 
170
def register_option(key, member):
 
171
    """Lazily register an option."""
 
172
    config.option_registry.register_lazy(
 
173
        key, 'breezy.plugins.upload.cmds', member)
 
174
 
 
175
 
 
176
register_option('upload_auto', 'auto_option')
 
177
register_option('upload_auto_quiet', 'auto_quiet_option')
 
178
register_option('upload_location', 'location_option')
 
179
register_option('upload_revid_location', 'revid_location_option')
 
180
 
 
181
 
 
182
commands.plugin_cmds.register_lazy(
 
183
    'cmd_upload', [], 'breezy.plugins.upload.cmds')
 
184
 
 
185
 
 
186
def auto_upload_hook(params):
 
187
    from ... import (
 
188
        osutils,
 
189
        trace,
 
190
        transport,
 
191
        urlutils,
 
192
        )
 
193
    from .cmds import (
 
194
        BzrUploader,
 
195
        )
 
196
    import sys
 
197
    source_branch = params.branch
 
198
    conf = source_branch.get_config_stack()
 
199
    destination = conf.get('upload_location')
 
200
    if destination is None:
 
201
        return
 
202
    auto_upload = conf.get('upload_auto')
 
203
    if not auto_upload:
 
204
        return
 
205
    quiet = conf.get('upload_auto_quiet')
 
206
    if not quiet:
 
207
        display_url = urlutils.unescape_for_display(
 
208
            destination, osutils.get_terminal_encoding())
 
209
        trace.note('Automatically uploading to %s', display_url)
 
210
    to_transport = transport.get_transport(destination)
 
211
    last_revision = source_branch.last_revision()
 
212
    last_tree = source_branch.repository.revision_tree(last_revision)
 
213
    uploader = BzrUploader(source_branch, to_transport, sys.stdout,
 
214
                           last_tree, last_revision, quiet=quiet)
 
215
    uploader.upload_tree()
 
216
 
 
217
 
 
218
def install_auto_upload_hook():
 
219
    hooks.install_lazy_named_hook(
 
220
        'breezy.branch', 'Branch.hooks',
 
221
        'post_change_branch_tip', auto_upload_hook,
 
222
        'Auto upload code from a branch when it is changed.')
 
223
 
 
224
 
 
225
install_auto_upload_hook()
 
226
 
 
227
 
 
228
def load_tests(loader, basic_tests, pattern):
 
229
    # This module shouldn't define any tests but I don't know how to report
 
230
    # that. I prefer to update basic_tests with the other tests to detect
 
231
    # unwanted tests and I think that's sufficient.
 
232
 
 
233
    testmod_names = [
 
234
        'tests',
 
235
        ]
 
236
    basic_tests.addTest(loader.loadTestsFromModuleNames(
 
237
            ["%s.%s" % (__name__, tmn) for tmn in testmod_names]))
 
238
    return basic_tests