~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/win32utils.py

  • Committer: Martin Pool
  • Date: 2010-04-01 04:41:18 UTC
  • mto: This revision was merged to the branch mainline in revision 5128.
  • Revision ID: mbp@sourcefrog.net-20100401044118-shyctqc02ob08ngz
ignore .testrepository

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 
22
22
import glob
23
23
import os
 
24
import re
24
25
import struct
25
26
import sys
26
27
 
522
523
            trace.mutter('Unable to set hidden attribute on %r: %s', path, e)
523
524
 
524
525
 
525
 
def _command_line_to_argv(command_line, argv, single_quotes_allowed=False):
 
526
def _command_line_to_argv(command_line, single_quotes_allowed=False):
526
527
    """Convert a Unicode command line into a list of argv arguments.
527
528
 
528
529
    It performs wildcard expansion to make wildcards act closer to how they
535
536
                                  default.
536
537
    :return: A list of unicode strings.
537
538
    """
538
 
    # First, spit the command line
539
539
    s = cmdline.Splitter(command_line, single_quotes_allowed=single_quotes_allowed)
540
 
    
541
 
    # Bug #587868 Now make sure that the length of s agrees with sys.argv 
542
 
    # we do this by simply counting the number of arguments in each. The counts should 
543
 
    # agree no matter what encoding sys.argv is in (AFAIK) 
544
 
    # len(arguments) < len(sys.argv) should be an impossibility since python gets 
545
 
    # args from the very same PEB as does GetCommandLineW
546
 
    arguments = list(s)
547
 
    
548
 
    # Now shorten the command line we get from GetCommandLineW to match sys.argv
549
 
    if len(arguments) < len(argv):
550
 
        raise AssertionError("Split command line can't be shorter than argv")
551
 
    arguments = arguments[len(arguments) - len(argv):]
552
 
    
553
 
    # Carry on to process globs (metachars) in the command line
554
 
    # expand globs if necessary
 
540
    # Now that we've split the content, expand globs if necessary
555
541
    # TODO: Use 'globbing' instead of 'glob.glob', this gives us stuff like
556
542
    #       '**/' style globs
557
543
    args = []
558
 
    for is_quoted, arg in arguments:
 
544
    for is_quoted, arg in s:
559
545
        if is_quoted or not glob.has_magic(arg):
560
546
            args.append(arg)
561
547
        else:
572
558
        if command_line is None:
573
559
            raise ctypes.WinError()
574
560
        # Skip the first argument, since we only care about parameters
575
 
        argv = _command_line_to_argv(command_line, sys.argv)[1:]
 
561
        argv = _command_line_to_argv(command_line)[1:]
 
562
        if getattr(sys, 'frozen', None) is None:
 
563
            # Invoked via 'python.exe' which takes the form:
 
564
            #   python.exe [PYTHON_OPTIONS] C:\Path\bzr [BZR_OPTIONS]
 
565
            # we need to get only BZR_OPTIONS part,
 
566
            # We already removed 'python.exe' so we remove everything up to and
 
567
            # including the first non-option ('-') argument.
 
568
            for idx in xrange(len(argv)):
 
569
                if argv[idx][:1] != '-':
 
570
                    break
 
571
            argv = argv[idx+1:]
576
572
        return argv
577
573
else:
578
574
    get_unicode_argv = None