~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/win32utils.py

  • Committer: John Arbash Meinel
  • Date: 2009-11-04 22:12:46 UTC
  • mto: This revision was merged to the branch mainline in revision 4787.
  • Revision ID: john@arbash-meinel.com-20091104221246-xkbux8f428u9hn5i
Refactor the glob_expand code a bit, making the inner function more reusable.

For now backslash is always translated back into forward slash.

Show diffs side-by-side

added added

removed removed

Lines of Context:
426
426
 
427
427
 
428
428
 
 
429
def glob_one(possible_glob):
 
430
    """Same as glob.glob().
 
431
 
 
432
    work around bugs in glob.glob()
 
433
    - Python bug #1001604 ("glob doesn't return unicode with ...")
 
434
    - failing expansion for */* with non-iso-8859-* chars
 
435
    """
 
436
    corrected_glob, corrected = _ensure_with_dir(possible_glob)
 
437
    glob_files = glob.glob(corrected_glob)
 
438
 
 
439
    if not glob_files:
 
440
        # special case to let the normal code path handle
 
441
        # files that do not exist, etc.
 
442
        glob_files = [possible_glob]
 
443
    elif corrected:
 
444
        glob_files = [_undo_ensure_with_dir(elem, corrected)
 
445
                      for elem in glob_files]
 
446
    return [elem.replace(u'\\', u'/') for elem in glob_files]
 
447
 
 
448
 
429
449
def glob_expand(file_list):
430
450
    """Replacement for glob expansion by the shell.
431
451
 
441
461
        return []
442
462
    expanded_file_list = []
443
463
    for possible_glob in file_list:
444
 
        # work around bugs in glob.glob()
445
 
        # - Python bug #1001604 ("glob doesn't return unicode with ...")
446
 
        # - failing expansion for */* with non-iso-8859-* chars
447
 
        possible_glob, corrected = _ensure_with_dir(possible_glob)
448
 
        glob_files = glob.glob(possible_glob)
449
 
 
450
 
        if glob_files == []:
451
 
            # special case to let the normal code path handle
452
 
            # files that do not exists
453
 
            expanded_file_list.append(
454
 
                _undo_ensure_with_dir(possible_glob, corrected))
455
 
        else:
456
 
            glob_files = [_undo_ensure_with_dir(elem, corrected) for elem in glob_files]
457
 
            expanded_file_list += glob_files
458
 
 
459
 
    return [elem.replace(u'\\', u'/') for elem in expanded_file_list]
 
464
        expanded_file_list.extend(glob_one(possible_glob))
 
465
    return expanded_file_list
460
466
 
461
467
 
462
468
def get_app_path(appname):
625
631
    #       '**/' style globs
626
632
    args = []
627
633
    for is_quoted, arg in s:
628
 
        if is_quoted:
629
 
            args.append(arg)
 
634
        if is_quoted or not glob.has_magic(arg):
 
635
            args.append(arg.replace(u'\\', u'/'))
630
636
        else:
631
 
            args.extend(glob_expand([arg]))
 
637
            args.extend(glob_one(arg))
632
638
    return args
633
639
 
634
640