/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
0.152.61 by Vincent Ladeuil
Fix bug #312686 and add an 'upload_auto_quiet' config variable.
1
# Copyright (C) 2008, 2009 Canonical Ltd
0.155.2 by James Westby
Add a post_change_branch_tip hook to upload.
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
import sys
18
19
0.152.61 by Vincent Ladeuil
Fix bug #312686 and add an 'upload_auto_quiet' config variable.
20
from bzrlib import (
21
    branch,
22
    osutils,
23
    trace,
24
    transport,
25
    urlutils,
26
    )
27
28
29
def auto_upload_hook(params):
30
    from bzrlib.plugins import upload
0.155.2 by James Westby
Add a post_change_branch_tip hook to upload.
31
    source_branch = params.branch
0.152.61 by Vincent Ladeuil
Fix bug #312686 and add an 'upload_auto_quiet' config variable.
32
    destination = upload.get_upload_location(source_branch)
0.155.2 by James Westby
Add a post_change_branch_tip hook to upload.
33
    if destination is None:
34
        return
0.152.61 by Vincent Ladeuil
Fix bug #312686 and add an 'upload_auto_quiet' config variable.
35
    auto_upload = upload.get_upload_auto(source_branch)
0.155.3 by James Westby
Add some tests for the hook, rename the option to "upload_auto"
36
    if not auto_upload:
0.155.2 by James Westby
Add a post_change_branch_tip hook to upload.
37
        return
0.152.61 by Vincent Ladeuil
Fix bug #312686 and add an 'upload_auto_quiet' config variable.
38
    quiet = upload.get_upload_auto_quiet(source_branch)
0.155.3 by James Westby
Add some tests for the hook, rename the option to "upload_auto"
39
    if not quiet:
0.152.61 by Vincent Ladeuil
Fix bug #312686 and add an 'upload_auto_quiet' config variable.
40
        display_url = urlutils.unescape_for_display(
41
            destination, osutils.get_terminal_encoding())
42
        trace.note('Automatically uploading to %s', display_url)
0.155.2 by James Westby
Add a post_change_branch_tip hook to upload.
43
    to_transport = transport.get_transport(destination)
44
    last_revision = source_branch.last_revision()
45
    last_tree = source_branch.repository.revision_tree(last_revision)
0.152.61 by Vincent Ladeuil
Fix bug #312686 and add an 'upload_auto_quiet' config variable.
46
    uploader = upload.BzrUploader(source_branch, to_transport, sys.stdout,
47
                                  last_tree, last_revision, quiet=quiet)
0.155.2 by James Westby
Add a post_change_branch_tip hook to upload.
48
    uploader.upload_tree()