~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/win32utils.py

  • Committer: Martin Pool
  • Date: 2011-06-14 02:21:41 UTC
  • mto: This revision was merged to the branch mainline in revision 6001.
  • Revision ID: mbp@canonical.com-20110614022141-18hmm7s0iw3utcbj
Deprecate __contains__ on Tree and Inventory

Show diffs side-by-side

added added

removed removed

Lines of Context:
468
468
 
469
469
 
470
470
def get_app_path(appname):
471
 
    """Look up in Windows registry for full path to application executable.
 
471
    r"""Look up in Windows registry for full path to application executable.
472
472
    Typically, applications create subkey with their basename
473
473
    in HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\
474
474
 
522
522
            trace.mutter('Unable to set hidden attribute on %r: %s', path, e)
523
523
 
524
524
 
525
 
def _command_line_to_argv(command_line, single_quotes_allowed=False):
 
525
def _command_line_to_argv(command_line, argv, single_quotes_allowed=False):
526
526
    """Convert a Unicode command line into a list of argv arguments.
527
527
 
528
528
    It performs wildcard expansion to make wildcards act closer to how they
535
535
                                  default.
536
536
    :return: A list of unicode strings.
537
537
    """
 
538
    # First, spit the command line
538
539
    s = cmdline.Splitter(command_line, single_quotes_allowed=single_quotes_allowed)
539
 
    # Now that we've split the content, expand globs if necessary
 
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
555
    # TODO: Use 'globbing' instead of 'glob.glob', this gives us stuff like
541
556
    #       '**/' style globs
542
557
    args = []
543
 
    for is_quoted, arg in s:
 
558
    for is_quoted, arg in arguments:
544
559
        if is_quoted or not glob.has_magic(arg):
545
560
            args.append(arg)
546
561
        else:
557
572
        if command_line is None:
558
573
            raise ctypes.WinError()
559
574
        # Skip the first argument, since we only care about parameters
560
 
        argv = _command_line_to_argv(command_line)[1:]
561
 
        if getattr(sys, 'frozen', None) is None:
562
 
            # Invoked via 'python.exe' which takes the form:
563
 
            #   python.exe [PYTHON_OPTIONS] C:\Path\bzr [BZR_OPTIONS]
564
 
            # we need to get only BZR_OPTIONS part,
565
 
            # We already removed 'python.exe' so we remove everything up to and
566
 
            # including the first non-option ('-') argument.
567
 
            for idx in xrange(len(argv)):
568
 
                if argv[idx][:1] != '-':
569
 
                    break
570
 
            argv = argv[idx+1:]
 
575
        argv = _command_line_to_argv(command_line, sys.argv)[1:]
571
576
        return argv
572
577
else:
573
578
    get_unicode_argv = None