~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to bzrtools.py

  • Committer: Aaron Bentley
  • Date: 2006-07-05 05:32:42 UTC
  • Revision ID: aaron.bentley@utoronto.ca-20060705053242-b9bbea9d1acd32d6
Make Ellerman's cdiff colours the default

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
import bzrlib.errors
28
28
from bzrlib.errors import (BzrCommandError, NotBranchError, NoSuchFile,
29
29
                           UnsupportedFormatError, TransportError, 
30
 
                           NoWorkingTree)
 
30
                           NoWorkingTree, PermissionDenied)
31
31
from bzrlib.bzrdir import BzrDir, BzrDirFormat
32
32
 
33
33
def temp_tree():
52
52
    ([u'foo'], {})
53
53
    >>> is_clean(tree)
54
54
    (False, [])
55
 
    >>> tree.commit("added file")
 
55
    >>> tree.commit("added file", rev_id='commit-id')
 
56
    'commit-id'
56
57
    >>> is_clean(tree)
57
58
    (True, [])
58
59
    >>> rm_tree(tree)
68
69
    return not delta.has_changed(), non_source
69
70
 
70
71
def set_push_data(tree, location):
71
 
    push_file = file (tree.branch.control_files.controlfilename("x-push-data"), "wb")
72
 
    push_file.write("%s\n" % location)
 
72
    tree.branch.control_files.put_utf8("x-push-data", "%s\n" % location)
73
73
 
74
74
def get_push_data(tree):
75
75
    """
78
78
    True
79
79
    >>> set_push_data(tree, 'http://somewhere')
80
80
    >>> get_push_data(tree)
81
 
    'http://somewhere'
 
81
    u'http://somewhere'
82
82
    >>> rm_tree(tree)
83
83
    """
84
 
    filename = tree.branch.control_files.controlfilename("x-push-data")
85
 
    if not os.path.exists(filename):
 
84
    try:
 
85
        location = tree.branch.control_files.get_utf8('x-push-data').read()
 
86
    except NoSuchFile:
86
87
        return None
87
 
    push_file = file (filename, "rb")
88
 
    (location,) = [f.rstrip('\n') for f in push_file]
89
 
    return location
 
88
    return location.rstrip('\n')
90
89
 
91
90
"""
92
91
>>> shell_escape('hello')
241
240
    except RsyncNoFile:
242
241
        return True
243
242
 
244
 
def push(tree, location=None, overwrite=False, working_tree=True):
 
243
def rspush(tree, location=None, overwrite=False, working_tree=True):
245
244
    push_location = get_push_data(tree)
246
245
    if location is not None:
247
246
        if not location.endswith('/'):
249
248
        push_location = location
250
249
    
251
250
    if push_location is None:
252
 
        if tree.branch.get_push_location() is None:
253
 
            raise BzrCommandError("No push location known or specified.")
254
 
        else:
255
 
            raise bzrlib.errors.MustUseDecorated
256
 
 
257
 
    if push_location.find('://') != -1:
258
 
        raise bzrlib.errors.MustUseDecorated
259
 
 
260
 
    if push_location.find(':') == -1:
261
 
        raise bzrlib.errors.MustUseDecorated
 
251
        raise BzrCommandError("No rspush location known or specified.")
 
252
 
 
253
    if (push_location.find('://') != -1 or
 
254
        push_location.find(':') == -1):
 
255
        raise BzrCommandError("Invalid rsync path %r." % push_location)
262
256
 
263
257
    if working_tree:
264
258
        clean, non_source = is_clean(tree)
305
299
 
306
300
def apache_ls(t):
307
301
    """Screen-scrape Apache listings"""
308
 
    apache_dir = '<IMG border="0" src="/icons/folder.gif" ALT="[DIR]">'\
309
 
        ' <A HREF="'
 
302
    apache_dir = '<img border="0" src="/icons/folder.gif" alt="[dir]">'\
 
303
        ' <a href="'
310
304
    lines = t.get('.')
 
305
    expr = re.compile('<a[^>]*href="([^>]*)"[^>]*>', flags=re.I)
311
306
    for line in lines:
312
 
        if line.startswith(apache_dir):
313
 
            url = line[len(apache_dir):].split('"')[0]
314
 
            yield url.rstrip('/')
 
307
        match = expr.search(line)
 
308
        if match is None:
 
309
            continue
 
310
        url = match.group(1)
 
311
        if url.startswith('http://') or url.startswith('/') or '../' in url:
 
312
            continue
 
313
        if '?' in url:
 
314
            continue
 
315
        yield url.rstrip('/')
315
316
 
316
317
 
317
318
def iter_branches(t, lister=None):
338
339
            except (NotBranchError, UnsupportedFormatError):
339
340
                continue
340
341
 
 
342
 
341
343
def iter_bzrdirs(t, lister=None):
342
344
    if lister is None:
343
345
        def lister(t):
345
347
    try:
346
348
        bzrdir = bzrdir_from_transport(t)
347
349
        yield bzrdir
348
 
    except (NotBranchError, UnsupportedFormatError, TransportError):
 
350
    except (NotBranchError, UnsupportedFormatError, TransportError,
 
351
            PermissionDenied):
349
352
        pass
350
353
    try:
351
354
        for directory in lister(t):
352
355
            if directory == ".bzr":
353
356
                continue
354
 
            subt = t.clone(directory)
355
 
            for bzrdir in iter_bzrdirs(subt):
 
357
            try:
 
358
                subt = t.clone(directory)
 
359
            except UnicodeDecodeError:
 
360
                continue
 
361
            for bzrdir in iter_bzrdirs(subt, lister):
356
362
                yield bzrdir
357
 
    except NoSuchFile:
358
 
        pass
359
 
    except TransportError, e:
 
363
    except (NoSuchFile, PermissionDenied, TransportError):
360
364
        pass
361
365
 
362
366