~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to plugins/rsync/__init__.py

  • Committer: Martin Pool
  • Date: 2005-07-04 08:06:51 UTC
  • Revision ID: mbp@sourcefrog.net-20050704080651-6ecec49164359e48
- track pending-merges

- unit tests for this

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
"""\
 
3
This is a plugin for the Bazaar-NG revision control system.
 
4
"""
 
5
 
 
6
import os
 
7
import bzrlib, bzrlib.commands
 
8
 
 
9
class cmd_rsync_pull(bzrlib.commands.Command):
 
10
    """Update the current working tree using rsync.
 
11
    With no arguments, look for a .bzr/x-rsync-location file
 
12
    to determine which remote system to rsync from.
 
13
    Otherwise, you can specify a new location to rsync from.
 
14
 
 
15
    Normally the first time you use it, you would write:
 
16
        bzr rsync-pull . path/to/otherdirectory
 
17
    """
 
18
    takes_args = ['local?', 'remote?']
 
19
    takes_options = ['verbose']
 
20
    aliases = ['rpull']
 
21
 
 
22
    def run(self, local=None, remote=None, verbose=True):
 
23
        from rsync_update import get_branch_remote_update, \
 
24
            check_should_pull, set_default_remote_info, pull
 
25
 
 
26
        b, remote, last_revno, last_revision = \
 
27
            get_branch_remote_update(local=local, remote=remote)
 
28
 
 
29
        if not check_should_pull(b, last_revno, last_revision):
 
30
            return 1
 
31
        b = pull(b, remote, verbose=verbose)
 
32
 
 
33
        set_default_remote_info(b, remote)
 
34
 
 
35
class cmd_rsync_pull_bzr(cmd_rsync_pull):
 
36
    takes_args = ['remote?']
 
37
    def run(self, remote=None, verbose=True):
 
38
        from rsync_update import get_branch_remote_update, \
 
39
            check_should_pull, set_default_remote_info, pull
 
40
 
 
41
        bzr_path = os.path.dirname(bzrlib.__path__[0])
 
42
        b, remote, last_revno, last_revision = \
 
43
            get_branch_remote_update(local=bzr_path, remote=remote
 
44
                , alt_remote='bazaar-ng.org::bazaar-ng/bzr/bzr.dev/')
 
45
 
 
46
        if not check_should_pull(b, last_revno, last_revision):
 
47
            return 1
 
48
        b = pull(b, remote, verbose=verbose)
 
49
 
 
50
        set_default_remote_info(b, remote)
 
51
 
 
52
class cmd_rsync_push(bzrlib.commands.Command):
 
53
    """Update the remote tree using rsync.
 
54
    With no arguments, look for a .bzr/x-rsync-location file
 
55
    to determine which remote system to rsync to.
 
56
    Otherwise, you can specify a new location to rsync to.
 
57
    """
 
58
    takes_args = ['local?', 'remote?']
 
59
    takes_options = ['verbose']
 
60
    aliases = ['rpush']
 
61
 
 
62
    def run(self, local=None, remote=None, verbose=True):
 
63
        from rsync_update import get_branch_remote_update, \
 
64
            check_should_push, set_default_remote_info, push
 
65
 
 
66
        b, remote, last_revno, last_revision = \
 
67
            get_branch_remote_update(local=local, remote=remote)
 
68
 
 
69
        if not check_should_push(b, last_revno, last_revision):
 
70
            return 1
 
71
 
 
72
        push(b, remote, verbose=verbose)
 
73
 
 
74
        set_default_remote_info(b, remote)
 
75
 
 
76
 
 
77
if hasattr(bzrlib.commands, 'register_plugin_command'):
 
78
    bzrlib.commands.register_plugin_command(cmd_rsync_pull)
 
79
    bzrlib.commands.register_plugin_command(cmd_rsync_pull_bzr)
 
80
    bzrlib.commands.register_plugin_command(cmd_rsync_push)
 
81
elif hasattr(bzrlib.commands, 'register_command'):
 
82
    bzrlib.commands.register_command(cmd_rsync_pull)
 
83
    bzrlib.commands.register_command(cmd_rsync_pull_bzr)
 
84
    bzrlib.commands.register_command(cmd_rsync_push)
 
85