~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/win32utils.py

  • Committer: Andrew Bennetts
  • Date: 2010-02-12 04:33:05 UTC
  • mfrom: (5031 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5032.
  • Revision ID: andrew.bennetts@canonical.com-20100212043305-ujdbsdoviql2t7i3
MergeĀ lp:bzr

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006, 2007 Canonical Ltd
 
1
# Copyright (C) 2005-2010 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
22
22
import glob
23
23
import os
24
24
import re
25
 
import shlex
26
25
import struct
27
 
import StringIO
28
26
import sys
29
27
 
30
28
 
137
135
                'WorkingSetSize': mem_struct.WorkingSetSize,
138
136
                'QuotaPeakPagedPoolUsage': mem_struct.QuotaPeakPagedPoolUsage,
139
137
                'QuotaPagedPoolUsage': mem_struct.QuotaPagedPoolUsage,
140
 
                'QuotaPeakNonPagedPoolUsage': mem_struct.QuotaPeakNonPagedPoolUsage,
 
138
                'QuotaPeakNonPagedPoolUsage':
 
139
                    mem_struct.QuotaPeakNonPagedPoolUsage,
141
140
                'QuotaNonPagedPoolUsage': mem_struct.QuotaNonPagedPoolUsage,
142
141
                'PagefileUsage': mem_struct.PagefileUsage,
143
142
                'PeakPagefileUsage': mem_struct.PeakPagefileUsage,
154
153
                   ' or win32process')
155
154
        return
156
155
    if short:
157
 
        trace.note('WorkingSize %7dKB'
158
 
                   '\tPeakWorking %7dKB\t%s',
 
156
        # using base-2 units (see HACKING.txt).
 
157
        trace.note('WorkingSize %7dKiB'
 
158
                   '\tPeakWorking %7dKiB\t%s',
159
159
                   info['WorkingSetSize'] / 1024,
160
160
                   info['PeakWorkingSetSize'] / 1024,
161
161
                   message)
162
162
        return
163
163
    if message:
164
164
        trace.note('%s', message)
165
 
    trace.note('WorkingSize       %8d KB', info['WorkingSetSize'] / 1024)
166
 
    trace.note('PeakWorking       %8d KB', info['PeakWorkingSetSize'] / 1024)
167
 
    trace.note('PagefileUsage     %8d KB', info.get('PagefileUsage', 0) / 1024)
168
 
    trace.note('PeakPagefileUsage %8d KB', info.get('PeakPagefileUsage', 0) / 1024)
169
 
    trace.note('PrivateUsage      %8d KB', info.get('PrivateUsage', 0) / 1024)
 
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)
170
171
    trace.note('PageFaultCount    %8d', info.get('PageFaultCount', 0))
171
172
 
172
173
 
182
183
        return (defaultx, defaulty)
183
184
 
184
185
    # To avoid problem with redirecting output via pipe
185
 
    # need to use stderr instead of stdout
 
186
    # we need to use stderr instead of stdout
186
187
    h = ctypes.windll.kernel32.GetStdHandle(WIN32_STDERR_HANDLE)
187
188
    csbi = ctypes.create_string_buffer(22)
188
189
    res = ctypes.windll.kernel32.GetConsoleScreenBufferInfo(h, csbi)
189
190
 
190
191
    if res:
191
192
        (bufx, bufy, curx, cury, wattr,
192
 
        left, top, right, bottom, maxx, maxy) = struct.unpack("hhhhHhhhhhh", csbi.raw)
 
193
        left, top, right, bottom, maxx, maxy) = struct.unpack(
 
194
            "hhhhHhhhhhh", csbi.raw)
193
195
        sizex = right - left + 1
194
196
        sizey = bottom - top + 1
195
197
        return (sizex, sizey)
392
394
 
393
395
 
394
396
def _ensure_unicode(s):
395
 
    from bzrlib import osutils
396
397
    if s and type(s) != unicode:
397
398
        from bzrlib import osutils
398
399
        s = s.decode(osutils.get_user_encoding())
413
414
 
414
415
 
415
416
def _ensure_with_dir(path):
416
 
    if not os.path.split(path)[0] or path.startswith(u'*') or path.startswith(u'?'):
 
417
    if (not os.path.split(path)[0] or path.startswith(u'*')
 
418
        or path.startswith(u'?')):
417
419
        return u'./' + path, True
418
420
    else:
419
421
        return path, False
631
633
    args = []
632
634
    for is_quoted, arg in s:
633
635
        if is_quoted or not glob.has_magic(arg):
634
 
            args.append(arg.replace(u'\\', u'/'))
 
636
            args.append(arg)
635
637
        else:
636
638
            args.extend(glob_one(arg))
637
639
    return args
648
650
        prototype = ctypes.WINFUNCTYPE(POINTER(LPCWSTR), LPCWSTR, POINTER(INT))
649
651
        command_line = GetCommandLine()
650
652
        # Skip the first argument, since we only care about parameters
651
 
        argv = _command_line_to_argv(GetCommandLine())[1:]
 
653
        argv = _command_line_to_argv(command_line)[1:]
652
654
        if getattr(sys, 'frozen', None) is None:
653
655
            # Invoked via 'python.exe' which takes the form:
654
656
            #   python.exe [PYTHON_OPTIONS] C:\Path\bzr [BZR_OPTIONS]