~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/win32utils.py

  • Committer: Gordon Tyler
  • Date: 2010-02-02 06:30:43 UTC
  • mto: (5037.3.1 integration)
  • mto: This revision was merged to the branch mainline in revision 5046.
  • Revision ID: gordon@doxxx.net-20100202063043-3ygr1114d25m3f7m
Added cmdline.split function, which replaces commands.shlex_split_unicode.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd
 
1
# Copyright (C) 2006, 2007 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
21
21
 
22
22
import glob
23
23
import os
 
24
import re
24
25
import struct
25
26
import sys
26
27
 
135
136
                'WorkingSetSize': mem_struct.WorkingSetSize,
136
137
                'QuotaPeakPagedPoolUsage': mem_struct.QuotaPeakPagedPoolUsage,
137
138
                'QuotaPagedPoolUsage': mem_struct.QuotaPagedPoolUsage,
138
 
                'QuotaPeakNonPagedPoolUsage':
139
 
                    mem_struct.QuotaPeakNonPagedPoolUsage,
 
139
                'QuotaPeakNonPagedPoolUsage': mem_struct.QuotaPeakNonPagedPoolUsage,
140
140
                'QuotaNonPagedPoolUsage': mem_struct.QuotaNonPagedPoolUsage,
141
141
                'PagefileUsage': mem_struct.PagefileUsage,
142
142
                'PeakPagefileUsage': mem_struct.PeakPagefileUsage,
153
153
                   ' or win32process')
154
154
        return
155
155
    if short:
156
 
        # using base-2 units (see HACKING.txt).
157
 
        trace.note('WorkingSize %7dKiB'
158
 
                   '\tPeakWorking %7dKiB\t%s',
 
156
        trace.note('WorkingSize %7dKB'
 
157
                   '\tPeakWorking %7dKB\t%s',
159
158
                   info['WorkingSetSize'] / 1024,
160
159
                   info['PeakWorkingSetSize'] / 1024,
161
160
                   message)
162
161
        return
163
162
    if message:
164
163
        trace.note('%s', message)
165
 
    trace.note('WorkingSize       %8d KiB', info['WorkingSetSize'] / 1024)
166
 
    trace.note('PeakWorking       %8d KiB', info['PeakWorkingSetSize'] / 1024)
167
 
    trace.note('PagefileUsage     %8d KiB', info.get('PagefileUsage', 0) / 1024)
168
 
    trace.note('PeakPagefileUsage %8d KiB',
169
 
               info.get('PeakPagefileUsage', 0) / 1024)
170
 
    trace.note('PrivateUsage      %8d KiB', info.get('PrivateUsage', 0) / 1024)
 
164
    trace.note('WorkingSize       %8d KB', info['WorkingSetSize'] / 1024)
 
165
    trace.note('PeakWorking       %8d KB', info['PeakWorkingSetSize'] / 1024)
 
166
    trace.note('PagefileUsage     %8d KB', info.get('PagefileUsage', 0) / 1024)
 
167
    trace.note('PeakPagefileUsage %8d KB', info.get('PeakPagefileUsage', 0) / 1024)
 
168
    trace.note('PrivateUsage      %8d KB', info.get('PrivateUsage', 0) / 1024)
171
169
    trace.note('PageFaultCount    %8d', info.get('PageFaultCount', 0))
172
170
 
173
171
 
190
188
 
191
189
    if res:
192
190
        (bufx, bufy, curx, cury, wattr,
193
 
        left, top, right, bottom, maxx, maxy) = struct.unpack(
194
 
            "hhhhHhhhhhh", csbi.raw)
 
191
        left, top, right, bottom, maxx, maxy) = struct.unpack("hhhhHhhhhhh", csbi.raw)
195
192
        sizex = right - left + 1
196
193
        sizey = bottom - top + 1
197
194
        return (sizex, sizey)
414
411
 
415
412
 
416
413
def _ensure_with_dir(path):
417
 
    if (not os.path.split(path)[0] or path.startswith(u'*')
418
 
        or path.startswith(u'?')):
 
414
    if not os.path.split(path)[0] or path.startswith(u'*') or path.startswith(u'?'):
419
415
        return u'./' + path, True
420
416
    else:
421
417
        return path, False
522
518
            trace.mutter('Unable to set hidden attribute on %r: %s', path, e)
523
519
 
524
520
 
525
 
def _command_line_to_argv(command_line, single_quotes_allowed=False):
 
521
def command_line_to_argv(command_line, wildcard_expansion=True,
 
522
                         single_quotes_allowed=False):
526
523
    """Convert a Unicode command line into a list of argv arguments.
527
524
 
528
 
    It performs wildcard expansion to make wildcards act closer to how they
529
 
    work in posix shells, versus how they work by default on Windows. Quoted
530
 
    arguments are left untouched.
 
525
    This optionally does wildcard expansion, etc. It is intended to make
 
526
    wildcards act closer to how they work in posix shells, versus how they
 
527
    work by default on Windows. Quoted arguments are left untouched.
531
528
 
532
529
    :param command_line: The unicode string to split into an arg list.
 
530
    :param wildcard_expansion: Whether wildcard expansion should be applied to
 
531
                               each argument. True by default.
533
532
    :param single_quotes_allowed: Whether single quotes are accepted as quoting
534
533
                                  characters like double quotes. False by
535
534
                                  default.
541
540
    #       '**/' style globs
542
541
    args = []
543
542
    for is_quoted, arg in s:
544
 
        if is_quoted or not glob.has_magic(arg):
 
543
        if is_quoted or not glob.has_magic(arg) or not wildcard_expansion:
545
544
            args.append(arg)
546
545
        else:
547
546
            args.extend(glob_one(arg))
557
556
        if command_line is None:
558
557
            raise ctypes.WinError()
559
558
        # Skip the first argument, since we only care about parameters
560
 
        argv = _command_line_to_argv(command_line)[1:]
 
559
        argv = command_line_to_argv(command_line)[1:]
561
560
        if getattr(sys, 'frozen', None) is None:
562
561
            # Invoked via 'python.exe' which takes the form:
563
562
            #   python.exe [PYTHON_OPTIONS] C:\Path\bzr [BZR_OPTIONS]