~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/win32utils.py

Abbreviate pack_stat struct format to '>6L'

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
import sys
26
26
 
27
27
from bzrlib import cmdline
 
28
from bzrlib.i18n import gettext
28
29
 
29
30
# Windows version
30
31
if sys.platform == 'win32':
128
129
            ctypes.byref(mem_struct),
129
130
            ctypes.sizeof(mem_struct))
130
131
        if not ret:
131
 
            trace.note('Failed to GetProcessMemoryInfo()')
 
132
            trace.note(gettext('Failed to GetProcessMemoryInfo()'))
132
133
            return
133
134
        info = {'PageFaultCount': mem_struct.PageFaultCount,
134
135
                'PeakWorkingSetSize': mem_struct.PeakWorkingSetSize,
149
150
        proc = win32process.GetCurrentProcess()
150
151
        info = win32process.GetProcessMemoryInfo(proc)
151
152
    else:
152
 
        trace.note('Cannot debug memory on win32 without ctypes'
153
 
                   ' or win32process')
 
153
        trace.note(gettext('Cannot debug memory on win32 without ctypes'
 
154
                   ' or win32process'))
154
155
        return
155
156
    if short:
156
157
        # using base-2 units (see HACKING.txt).
157
 
        trace.note('WorkingSize %7dKiB'
158
 
                   '\tPeakWorking %7dKiB\t%s',
 
158
        trace.note(gettext('WorkingSize {0:>7}KiB'
 
159
                   '\tPeakWorking {1:>7}KiB\t{2}').format(
159
160
                   info['WorkingSetSize'] / 1024,
160
161
                   info['PeakWorkingSetSize'] / 1024,
161
 
                   message)
 
162
                   message))
162
163
        return
163
164
    if message:
164
165
        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',
 
166
    trace.note(gettext('WorkingSize       %8d KiB'), info['WorkingSetSize'] / 1024)
 
167
    trace.note(gettext('PeakWorking       %8d KiB'), info['PeakWorkingSetSize'] / 1024)
 
168
    trace.note(gettext('PagefileUsage     %8d KiB'), info.get('PagefileUsage', 0) / 1024)
 
169
    trace.note(gettext('PeakPagefileUsage %8d KiB'),
169
170
               info.get('PeakPagefileUsage', 0) / 1024)
170
 
    trace.note('PrivateUsage      %8d KiB', info.get('PrivateUsage', 0) / 1024)
171
 
    trace.note('PageFaultCount    %8d', info.get('PageFaultCount', 0))
 
171
    trace.note(gettext('PrivateUsage      %8d KiB'), info.get('PrivateUsage', 0) / 1024)
 
172
    trace.note(gettext('PageFaultCount    %8d'), info.get('PageFaultCount', 0))
172
173
 
173
174
 
174
175
def get_console_size(defaultx=80, defaulty=25):
468
469
 
469
470
 
470
471
def get_app_path(appname):
471
 
    """Look up in Windows registry for full path to application executable.
 
472
    r"""Look up in Windows registry for full path to application executable.
472
473
    Typically, applications create subkey with their basename
473
474
    in HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\
474
475
 
576
577
        return argv
577
578
else:
578
579
    get_unicode_argv = None
 
580
 
 
581
 
 
582
if has_win32api:
 
583
    def _pywin32_is_local_pid_dead(pid):
 
584
        """True if pid doesn't correspond to live process on this machine"""
 
585
        try:
 
586
            handle = win32api.OpenProcess(1, False, pid) # PROCESS_TERMINATE
 
587
        except pywintypes.error, e:
 
588
            if e[0] == 5: # ERROR_ACCESS_DENIED
 
589
                # Probably something alive we're not allowed to kill
 
590
                return False
 
591
            elif e[0] == 87: # ERROR_INVALID_PARAMETER
 
592
                return True
 
593
            raise
 
594
        handle.close()
 
595
        return False
 
596
    is_local_pid_dead = _pywin32_is_local_pid_dead
 
597
elif has_ctypes and sys.platform == 'win32':
 
598
    from ctypes.wintypes import BOOL, DWORD, HANDLE
 
599
    _kernel32 = ctypes.windll.kernel32
 
600
    _CloseHandle = ctypes.WINFUNCTYPE(BOOL, HANDLE)(
 
601
        ("CloseHandle", _kernel32))
 
602
    _OpenProcess = ctypes.WINFUNCTYPE(HANDLE, DWORD, BOOL, DWORD)(
 
603
        ("OpenProcess", _kernel32))
 
604
    def _ctypes_is_local_pid_dead(pid):
 
605
        """True if pid doesn't correspond to live process on this machine"""
 
606
        handle = _OpenProcess(1, False, pid) # PROCESS_TERMINATE
 
607
        if not handle:
 
608
            errorcode = ctypes.GetLastError()
 
609
            if errorcode == 5: # ERROR_ACCESS_DENIED
 
610
                # Probably something alive we're not allowed to kill
 
611
                return False
 
612
            elif errorcode == 87: # ERROR_INVALID_PARAMETER
 
613
                return True
 
614
            raise ctypes.WinError(errorcode)
 
615
        _CloseHandle(handle)
 
616
        return False
 
617
    is_local_pid_dead = _ctypes_is_local_pid_dead