~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: 2008-12-01 20:17:21 UTC
  • mfrom: (3872.2.6 jam-integration)
  • Revision ID: pqm@pqm.ubuntu.com-20081201201721-zconkq0v7pow8nmw
(Marius Kruger) Raise an exception when we encounter an non-existing
        dotted revno.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
"""Win32-specific helper functions
18
18
 
97
97
MAX_COMPUTERNAME_LENGTH = 31
98
98
 
99
99
 
100
 
def debug_memory_win32api(message='', short=True):
101
 
    """Use trace.note() to dump the running memory info."""
102
 
    from bzrlib import trace
103
 
    if has_ctypes:
104
 
        class PROCESS_MEMORY_COUNTERS_EX(ctypes.Structure):
105
 
            """Used by GetProcessMemoryInfo"""
106
 
            _fields_ = [('cb', ctypes.c_ulong),
107
 
                        ('PageFaultCount', ctypes.c_ulong),
108
 
                        ('PeakWorkingSetSize', ctypes.c_size_t),
109
 
                        ('WorkingSetSize', ctypes.c_size_t),
110
 
                        ('QuotaPeakPagedPoolUsage', ctypes.c_size_t),
111
 
                        ('QuotaPagedPoolUsage', ctypes.c_size_t),
112
 
                        ('QuotaPeakNonPagedPoolUsage', ctypes.c_size_t),
113
 
                        ('QuotaNonPagedPoolUsage', ctypes.c_size_t),
114
 
                        ('PagefileUsage', ctypes.c_size_t),
115
 
                        ('PeakPagefileUsage', ctypes.c_size_t),
116
 
                        ('PrivateUsage', ctypes.c_size_t),
117
 
                       ]
118
 
        cur_process = ctypes.windll.kernel32.GetCurrentProcess()
119
 
        mem_struct = PROCESS_MEMORY_COUNTERS_EX()
120
 
        ret = ctypes.windll.psapi.GetProcessMemoryInfo(cur_process,
121
 
            ctypes.byref(mem_struct),
122
 
            ctypes.sizeof(mem_struct))
123
 
        if not ret:
124
 
            trace.note('Failed to GetProcessMemoryInfo()')
125
 
            return
126
 
        info = {'PageFaultCount': mem_struct.PageFaultCount,
127
 
                'PeakWorkingSetSize': mem_struct.PeakWorkingSetSize,
128
 
                'WorkingSetSize': mem_struct.WorkingSetSize,
129
 
                'QuotaPeakPagedPoolUsage': mem_struct.QuotaPeakPagedPoolUsage,
130
 
                'QuotaPagedPoolUsage': mem_struct.QuotaPagedPoolUsage,
131
 
                'QuotaPeakNonPagedPoolUsage': mem_struct.QuotaPeakNonPagedPoolUsage,
132
 
                'QuotaNonPagedPoolUsage': mem_struct.QuotaNonPagedPoolUsage,
133
 
                'PagefileUsage': mem_struct.PagefileUsage,
134
 
                'PeakPagefileUsage': mem_struct.PeakPagefileUsage,
135
 
                'PrivateUsage': mem_struct.PrivateUsage,
136
 
               }
137
 
    elif has_win32api:
138
 
        import win32process
139
 
        # win32process does not return PrivateUsage, because it doesn't use
140
 
        # PROCESS_MEMORY_COUNTERS_EX (it uses the one without _EX).
141
 
        proc = win32process.GetCurrentProcess()
142
 
        info = win32process.GetProcessMemoryInfo(proc)
143
 
    else:
144
 
        trace.note('Cannot debug memory on win32 without ctypes'
145
 
                   ' or win32process')
146
 
        return
147
 
    if short:
148
 
        trace.note('WorkingSize %7dKB'
149
 
                   '\tPeakWorking %7dKB\t%s',
150
 
                   info['WorkingSetSize'] / 1024,
151
 
                   info['PeakWorkingSetSize'] / 1024,
152
 
                   message)
153
 
        return
154
 
    if message:
155
 
        trace.note('%s', message)
156
 
    trace.note('WorkingSize       %8d KB', info['WorkingSetSize'] / 1024)
157
 
    trace.note('PeakWorking       %8d KB', info['PeakWorkingSetSize'] / 1024)
158
 
    trace.note('PagefileUsage     %8d KB', info.get('PagefileUsage', 0) / 1024)
159
 
    trace.note('PeakPagefileUsage %8d KB', info.get('PeakPagefileUsage', 0) / 1024)
160
 
    trace.note('PrivateUsage      %8d KB', info.get('PrivateUsage', 0) / 1024)
161
 
    trace.note('PageFaultCount    %8d', info.get('PageFaultCount', 0))
162
 
 
163
 
 
164
100
def get_console_size(defaultx=80, defaulty=25):
165
101
    """Return size of current console.
166
102
 
190
126
 
191
127
def _get_sh_special_folder_path(csidl):
192
128
    """Call SHGetSpecialFolderPathW if available, or return None.
193
 
 
 
129
    
194
130
    Result is always unicode (or None).
195
131
    """
196
132
    if has_ctypes:
286
222
    If location cannot be obtained return system drive root,
287
223
    i.e. C:\
288
224
 
289
 
    Returned value can be unicode or plain string.
 
225
    Returned value can be unicode or plain sring.
290
226
    To convert plain string to unicode use
291
227
    s.decode(osutils.get_user_encoding())
292
228
    """
309
245
    """Return user name as login name.
310
246
    If name cannot be obtained return None.
311
247
 
312
 
    Returned value can be unicode or plain string.
 
248
    Returned value can be unicode or plain sring.
313
249
    To convert plain string to unicode use
314
250
    s.decode(osutils.get_user_encoding())
315
251
    """
408
344
        return u'./' + path, True
409
345
    else:
410
346
        return path, False
411
 
 
 
347
    
412
348
def _undo_ensure_with_dir(path, corrected):
413
349
    if corrected:
414
350
        return path[2:]
433
369
    import glob
434
370
    expanded_file_list = []
435
371
    for possible_glob in file_list:
436
 
 
 
372
        
437
373
        # work around bugs in glob.glob()
438
374
        # - Python bug #1001604 ("glob doesn't return unicode with ...")
439
375
        # - failing expansion for */* with non-iso-8859-* chars
448
384
        else:
449
385
            glob_files = [_undo_ensure_with_dir(elem, corrected) for elem in glob_files]
450
386
            expanded_file_list += glob_files
451
 
 
452
 
    return [elem.replace(u'\\', u'/') for elem in expanded_file_list]
 
387
            
 
388
    return [elem.replace(u'\\', u'/') for elem in expanded_file_list] 
453
389
 
454
390
 
455
391
def get_app_path(appname):
456
392
    """Look up in Windows registry for full path to application executable.
457
 
    Typically, applications create subkey with their basename
 
393
    Typicaly, applications create subkey with their basename
458
394
    in HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\
459
395
 
460
396
    :param  appname:    name of application (if no filename extension