~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to scriptlib.py

  • Committer: abentley
  • Date: 2005-05-02 07:04:00 UTC
  • Revision ID: abentley@lappy-20050502070400-d14eee47272c8cdf
added bzr-push command

Show diffs side-by-side

added added

removed removed

Lines of Context:
59
59
    location, rev_id = [f.rstrip('\n') for f in pull_file]
60
60
    return location, rev_id
61
61
 
 
62
def set_push_data(br, location):
 
63
    push_file = file (br.controlfilename("x-push-data"), "wb")
 
64
    push_file.write("%s\n" % location)
 
65
 
 
66
def get_push_data(br):
 
67
    """
 
68
    >>> br = temp_branch()
 
69
    >>> get_push_data(br) is None
 
70
    True
 
71
    >>> set_push_data(br, 'http://somewhere')
 
72
    >>> get_push_data(br)
 
73
    'http://somewhere'
 
74
    >>> rm_branch(br)
 
75
    """
 
76
    filename = br.controlfilename("x-push-data")
 
77
    if not os.path.exists(filename):
 
78
        return None
 
79
    push_file = file (filename, "rb")
 
80
    (location,) = [f.rstrip('\n') for f in push_file]
 
81
    return location
 
82
 
62
83
"""
63
84
>>> shell_escape('hello')
64
85
'\h\e\l\l\o'
77
98
    arg_str = " ".join([shell_escape(a) for a in args])
78
99
    return os.system(arg_str)
79
100
 
80
 
def rsync(source, target):
 
101
def rsync(source, target, ssh=False):
81
102
    """
82
103
    >>> real_system = os.system
83
104
    >>> os.system = sys.stdout.write
85
106
    \\r\\s\\y\\n\\c \\-\\a\\v \\-\\-\\d\\e\\l\\e\\t\\e \\a \\b
86
107
    >>> os.system = real_system
87
108
    """
88
 
    safe_system(("rsync", "-av", "--delete", source, target))
 
109
    cmd = ["rsync", "-av", "--delete"]
 
110
    if ssh:
 
111
        cmd.extend(('-e', 'ssh'))
 
112
    cmd.extend((source, target))
 
113
    safe_system(cmd)
89
114
 
90
115
def pull(cur_branch, location=None):
91
116
    pull_location, pull_revision = get_pull_data(cur_branch)
111
136
 
112
137
    set_pull_data(cur_branch, pull_location, cur_branch.last_patch())
113
138
 
 
139
 
 
140
def push(cur_branch, location=None):
 
141
    push_location = get_push_data(cur_branch)
 
142
    if location is not None:
 
143
        push_location = location
 
144
    
 
145
    if push_location is None:
 
146
        print "No push location saved.  Please specify one on the command line."
 
147
        sys.exit(1)
 
148
 
 
149
    if not is_clean(cur_branch):
 
150
        print "Error: This tree has uncommitted changes or unknown (?) files."
 
151
        sys.exit(1)
 
152
 
 
153
    print "Pushing to %s" % push_location
 
154
    rsync (cur_branch.base, push_location, ssh=True)
 
155
 
 
156
    set_push_data(cur_branch, push_location)
 
157
 
114
158
def run_tests():
115
159
    import doctest
116
160
    bzrlib.trace.create_tracefile([])