/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 breezy/win32utils.py

  • Committer: Jelmer Vernooij
  • Date: 2017-06-10 00:06:46 UTC
  • mfrom: (6673 work)
  • mto: This revision was merged to the branch mainline in revision 6675.
  • Revision ID: jelmer@jelmer.uk-20170610000646-xj6jh277lo4xuo10
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
 
30
30
from breezy import (
31
31
    cmdline,
32
 
    symbol_versioning,
33
32
    )
34
33
from breezy.i18n import gettext
35
34
 
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
 
 
62
 
 
63
35
# We can cope without it; use a separate variable to help pyflakes
64
36
try:
65
37
    import ctypes
67
39
except ImportError:
68
40
    has_ctypes = False
69
41
else:
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'
 
42
    create_buffer = ctypes.create_unicode_buffer
 
43
    extract_buffer = operator.attrgetter("value")
 
44
    suffix = 'W'
79
45
try:
80
46
    import pywintypes
81
47
    has_pywintypes = True
372
338
    return get_environ_unicode('COMPUTERNAME')
373
339
 
374
340
 
375
 
@symbol_versioning.deprecated_function(
376
 
    symbol_versioning.deprecated_in((2, 5, 0)))
377
 
def _ensure_unicode(s):
378
 
    if s and not isinstance(s, unicode):
379
 
        from . 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
 
 
397
341
def _ensure_with_dir(path):
398
342
    if (not os.path.split(path)[0] or path.startswith(u'*')
399
343
        or path.startswith(u'?')):
491
435
def set_file_attr_hidden(path):
492
436
    """Set file attributes to hidden if possible"""
493
437
    if has_win32file:
494
 
        if winver != 'Windows 98':
495
 
            SetFileAttributes = win32file.SetFileAttributesW
496
 
        else:
497
 
            SetFileAttributes = win32file.SetFileAttributes
 
438
        SetFileAttributes = win32file.SetFileAttributesW
498
439
        try:
499
440
            SetFileAttributes(path, win32file.FILE_ATTRIBUTE_HIDDEN)
500
441
        except pywintypes.error as e:
543
484
    return args
544
485
 
545
486
 
546
 
if has_ctypes and winver == 'Windows NT':
 
487
if has_ctypes:
547
488
    def get_unicode_argv():
548
489
        prototype = ctypes.WINFUNCTYPE(ctypes.c_wchar_p)
549
490
        GetCommandLineW = prototype(("GetCommandLineW",
554
495
        # Skip the first argument, since we only care about parameters
555
496
        argv = _command_line_to_argv(command_line, sys.argv)[1:]
556
497
        return argv
557
 
    
 
498
 
558
499
 
559
500
    def get_environ_unicode(key, default=None):
560
501
        """Get `key` from environment as unicode or `default` if unset
587
528
            if buffer_size > length:
588
529
                return buffer[:length]
589
530
            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 breezy import osutils
598
 
        try:
599
 
            return os.environ[key].decode(osutils.get_user_encoding())
600
 
        except KeyError:
601
 
            return default
602
531
 
603
532
 
604
533
if has_win32api: