Exemplo n.º 1
0
import sys
import logging
logger = logging.getLogger(__name__)

class Platform:
    """
    Provides some simple constants that make checking the platform a lot easier to read.
    """
    isWindows = sys.platform.startswith("win")
    isMac = sys.platform.startswith("darwin")

if Platform.isWindows:
    # We want to elevate privs to be able to create symlinks - this requires SeCreateSymbolicLinkPrivilege
    import jaraco.windows.privilege

    status = jaraco.windows.privilege.enable_symlink_privilege()
    if not status:
        logger.critical("FAILED to elevate our privileges to be able to construct SymLinks")

    # path the os routines to use jaraco.windows
    import jaraco.windows.filesystem as fs; fs.patch_os_module()
    # uncomment to dump privs to debug console
    # jaraco.windows.privilege.report_privilege_information()
import ctypes
import os
import platform
import sys
import traceback

# A few Windows constants
SW_HIDE = 0
SW_SHOWNORMAL = 1

sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))

# Add support for Windows symbolic links
if platform.system() == 'Windows':
    from jaraco.windows.filesystem import patch_os_module
    patch_os_module()

def escape_param(param):
    return '"%s"' % param.replace('"', r'\"')

def ensure_privileges():
    # Elevates UAC priviledges if we're on Windows
    if platform.system() != 'Windows':
        return
    if int(platform.version().split('.')[0]) < 6:
        sys.stderr.write('This script does not support Windows XP or older Windows '
                         'versions.\n')
        sys.exit(1)
    if ctypes.windll.shell32.IsUserAnAdmin():
        return
    ShellExecuteA = ctypes.windll.shell32.ShellExecuteA