~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to bzrtools.py

  • Committer: Aaron Bentley
  • Date: 2007-08-14 20:19:46 UTC
  • Revision ID: abentley@panoramicfeedback.com-20070814201946-0sakbyeb2zb533uf
Remove branch-mark command

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
import sys
25
25
 
26
26
import bzrlib
 
27
from bzrlib import urlutils
27
28
import bzrlib.errors
28
29
from bzrlib.errors import (BzrCommandError, NotBranchError, NoSuchFile,
29
 
                           UnsupportedFormatError, TransportError, 
30
 
                           NoWorkingTree, PermissionDenied)
 
30
                           UnsupportedFormatError, TransportError,
 
31
                           NoWorkingTree, PermissionDenied, ConnectionError)
31
32
from bzrlib.bzrdir import BzrDir, BzrDirFormat
 
33
from bzrlib.transport import get_transport
32
34
 
33
35
def temp_tree():
34
36
    dirname = tempfile.mkdtemp("temp-branch")
99
101
    def __init__(self, rsync_name):
100
102
        Exception.__init__(self, "%s not found." % rsync_name)
101
103
 
102
 
def rsync(source, target, ssh=False, excludes=(), silent=False, 
 
104
def rsync(source, target, ssh=False, excludes=(), silent=False,
103
105
          rsync_name="rsync"):
104
106
    """
105
107
    >>> new_dir = tempfile.mkdtemp()
134
136
    except OSError, e:
135
137
        if e.errno == errno.ENOENT:
136
138
            raise NoRsync(rsync_name)
137
 
            
 
139
 
138
140
    proc.stdin.write('\n'.join(excludes)+'\n')
139
141
    proc.stdin.close()
140
142
    if silent:
176
178
        raise RsyncUnknownStatus(proc.returncode)
177
179
    return [l.split(' ')[-1].rstrip('\n') for l in result.splitlines(True)]
178
180
 
179
 
exclusions = ('.bzr/x-push-data', '.bzr/branch/x-push/data', '.bzr/parent', 
 
181
exclusions = ('.bzr/x-push-data', '.bzr/branch/x-push/data', '.bzr/parent',
180
182
              '.bzr/branch/parent', '.bzr/x-pull-data', '.bzr/x-pull',
181
183
              '.bzr/pull', '.bzr/stat-cache', '.bzr/x-rsync-data',
182
184
              '.bzr/basis-inventory', '.bzr/inventory.backup.weave')
216
218
        return False
217
219
    for local, remote in zip(remote_history, local_history):
218
220
        if local != remote:
219
 
            return False 
 
221
            return False
220
222
    return True
221
223
 
222
224
def empty_or_absent(location):
232
234
        if not location.endswith('/'):
233
235
            location += '/'
234
236
        push_location = location
235
 
    
 
237
 
236
238
    if push_location is None:
237
239
        raise BzrCommandError("No rspush location known or specified.")
238
240
 
275
277
                " specified location.  Please ensure that"
276
278
                ' "%s" is of the form "machine:/path".' % push_location)
277
279
    print "Pushing to %s" % push_location
278
 
    rsync(tree.basedir+'/', push_location, ssh=usessh, 
 
280
    rsync(tree.basedir+'/', push_location, ssh=usessh,
279
281
          excludes=final_exclusions)
280
282
 
281
283
    set_push_data(tree, push_location)
292
294
    """Screen-scrape Apache listings"""
293
295
    apache_dir = '<img border="0" src="/icons/folder.gif" alt="[dir]">'\
294
296
        ' <a href="'
295
 
    lines = t.get('.')
 
297
    t = t.clone()
 
298
    t._remote_path = lambda x: t.base
 
299
    lines = t.get('')
296
300
    expr = re.compile('<a[^>]*href="([^>]*)"[^>]*>', flags=re.I)
297
301
    for line in lines:
298
302
        match = expr.search(line)
338
342
    try:
339
343
        bzrdir = bzrdir_from_transport(t)
340
344
        yield bzrdir
 
345
    except (ConnectionError):
 
346
        raise
341
347
    except (NotBranchError, UnsupportedFormatError, TransportError,
342
348
            PermissionDenied):
343
349
        pass
354
360
    except (NoSuchFile, PermissionDenied, TransportError):
355
361
        pass
356
362
 
357
 
    
 
363
 
358
364
def bzrdir_from_transport(t):
359
365
    """Open a bzrdir from a transport (not a location)"""
360
366
    format = BzrDirFormat.find_format(t)
362
368
    return format.open(t)
363
369
 
364
370
 
 
371
def open_from_url(location):
 
372
    location = urlutils.normalize_url(location)
 
373
    dirname, basename = urlutils.split(location)
 
374
    return get_transport(dirname).get(basename)
 
375
 
 
376
 
365
377
def run_tests():
366
378
    import doctest
367
379
    result = doctest.testmod()