~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/win32utils.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-05-14 16:27:55 UTC
  • mfrom: (4355.2.5 cmdline)
  • Revision ID: pqm@pqm.ubuntu.com-20090514162755-t4q986mjos2ekecr
(bialix) Use get_unicode_argv() to properly handle Unicode arguments
        on windows.

Show diffs side-by-side

added added

removed removed

Lines of Context:
433
433
    import glob
434
434
    expanded_file_list = []
435
435
    for possible_glob in file_list:
436
 
 
437
436
        # work around bugs in glob.glob()
438
437
        # - Python bug #1001604 ("glob doesn't return unicode with ...")
439
438
        # - failing expansion for */* with non-iso-8859-* chars
488
487
    """Set file attributes to hidden if possible"""
489
488
    if has_win32file:
490
489
        win32file.SetFileAttributes(path, win32file.FILE_ATTRIBUTE_HIDDEN)
 
490
 
 
491
 
 
492
if has_ctypes and winver != 'Windows 98':
 
493
    def get_unicode_argv():
 
494
        LPCWSTR = ctypes.c_wchar_p
 
495
        INT = ctypes.c_int
 
496
        POINTER = ctypes.POINTER
 
497
        prototype = ctypes.WINFUNCTYPE(LPCWSTR)
 
498
        GetCommandLine = prototype(("GetCommandLineW",
 
499
                                    ctypes.windll.kernel32))
 
500
        prototype = ctypes.WINFUNCTYPE(POINTER(LPCWSTR), LPCWSTR, POINTER(INT))
 
501
        CommandLineToArgv = prototype(("CommandLineToArgvW",
 
502
                                       ctypes.windll.shell32))
 
503
        c = INT(0)
 
504
        pargv = CommandLineToArgv(GetCommandLine(), ctypes.byref(c))
 
505
        # Skip the first argument, since we only care about parameters
 
506
        argv = [pargv[i] for i in range(1, c.value)]
 
507
        if getattr(sys, 'frozen', None) is None:
 
508
            # Invoked via 'python.exe' which takes the form:
 
509
            #   python.exe [PYTHON_OPTIONS] C:\Path\bzr [BZR_OPTIONS]
 
510
            # we need to get only BZR_OPTIONS part,
 
511
            # so let's using sys.argv[1:] as reference to get the tail
 
512
            # of unicode argv
 
513
            tail_len = len(sys.argv[1:])
 
514
            ix = len(argv) - tail_len
 
515
            argv = argv[ix:]
 
516
        return argv
 
517
else:
 
518
    get_unicode_argv = None