/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/win32utils.py

  • Committer: Richard Wilbur
  • Date: 2016-02-04 19:07:28 UTC
  • mto: This revision was merged to the branch mainline in revision 6618.
  • Revision ID: richard.wilbur@gmail.com-20160204190728-p0zvfii6zase0fw7
Update COPYING.txt from the original http://www.gnu.org/licenses/gpl-2.0.txt  (Only differences were in whitespace.)  Thanks to Petr Stodulka for pointing out the discrepancy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
import struct
28
28
import sys
29
29
 
30
 
from breezy import (
 
30
from bzrlib import (
31
31
    cmdline,
 
32
    symbol_versioning,
32
33
    )
33
 
from breezy.i18n import gettext
 
34
from bzrlib.i18n import gettext
 
35
 
 
36
# Windows version
 
37
if sys.platform == 'win32':
 
38
    _major,_minor,_build,_platform,_text = sys.getwindowsversion()
 
39
    # from MSDN:
 
40
    # dwPlatformId
 
41
    #   The operating system platform.
 
42
    #   This member can be one of the following values.
 
43
    #   ==========================  ======================================
 
44
    #   Value                       Meaning
 
45
    #   --------------------------  --------------------------------------
 
46
    #   VER_PLATFORM_WIN32_NT       The operating system is Windows Vista,
 
47
    #   2                           Windows Server "Longhorn",
 
48
    #                               Windows Server 2003, Windows XP,
 
49
    #                               Windows 2000, or Windows NT.
 
50
    #
 
51
    #   VER_PLATFORM_WIN32_WINDOWS  The operating system is Windows Me,
 
52
    #   1                           Windows 98, or Windows 95.
 
53
    #   ==========================  ======================================
 
54
    if _platform == 2:
 
55
        winver = 'Windows NT'
 
56
    else:
 
57
        # don't care about real Windows name, just to force safe operations
 
58
        winver = 'Windows 98'
 
59
else:
 
60
    winver = None
 
61
 
34
62
 
35
63
# We can cope without it; use a separate variable to help pyflakes
36
64
try:
39
67
except ImportError:
40
68
    has_ctypes = False
41
69
else:
42
 
    create_buffer = ctypes.create_unicode_buffer
43
 
    extract_buffer = operator.attrgetter("value")
44
 
    suffix = 'W'
 
70
    if winver == 'Windows 98':
 
71
        create_buffer = ctypes.create_string_buffer
 
72
        def extract_buffer(buf):
 
73
            return buf.value.decode("mbcs")
 
74
        suffix = 'A'
 
75
    else:
 
76
        create_buffer = ctypes.create_unicode_buffer
 
77
        extract_buffer = operator.attrgetter("value")
 
78
        suffix = 'W'
45
79
try:
46
80
    import pywintypes
47
81
    has_pywintypes = True
87
121
 
88
122
def debug_memory_win32api(message='', short=True):
89
123
    """Use trace.note() to dump the running memory info."""
90
 
    from breezy import trace
 
124
    from bzrlib import trace
91
125
    if has_ctypes:
92
126
        class PROCESS_MEMORY_COUNTERS_EX(ctypes.Structure):
93
127
            """Used by GetProcessMemoryInfo"""
193
227
            pass
194
228
        else:
195
229
            buf = ctypes.create_unicode_buffer(MAX_PATH)
196
 
            if SHGetSpecialFolderPath(None, buf, csidl, 0):
 
230
            if SHGetSpecialFolderPath(None,buf,csidl,0):
197
231
                return buf.value
198
232
 
199
233
    global has_win32com_shell
338
372
    return get_environ_unicode('COMPUTERNAME')
339
373
 
340
374
 
 
375
@symbol_versioning.deprecated_function(
 
376
    symbol_versioning.deprecated_in((2, 5, 0)))
 
377
def _ensure_unicode(s):
 
378
    if s and type(s) != unicode:
 
379
        from bzrlib import osutils
 
380
        s = s.decode(osutils.get_user_encoding())
 
381
    return s
 
382
 
 
383
 
 
384
get_appdata_location_unicode = symbol_versioning.deprecated_function(
 
385
    symbol_versioning.deprecated_in((2, 5, 0)))(get_appdata_location)
 
386
 
 
387
get_home_location_unicode = symbol_versioning.deprecated_function(
 
388
    symbol_versioning.deprecated_in((2, 5, 0)))(get_home_location)
 
389
 
 
390
get_user_name_unicode = symbol_versioning.deprecated_function(
 
391
    symbol_versioning.deprecated_in((2, 5, 0)))(get_user_name)
 
392
 
 
393
get_host_name_unicode = symbol_versioning.deprecated_function(
 
394
    symbol_versioning.deprecated_in((2, 5, 0)))(get_host_name)
 
395
 
 
396
 
341
397
def _ensure_with_dir(path):
342
398
    if (not os.path.split(path)[0] or path.startswith(u'*')
343
399
        or path.startswith(u'?')):
381
437
    :param file_list: A list of filenames which may include shell globs.
382
438
    :return: An expanded list of filenames.
383
439
 
384
 
    Introduced in breezy 0.18.
 
440
    Introduced in bzrlib 0.18.
385
441
    """
386
442
    if not file_list:
387
443
        return []
435
491
def set_file_attr_hidden(path):
436
492
    """Set file attributes to hidden if possible"""
437
493
    if has_win32file:
438
 
        SetFileAttributes = win32file.SetFileAttributesW
 
494
        if winver != 'Windows 98':
 
495
            SetFileAttributes = win32file.SetFileAttributesW
 
496
        else:
 
497
            SetFileAttributes = win32file.SetFileAttributes
439
498
        try:
440
499
            SetFileAttributes(path, win32file.FILE_ATTRIBUTE_HIDDEN)
441
 
        except pywintypes.error as e:
442
 
            from . import trace
 
500
        except pywintypes.error, e:
 
501
            from bzrlib import trace
443
502
            trace.mutter('Unable to set hidden attribute on %r: %s', path, e)
444
503
 
445
504
 
484
543
    return args
485
544
 
486
545
 
487
 
if has_ctypes:
 
546
if has_ctypes and winver == 'Windows NT':
488
547
    def get_unicode_argv():
489
548
        prototype = ctypes.WINFUNCTYPE(ctypes.c_wchar_p)
490
549
        GetCommandLineW = prototype(("GetCommandLineW",
495
554
        # Skip the first argument, since we only care about parameters
496
555
        argv = _command_line_to_argv(command_line, sys.argv)[1:]
497
556
        return argv
498
 
 
 
557
    
499
558
 
500
559
    def get_environ_unicode(key, default=None):
501
560
        """Get `key` from environment as unicode or `default` if unset
528
587
            if buffer_size > length:
529
588
                return buffer[:length]
530
589
            buffer_size = length
 
590
else:
 
591
    get_unicode_argv = None
 
592
    def get_environ_unicode(key, default=None):
 
593
        """Get `key` from environment as unicode or `default` if unset
 
594
 
 
595
        Fallback version that should basically never be needed.
 
596
        """
 
597
        from bzrlib import osutils
 
598
        try:
 
599
            return os.environ[key].decode(osutils.get_user_encoding())
 
600
        except KeyError:
 
601
            return default
531
602
 
532
603
 
533
604
if has_win32api:
535
606
        """True if pid doesn't correspond to live process on this machine"""
536
607
        try:
537
608
            handle = win32api.OpenProcess(1, False, pid) # PROCESS_TERMINATE
538
 
        except pywintypes.error as e:
 
609
        except pywintypes.error, e:
539
610
            if e[0] == 5: # ERROR_ACCESS_DENIED
540
611
                # Probably something alive we're not allowed to kill
541
612
                return False